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

Add support for enumerations #45

Closed
ghost opened this issue Aug 9, 2012 · 5 comments
Closed

Add support for enumerations #45

ghost opened this issue Aug 9, 2012 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 9, 2012

We can already do this:

Usage: go (north | west | east | south)

But this uses subcommands, which have an awkward access syntax, and issues #42 and #4 suggest to me they're meant for something rather more heavy-duty. Moreover, the set of legal values might be too verbose or too large to enumerate in an usage pattern. In such cases, something like this would be more useful:

Usage: go <direction>

  <direction>  The direction to go in (north, west, east, south)
@sonwell
Copy link

sonwell commented Aug 9, 2012

There is support for this in the form of

args = docopt(...)

if args['<direction>'] not in ['north', 'west', 'east', 'south']:
    raise SomeException

@keleshev
Copy link
Member

keleshev commented Aug 9, 2012

This could be done for options with arguments:

Usage: prog [options]

--option=(this | that | or-that)

but dunno how to do it nicely for positional arguments...

@ghost
Copy link
Author

ghost commented Aug 10, 2012

We've already got syntax for default values, which seems to me to be a intuitive basis for this (and other argument value metadata stuff, like in #8.) If/when #37 gets implemented, it would naturally also apply to positional arguments. Something like this:

  <direction>  The direction to go in [north, south, west, east, default: north]

Vis-a-vis prior art, the only programs I could think of that have arguments like this were xrandr and xsetwacom, who communicate the idea with

--rotate normal,inverted,left,right
--orientation <normal,inverted,left,right,0,1,2,3>
Rotate           - Sets the rotation of the tablet. Values = none, cw, ccw, half (default is none).

But I don't really like any of them.

@keleshev
Copy link
Member

Maybe this should be dropped (similar to #8) in favor of using schema-validation tools instead, like in this example:

https://github.com/docopt/docopt/blob/master/examples/validation_example.py

@keleshev
Copy link
Member

keleshev commented Oct 8, 2012

This issue is a special case of #52, further discussion is directed there.

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

2 participants