getopts_long
getopts_long copied to clipboard
Fix default argument logic
This PR updates the logic executed when arguments are not explicitly passed to getopts_long
and instead they are determined from the call stack (using BASH_ARGV
), which attempts to match the default argument behavior of the builtin getopts
command.
Based on my tests, the updated logic fixes all the bugs I found, e.g. when calling getopts_long
within nested functions, etc.
Also, while testing, I noticed the use of BASH_ARGV
requires shopt -s extdebug
to be enabled. Also, the logic may not work in all scenarios, e.g. when the arguments have been shifted, etc. However, this was always the case, and is not new to the changes in this PR.