Menu

#420 Enable 'return' in scripts

v1.1.x
closed
None
v1.1.2
New Functionality
2019-08-22
2018-12-05
Erik Hänel
No

Enable the return command in scripts to leave a script before its actual end. (Can be used to notify the user that the current script is an install script: add return to the install section and print the notification afterwards)

Analysis:

In the Script class member function Script::getNextScriptCommand() one has to intercept the returned command and check, whether it equals return. In this case, one has to stop the script evaluation by calling Script::close() and setting bLastScriptCommand to true and returning an empty string.
If the script currently executed an install section, then one has to ensure that the install process is correctly terminated. This can be done by using the lines 736-744 at the correct location. The best solution would be to extract the whole logic into a private member function handling all this stuff.

The correct location to implement the return statement is in the Kernel in the function NumeReKernel::handleFlowControls(). The planned implementation from the previous analysis shall be added according to the following snippet:

if (_procedure.getLoop() || sCurrentCommand == "for" || sCurrentCommand == "if" || sCurrentCommand == "while" || sCurrentCommand == "switch")
{
    ...
    if (!(_script.isValid() && _script.isOpen()) && !sCmdCache.length())
    {
        ...
    }
    else
    {
        // check here for the existence of the return signal using 
        // FlowCtrl::getReturnSignal() and close the script, if needed
        // set: nReturnVal = NUMERE_DONE_KEYWORD;
    }

    return false;
}
else if (sCurrentCommand == "return")
{
    // close here the script
    // set: nReturnVal = NUMERE_DONE_KEYWORD;
}

return true;

To ensure that the return signal is resetted correctly, add bReturnSignal = false to FlowCtrl::setCommand().

Implementation:

  • Implementation: The implementation was done as proposed by the analysis. An additional method was added to Script.
  • Revision: [r605]
  • Implementation test: Scripts with return statements at the relevant locations (plain script, inside flow control block, inside an install section) were tested without deviation.

Documentation:

  • ChangesLog: updated
  • Comments: Code changes commented
  • Documentation articles: Not needed
  • Language files: Language files were updated correspondingly.

Tests:

This functionality was tested together with the install scripts provided by the package creator [#375]. No deviation occured.

Related

Commit: [r605]
Tickets: #375

Discussion

  • Erik Hänel

    Erik Hänel - 2018-12-05
    • status: open --> accepted
     
  • Erik Hänel

    Erik Hänel - 2019-02-09
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +1,18 @@
     Enable the `return` command in scripts to leave a script before its actual end. (Can be used to notify the user that the current script is an install script: add `return` to the install section and print the notification afterwards)
    +
    +###Analysis:
    +(*Describe, what's the issue and which changes have to be made*)
    +
    +###Implementation:
    +* Implementation: (*Describe, what you've changed*) 
    +* Revision: [rXXX]
    +* Implementation test: (*Describe the type of test, which you performed, and if it was successful*)
    +
    +###Documentation:
    +* ChangesLog: (*Have you updated the changes log?*)
    +* Comments: (*Have you written comments in the code, which describe your change?*)
    +* Documentation articles: (*Have you updated the documentation articles?*)
    +* Language files: (*Have you updated the language files?*)
    +
    +###Tests:
    +(*Describe, which tests you performed and their outcome*)
    
    • status: accepted --> analyzing
     
  • Erik Hänel

    Erik Hänel - 2019-02-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,7 +1,8 @@
     Enable the `return` command in scripts to leave a script before its actual end. (Can be used to notify the user that the current script is an install script: add `return` to the install section and print the notification afterwards)
    
     ###Analysis:
    -(*Describe, what's the issue and which changes have to be made*)
    +In the `Script` class member function `Script::getNextScriptCommand()` one has to intercept the returned command and check, whether it equals `return`. In this case, one has to stop the script evaluation by calling `Script::close()` and setting `bLastScriptCommand` to `true` and returning an empty string.
    +If the script currently executed an install section, then one has to ensure that the install process is correctly terminated. This can be done by using the lines 736-744 at the correct location. The best solution would be to extract the whole logic into a private member function handling all this stuff.
    
     ###Implementation:
    
     * Implementation: (*Describe, what you've changed*) 
    
    • status: analyzing --> implementing
    • assigned_to: Erik Hänel --> Rudolf Brausemann
     
  • Erik Hänel

    Erik Hänel - 2019-05-17
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,8 +1,37 @@
     Enable the `return` command in scripts to leave a script before its actual end. (Can be used to notify the user that the current script is an install script: add `return` to the install section and print the notification afterwards)
    
     ###Analysis:
    -In the `Script` class member function `Script::getNextScriptCommand()` one has to intercept the returned command and check, whether it equals `return`. In this case, one has to stop the script evaluation by calling `Script::close()` and setting `bLastScriptCommand` to `true` and returning an empty string.
    -If the script currently executed an install section, then one has to ensure that the install process is correctly terminated. This can be done by using the lines 736-744 at the correct location. The best solution would be to extract the whole logic into a private member function handling all this stuff.
    +<s>In the `Script` class member function `Script::getNextScriptCommand()` one has to intercept the returned command and check, whether it equals `return`. In this case, one has to stop the script evaluation by calling `Script::close()` and setting `bLastScriptCommand` to `true` and returning an empty string.
    +If the script currently executed an install section, then one has to ensure that the install process is correctly terminated. This can be done by using the lines 736-744 at the correct location. The best solution would be to extract the whole logic into a private member function handling all this stuff.</s>
    +
    +The correct location to implement the `return` statement is in the Kernel in the function `NumeReKernel::handleFlowControls()`. The planned implementation from the previous analysis shall be added according to the following snippet:
    +
    
    +    :::C++
    +    if (_procedure.getLoop() || sCurrentCommand == "for" || sCurrentCommand == "if" || sCurrentCommand == "while" || sCurrentCommand == "switch")
    +    {
    +        ...
    +        if (!(_script.isValid() && _script.isOpen()) && !sCmdCache.length())
    +        {
    +            ...
    +        }
    +        else
    +        {
    +            // check here for the existence of the return signal using 
    +            // FlowCtrl::getReturnSignal() and close the script, if needed
    +            // set: nReturnVal = NUMERE_DONE_KEYWORD;
    +        }
    +        
    +        return false;
    +    }
    +    else if (sCurrentCommand == "return")
    +    {
    +        // close here the script
    +        // set: nReturnVal = NUMERE_DONE_KEYWORD;
    +    }
    +    
    +    return true;
    +
    +To ensure that the return signal is resetted correctly, add `bReturnSignal = false` to `FlowCtrl::setCommand()`.
    
     ###Implementation:
    
     * Implementation: (*Describe, what you've changed*) 
    
     
  • Erik Hänel

    Erik Hänel - 2019-07-30
    • assigned_to: Rudolf Brausemann --> Erik Hänel
     
  • Erik Hänel

    Erik Hänel - 2019-07-31
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -34,15 +34,15 @@
     To ensure that the return signal is resetted correctly, add `bReturnSignal = false` to `FlowCtrl::setCommand()`.
    
     ###Implementation:
    -* Implementation: (*Describe, what you&#39;ve changed*) 
    -* Revision: [rXXX]
    -* Implementation test: (*Describe the type of test, which you performed, and if it was successful*)
    +* Implementation: The implementation was done as proposed by the analysis. An additional method was added to `Script`.
    +* Revision: [r605]
    +* Implementation test: Scripts with `return` statements at the relevant locations (plain script, inside flow control block, inside an install section) were tested without deviation.
    
     ###Documentation:
    -* ChangesLog: (*Have you updated the changes log?*)
    -* Comments: (*Have you written comments in the code, which describe your change?*)
    -* Documentation articles: (*Have you updated the documentation articles?*)
    -* Language files: (*Have you updated the language files?*)
    +* ChangesLog: updated
    +* Comments: Code changes commented
    +* Documentation articles: Not needed
    +* Language files: Language files were updated correspondingly.
    
     ###Tests:
     (*Describe, which tests you performed and their outcome*)
    
    • status: implementing --> testing
     

    Related

    Commit: [r605]

  • Erik Hänel

    Erik Hänel - 2019-08-22
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -45,4 +45,4 @@
    
     * Language files: Language files were updated correspondingly.
    
     ###Tests:
    -(*Describe, which tests you performed and their outcome*)
    +This functionality was tested together with the install scripts provided by the package creator [#375]. No deviation occured.
    
    • status: testing --> closed
     

    Related

    Tickets: #375

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB