Repeating argument inside [options]
See original GitHub issueHi.
I was trying to simplify some scripts by using [options]
but i got into a issue when i had to have repeating arguments.
The following code is the old way where i have to define the repeating arguments in the usage section
from docopt import docopt
__docopt__ = """
usage:
script foo <bar> [-v ...] [options]
Options:
<bar> Key identifier username
-v increase verbosity
"""
args = docopt(__docopt__)
print(args)
that works fine when callde with
$ python repeat_broken.py foo asd -vvv
{'-v': 3,
'<bar>': 'asd',
'foo': True}
but when trying to move the repeating part down to the options definition i get the following
from docopt import docopt
__docopt__ = """
usage:
script foo <bar> [options]
Options:
<bar> Key identifier username
-v ... increase verbosity
"""
args = docopt(__docopt__)
print(args)
and called with
$ python repeat_broken.py foo asd -vvv
{'-v': 'vv',
'<bar>': 'asd',
'foo': True}
In this case it interpretates the ...
as something different then when defined in the usage section.
Is it intended that ...
should not be possible to use in the options section or is this a bug?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Repeating arguments specified in options list - docopt
I'm aware that having repeating optional arguments is possible, I would just really prefer to specify so inside the options description ...
Read more >Declare function argument validation - MATLAB arguments
Repeating arguments are single arguments or groups of arguments that can be repeated zero or more times in a function call. The fRepeat...
Read more >Multiple CLI Options - Typer - tiangolo
You can declare a CLI option that can be used multiple times, and then get all the values. For example, let's say you...
Read more >Difference between multiple arguments and options object
Example: This is an example of multiple arguments in javascript. Actually arguments is not like an arrays, It does not follow the array ......
Read more >Command-line syntax overview for System.CommandLine
CommandLine can be configured to accept multiple arguments for one option without repeating the option name. In the following example, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cargo also recently ran into this problem, our doc string should in theory allow commands of the form:
but unfortunately you can only pass one
--bin
for now. We could in theory modify the usage string to include[--bin NAME ...]
, but we’d have to repeat that for--test
,--example
, etc, and also repeat that across the other subcommands that Cargo has. Overall I agree with @BurntSushi that modifying the options section would be what I’d love to see as well!I have an experimental implementation of this working and I think it works quite nicely. I basically just took the idea in the OP and ran with it. If
...
proceeds a flag name/argument in an option description (separated by exactly one space, just like the argument), then that flag is allowed to be repeated an arbitrary number of times. Namely, this:is equivalent to
I’ve written down some test cases that should clarify the rest:
Two notes:
.
. I don’t think I’ve ever seen such a flag argument name in the wild, so I think that’s OK.-aa
). I’m not convinced we want that much flexibility in the option descriptions, and if we did, it could always be added later.