argbash icon indicating copy to clipboard operation
argbash copied to clipboard

Use parameter expansion for default variable initialization

Open edannenberg opened this issue 8 years ago • 1 comments

Currently argument variables are initialized like this:

# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_print=off
_arg_foo_option="boo"

This is problematic when using sub-parsers, as optionals that were already parsed by the main script are reset to it's defaults and not parsed again. Could parameter expansion be used instead?

# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_print=${_arg_print:-off}
_arg_foo_option="${_arg_foo_option:-boo}"

edannenberg avatar Feb 20 '17 23:02 edannenberg

You could actually try to specify ${_arg_print:-off} as the default value. Aside from that, I would like to support subparsers in a less "hacky" way, but I have to think about it somehow more.

matejak avatar Apr 20 '17 19:04 matejak