argbash icon indicating copy to clipboard operation
argbash copied to clipboard

Multiple Positional Arguments with Defaults

Open EdwardOst opened this issue 6 years ago • 5 comments

Feature Request: Argbash allows defaults for positional arguments, but in practice it can only be applied to the first positional argument. Many scripts have multiple parameters which have defaults. All such positional optional parameters are necessarily at the end of the signature. Intelligent defaults is a good practice in general. Could this be supported in a future version of Argbash?

Example

# ARG_POSITIONAL_SINGLE([bucket], [s3 bucket to publish the AWS CLI layer], [default_bucket])
# ARG_POSITIONAL_SINGLE([s3_folder], [s3 folder key to publish AWS CLI layer], [awscli])

could support

myscript myscript mybucket myscript mybucket my/folder/key

EdwardOst avatar Jul 01 '19 10:07 EdwardOst

This is a tricky feature request. Imagine that the script accepts two arguments, both of them have default. You supply one. The question is: Which one has been supplied? The first one, or the last one?

matejak avatar Jul 01 '19 13:07 matejak

since they are positional it would be the first one. I realize that I can do this with ARG_POSITIONAL_INF but the parameters are not named.

EdwardOst avatar Jul 02 '19 17:07 EdwardOst

Your answer sounds reasonable. I will think of this - the feature is not so complicated to implement, but it will open a lot of possibilities, and the code has to be tested thoroughly, so it won't break in the future.

matejak avatar Jul 08 '19 09:07 matejak

I second this feature request.

In my particular case I want a command similar to man, which has the usage man <options go here> [section] name

So you can pass either one positional argument (which is interpreted as name) or two (which are interpreted as section first and then name).

I was thinking about implementing this with an empty default for section, indicating that it is optional:

# ARG_POSITIONAL_SINGLE([section],[],[""])
# ARG_POSITIONAL_SINGLE([name])

But as @EdwardOst points out, you can't have positional arguments with defaults at the beginning.

Now, it works fine the other way around, but I would prefer to have it this way to share muscle memory with related commands.

sebastiancarlos avatar Apr 05 '23 16:04 sebastiancarlos