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 argument name to Options class and make it accessible from the argument dict #346

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

con-f-use
Copy link

@con-f-use con-f-use commented Sep 19, 2016

Consider the option strings:

-o --option=<int>         An Option
-a --another=<float>   Another Option

For post-processing of command line arguments it is sometimes useful to have the argument type available (meaning <int> or <float> in the example above).

E.g. for things like:

    args = docopt(a,[])
    for k, v in args.iteritems():
        atype = [t.atype for t in args.options if t.long == k]
        atype = atype[0] if atype else None
        if atype == '<int>':
            args[k] = int(v)
        elif atype == '<float>':
            args[k] = float(v)     

My pull requests adds the atype property to the Option class which stores the argument type (or whatever <int> and <float> might be called in above example strings). It then makes the results from following line in docopt(...) available:

options = parse_defaults(doc)

It can be accessed from the argument dictionary like so:

from docopt import docopt
args = docopt(a,[])
args.options

Everything else remains unchanged.

@con-f-use
Copy link
Author

The travis "All checks have failed" doesn't seem to come from my changes:

0.19s$ pip install tox --use-mirrors
Usage:   
  pip install [options] <requirement specifier> [package-index-options] ...
  ...
no such option: --use-mirrors

@con-f-use
Copy link
Author

@mboersma yes? no? maybe?

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

Successfully merging this pull request may close these issues.

None yet

1 participant