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 required positional arguments? #17

Closed
btamayo opened this issue Jul 31, 2017 · 2 comments
Closed

Multiple required positional arguments? #17

btamayo opened this issue Jul 31, 2017 · 2 comments

Comments

@btamayo
Copy link
Contributor

btamayo commented Jul 31, 2017

I'm trying to generate the following type of usage template:

Usage: my_program <host> <port>

So far, I've realized I can't use ARG_POSITIONAL_SINGLE twice in a row as it throws an error.

And using the following template:

# ARG_POSITIONAL_MULTI([host][port],[Your host][Your port],2,[hosts][port])
# ARG_HELP([short program description (optional)], [long program description (optional)])
# ARGBASH_GO()

generates the help message:

short program description (optional)
Usage: script [-h|--help] <hostport-1> [<hostport-2>]
	<hostport>: Your hostYour port (defaults for <hostport-2>: 'hostsport')
	-h,--help: Prints help

long program description (optional)

Although they are technically repeated arguments with a max number of 2 repeats, I would like to know if it's possible to customize the template so that it generates my desired output.

Would really appreciate any guidance here. Thanks!

@matejak
Copy link
Owner

matejak commented Jul 31, 2017

Hello, the correct way to go would be to have two instances of ARG_POSITIONAL_SINGLE.
Argbash should not complain about this, unless both of those arguments have defaults. Why? The short version of explanation would be that if both arguments have defaults, then it is unclear what was specified, was it the port, or the host?
If you want defaults for both, then the cleanest solution for the time being would be to have one positional argument with default for host and one optional argument with default for the port number.
For the sake of completness: The output of ARG_POSITIONAL_MULTI from your example is OK (i.e. it is not a bug). Specifying [host][port] is the same as [hostport].

@matejak
Copy link
Owner

matejak commented Jul 25, 2019

The question is answered in the previous comment.

@matejak matejak closed this as completed Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants