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

Why cannot docopt parse args? #513

Open
monagai opened this issue May 31, 2023 · 3 comments
Open

Why cannot docopt parse args? #513

monagai opened this issue May 31, 2023 · 3 comments

Comments

@monagai
Copy link

monagai commented May 31, 2023

python=3.10,6, docopt==0.6.2

[test.py]

#!/usr/bin/env python3
"""
Usage: 
    test.py [-h|--help] [-b|--bbbbb] (-r <rvalue>) [-o <ovalue>] [-l <lvalues>...]
options:
    -h,--help       show this help message and exit
    -b,--bbbbb      b option  (optional)
    -r <r_value>    r value   (required)
    -o <o_value>    o value   (optional) [default: 1.0]
    -l <l_values>   l values  (optional)
"""
print('point1')
from docopt import docopt
args = docopt(__doc__)

print('point2')
print(args)
$ ./test.py -r xxx
point1
usage:
    test.py [-h|--help] [-b|--bbbbb] (-r <r_value>) [-o <o_value>] [-l <l_values>...]
options:
    -h,--help       show this help message and exit
    -b,--bbbbb      b option  (optional)
    -r <r_value>    r value   (required)
    -o <o_value>    o value   (optional) [default: 1.0]
    -l <l_values>   l values  (optional)

Wny does this script stop at args = docopt(__doc__)?

@TylerTemp
Copy link

I believe that [-l <l_values>...] is not a thing. docopt only accepts standard POSIX style, which a flag can either accept 0 or 1 argument.

@Sylvain303
Copy link

Wny does this script stop at args = docopt(doc)?

Try: pip install docopt-ng (#371)

outputs:

./t.py -r xxx
point1
point2
{'--bbbbb': False,
 '--help': False,
 '-l': [],
 '-o': '1.0',
 '-r': 'xxx'}

This should be fine, right?

@monagai
Copy link
Author

monagai commented Jun 1, 2023

Thank you for your comment! @TylerTemp , @Sylvain303

I believe that [-l <l_values>...] is not a thing

I changed the setting. However, it still stops. I cannot find the reason.

"""
Usage: 
    test.py [-h|--help] [-b|--bbbbb] (-r <rvalue>) [-o <ovalue>] [-l <lvalue>]
options:
    -h,--help       show this help message and exit
    -b,--bbbbb      b option  (optional)
    -r <rvalue>    r value   (required)
    -o <ovalue>    o value   (optional) [default: 1.0]
    -l <lvalue>   l values  (optional)
"""

Try: pip install docopt-ng

Thank you! It works.

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

3 participants