Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARG_OPTIONAL_REPEATED always appends to the defaults rather than replacing #12

Closed
sgallagher opened this issue Jun 5, 2017 · 5 comments
Assignees
Labels

Comments

@sgallagher
Copy link
Contributor

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
Copy link
Owner

matejak commented Jun 5, 2017

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?

@matejak matejak self-assigned this Jun 5, 2017
@matejak matejak added the bug label Jun 5, 2017
@sgallagher
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Owner

matejak commented Jun 6, 2017

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

@matejak
Copy link
Owner

matejak commented Jun 23, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants