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

Multiple Positional Arguments with Defaults #99

Open
EdwardOst opened this issue Jul 1, 2019 · 4 comments
Open

Multiple Positional Arguments with Defaults #99

EdwardOst opened this issue Jul 1, 2019 · 4 comments

Comments

@EdwardOst
Copy link

EdwardOst commented Jul 1, 2019

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

@matejak
Copy link
Owner

matejak commented Jul 1, 2019

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?

@EdwardOst
Copy link
Author

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.

@matejak
Copy link
Owner

matejak commented Jul 8, 2019

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.

@sebastiancarlos
Copy link

sebastiancarlos commented Apr 5, 2023

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.

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

No branches or pull requests

3 participants