getopts_long icon indicating copy to clipboard operation
getopts_long copied to clipboard

Fix default argument logic

Open billyzkid opened this issue 1 year ago • 0 comments

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.

billyzkid avatar Aug 24 '23 18:08 billyzkid