matejak / argbash

Bash argument parsing code generator
Other
1.4k stars 62 forks source link

Multiple required positional arguments? #17

Closed btamayo closed 5 years ago

btamayo commented 7 years ago

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 commented 7 years ago

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 commented 5 years ago

The question is answered in the previous comment.