You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I source runx and pass the "-h" option, after the help output, I get the following errors:
Command 'main' not found, did you mean:
command 'maim' from deb maim (5.6.3-1)
command 'rain' from deb bsdgames (2.17-29)
command 'man' from deb man-db (2.10.2-1)
command 'mail' from deb mailutils (1:3.14-1)
Try: apt install <deb name>
finish: command not found
This is because in parse_options, when the "-h" or "--help" option is detected, the finish function is called, which uses "$Sourced" to detect that the script has been sourced and then unsets all the variables and functions defined in the script.
After returning from parse_options, the script tries to call the main and then finish functions, but these have already been unset, so the shell tries to find them as standard commands, which it can't.
As such, it then tries to suggest packages to install which could provide these functions as standard commands.
Furthermore, if a fix to issue #13 is implemented, moving the parse_options function to before the check_host function, this breaks the "$Sourced" logic because the detection of whether the script is "$Sourced" is performed in the check_host function, so when "-h" is then detected and finish is called, the finish function no longer knows that the script has been "$Sourced".
So:
The detection of "$Sourced" should be moved into the parse_options function, because sourcing the function is a 'kind-of' option - and that detection should be done as early as possible, before there is any chance that the script will need to know that it has been "$Sourced".
The finish function should not be called on detection of "-h" or "--help" by parse_options. Instead, the parse_options function should return as normal, but setting "$Exitcode" to a value (0 is suggested, because outputting help is a 'kind-of' success) and then testing "$Exitcode" to ensure that it is still unset before calling any of the subsequent functionality.
The finish function is then called as the last function call in the script, and it can happily unset everything without there being any resulting errors.
The text was updated successfully, but these errors were encountered:
Context, my system is an Ubuntu WSL2 system.
When I source
runx
and pass the "-h" option, after the help output, I get the following errors:This is because in
parse_options
, when the "-h" or "--help" option is detected, thefinish
function is called, which uses "$Sourced" to detect that the script has been sourced and thenunset
s all the variables and functions defined in the script.After returning from
parse_options
, the script tries to call themain
and thenfinish
functions, but these have already been unset, so the shell tries to find them as standard commands, which it can't.As such, it then tries to suggest packages to install which could provide these functions as standard commands.
Furthermore, if a fix to issue #13 is implemented, moving the
parse_options
function to before thecheck_host
function, this breaks the "$Sourced" logic because the detection of whether the script is "$Sourced" is performed in thecheck_host
function, so when "-h" is then detected andfinish
is called, thefinish
function no longer knows that the script has been "$Sourced".So:
parse_options
function, because sourcing the function is a 'kind-of' option - and that detection should be done as early as possible, before there is any chance that the script will need to know that it has been "$Sourced".finish
function should not be called on detection of "-h" or "--help" byparse_options
. Instead, theparse_options
function should return as normal, but setting "$Exitcode" to a value (0 is suggested, because outputting help is a 'kind-of' success) and then testing "$Exitcode" to ensure that it is still unset before calling any of the subsequent functionality.finish
function is then called as the last function call in the script, and it can happily unset everything without there being any resulting errors.The text was updated successfully, but these errors were encountered: