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

command line parsing is storing some options multiple times #60

Open
ThosRTanner opened this issue Jan 26, 2024 · 2 comments
Open

command line parsing is storing some options multiple times #60

ThosRTanner opened this issue Jan 26, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ThosRTanner
Copy link
Contributor

ThosRTanner commented Jan 26, 2024

This little program here:

#!/usr/bin/env python

"""
Usage:
    test.py [--to=SITE]... [--] FILE...
    test.py [--to=SITE]... --config CONFIG [[--] FILE...]

Options:
    --config CONFIG     Configuration file.
    --to=SITE           Target site

"""

import docopt

options = docopt.docopt(__doc__)
print(options)

If I run test.py --to a --to b c, I get this output:

{'--': False,
 '--config': None,
 '--to': ['a', 'b', 'b'],
 'FILE': ['c']}

Notice the double occurrence of 'b'

@NickCrews
Copy link
Contributor

Thanks for this! I can reproduce.

I don't actually understand the parser that well (I inherited maintainership but didn't write it), and I don't even use docopt anymore, so if you want this fixed, I think you will need to do the work. Sorry, and thank you!

@NickCrews NickCrews added bug Something isn't working help wanted Extra attention is needed labels Mar 29, 2024
@NickCrews
Copy link
Contributor

To repro, add this to the end of testcases.docopt:

# https://github.com/jazzband/docopt-ng/issues/60
r"""
Usage:
    test.py [--to=SITE]... [--] FILE...
    test.py [--to=SITE]... --config CONFIG [[--] FILE...]

Options:
    --config CONFIG     Configuration file.
    --to=SITE           Target site
"""
$ prog --to a --to b c
{"--": false, "--config": null, "--to": ["a", "b"], "FILE": ["c"]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants