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

how to implement number argument? #522

Open
xhawk18 opened this issue Mar 1, 2024 · 3 comments
Open

how to implement number argument? #522

xhawk18 opened this issue Mar 1, 2024 · 3 comments

Comments

@xhawk18
Copy link

xhawk18 commented Mar 1, 2024

e.g.
gcc --std=c++20 -O0
gcc --std=c++20 -O1
gcc --std=c++20 -O2

Can I write docotp USAGE like this?
gcc [--std=<ver>] [-O (0|1|2)]
I seems not work.

@Sylvain303
Copy link

Hello @xhawk18

I will suppose you've read http://docopt.org/

So docopt doesn't validate argument, it's up to your code to do so:

In case you missed the fork:

pip install docopt-ng
"""
Usage: ./test-docopt-number.py  [--std=<ver>] [-O NUM_OPTIMIZE]
"""
from docopt import docopt
args = docopt(__doc__)
print(args)


if args['-O']:
    if args['NUM_OPTIMIZE'].isdigit():
        optimization = int(args['NUM_OPTIMIZE'])
    else:
        raise RuntimeError(f"argument NUM_OPTIMIZE must be an int: {args['NUM_OPTIMIZE']}")

    print(f"optimization: {optimization}")

Was it a feature request or an help support?

If it was for help request, stackoverflow would have been a more useful source of information. 😉

@xhawk18
Copy link
Author

xhawk18 commented Mar 4, 2024

Thank you @Sylvain303

It may be a feature request 😉

@Sylvain303
Copy link

Thank you @Sylvain303

It may be a feature request 😉

You're welcome. 😁

Unfortunately this main github repository is deprecated / stalled 😢 see related issue #371
Until someone will takeover or being granted the code here. I'm afraid issues will stack forever for the python version.
For other languages see related repository. 😉

the forked python code ➡️ https://github.com/bazaar-projects/docopt-ng

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