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

Repeatable commands with optional arguments doesn't work in experimental branch #42

Closed
shabbyrobe opened this issue Aug 1, 2012 · 3 comments

Comments

@shabbyrobe
Copy link
Member

It feels like #4 will solve this problem (though a solution for #4 does indeed seem like it will be anything but trivial), but when I try to provide optional arguments to a repeatable subcommand, the indexing makes it impossible to work out which command each argument belongs to.

The following example raises an IndexError on the third iteration because the --speed 999 gets interpreted as part of the second go command rather than the third:

import docopt
arguments = docopt.docopt(
    "usage: prog (go <direction> [--speed=<km/h>])...",
    "go forwardnotbackward --speed 123  go upwardnotforward  go twirling --speed 999"
)

for i in xrange(0, arguments['go']):
    print arguments['<direction>'][i]
    print arguments['--speed'][i]
@keleshev
Copy link
Member

keleshev commented Aug 1, 2012

Doing (go <direction> [--speed=<km/h>])... is not possible in any other cli parser (as I know), so I wouldn't say:

Repeatable commands with optional arguments doesn't work

They work as intended. But maybe what I intended is not optimal.

However, #4 lacks API and I don't know how to resolve it or this issue yet. Any ideas?

@keleshev
Copy link
Member

keleshev commented Aug 9, 2012

Maybe args['go'] should accumulate arguments and options passed after it? Right now commands are treated same as flag options (they are True/False or counted). However, maybe, they should be treated more like options with arguments? I.e. having other options/arguments as its value?

@ghost ghost mentioned this issue Aug 9, 2012
@keleshev
Copy link
Member

keleshev commented Oct 8, 2012

Any ideas? How do we solve this? Is this a problem?

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