matejak / argbash

Bash argument parsing code generator
Other
1.4k stars 62 forks source link

ARG_OPTIONAL_REPEATED always appends to the defaults rather than replacing #12

Closed sgallagher closed 7 years ago

sgallagher commented 7 years ago

The documentation for ARG_OPTIONAL_REPEATED reads:

The default default is an empty array. The argument can be repeated multiple times, but instead of the later specifications overriding earlier ones (s.a. ARG_OPTIONAL_SINGLE does), arguments are gradually appended to an array. The form of the default is what you normally put between the brackets when you create bash arrays, so put whitespace-separated values in there

The other options for argbash will supersede their defaults, but the effect of using the default option in ARG_OPTIONAL_REPEATED means that this set of values will always be present in the resulting list and that the arguments specified at the command-line merely supplement them.

Either the documentation should reflect this behavior or it should be changed to behave more similarly to the other options.

matejak commented 7 years ago

Hello, you are right, the current handling of defaults is not documented. I slightly prefer this behavior for its consistency --- now, adding script arguments to the command-line makes the script core functionality believe that it got more arguments, or some of the existing arguments were overriden (or both). Throwing away defaults from repeated arguments would lead to the effect that adding one argument would remove multiple values. So I plan to fix this by properly documenting the existing behavior; however, do you have user stories suggesting that the alternative behavior is more useful?

sgallagher commented 7 years ago

Well, in my particular case, I was attempting to create an option that would tell a script to operate on multiple architectures of sample data. I wanted to be able to set a default that it would run on all the architectures that we support, but to be able to set a reduced number (possibly only one) at the command-line, primarily for debugging (so I wouldn't have to wait for the script to process through all of them at once).

Perhaps when using ARG_OPTIONAL_REPEATED, it could also generate a --clear-foo flag that would allow you to empty the default list explicitly and then append to it with further --foo arguments?

sgallagher commented 7 years ago

If you are curious, the example I was working on is here: https://github.com/sgallagher/baseruntime-package-lists/blob/master/download_repo.sh#L9

For now, I'm leaving it blank and adding the values I need at the command line. But I'd prefer to be able to set the defaults.

matejak commented 7 years ago

You have a good point, I will think about it.

matejak commented 7 years ago

The issue is technically fixed (by added documentation), but see #13 for the proper fix.