argbash icon indicating copy to clipboard operation
argbash copied to clipboard

Introduce macros that have different handling of defaults

Open matejak opened this issue 7 years ago • 4 comments

The ARG_OPTIONAL_REPEATED and ARG_OPTIONAL_INCREMENTAL currently extend their defaults. It may make sense to give a possibility to pick the way defaults are handled, because there are legitimate use cases when users want the defaults to be forgotten if they supply value(s) to these commands (see #12 for more in-depth insights). The proposal is to introduce two alternatives for each macro that is in question:

  • ARG_OPTIONAL_REPEATED_ADD
  • ARG_OPTIONAL_REPEATED_REPLACE
  • ARG_OPTIONAL_INCREMENTAL_ADD
  • ARG_OPTIONAL_INCREMENTAL_REPLACE

Those macros would accept the same arguments, but they would treat the defaults differently (and also the help message would have to be different). Any feedback is welcome, but most importantly:

  • Does it look like a good idea?
  • Do the names feel right?

matejak avatar Jun 12 '17 17:06 matejak

Would these replace the existing ARG_OPTIONAL_REPEATED and ARG_OPTIONAL_INCREMENTAL macros, or would they be an alias for the _ADD implementations?

I might use ARG_OPTIONAL_REPEATED_SUPPLEMENT instead. I can't put my finger on the exact reasoning, but as a native English speaker I think "supplement" is clearer.

The only thing this doesn't address from #12 is the idea that it might be possible that the user would want to override this, rather than just the tool developer. For example, the tool developer might use the _ADD implementation because they feel that certain values must always be present, but the user might disagree. I'm not sure that this is a use-case worth designing for, but it's never a bad idea to consider all the possibilities.

sgallagher avatar Jun 23 '17 14:06 sgallagher

Good point about the user overrides. I will think a bit more and come up with something.

matejak avatar Jun 23 '17 14:06 matejak

I'm definitely :+1: for ARG_OPTIONAL_REPEATED to have alternative handling. I'd like to be able to replace the options rather than appending.

gdevenyi avatar Mar 25 '21 20:03 gdevenyi

This would be useful to me - I'm writing a script to generate specimen text, and would like to specify a default list of characters to process, but the user should be able to override the character list with their own, rather than adding to the default. I'd be using ARG_OPTIONAL_REPEATED_REPLACE to get multiple lines of characters.

iainhallam avatar Jul 22 '23 23:07 iainhallam