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

subparsers show arguments from the main parser #15

Closed
jimparis opened this issue Mar 2, 2013 · 1 comment
Closed

subparsers show arguments from the main parser #15

jimparis opened this issue Mar 2, 2013 · 1 comment

Comments

@jimparis
Copy link
Contributor

jimparis commented Mar 2, 2013

With this program:

#!/usr/bin/env python
import argparse
import argcomplete

def c_url(prefix, parsed_args, **kwargs):
    return [ "http://url1", "http://url2" ]

def c_get(prefix, parsed_args, **kwargs):
    return [ "get1", "get2" ]

def c_put(prefix, parsed_args, **kwargs):
    return [ ]

parser = argparse.ArgumentParser()
parser.add_argument("--url", help="URL").completer = c_url
sub = parser.add_subparsers()

get = sub.add_parser("get")
get.add_argument("filename").completer = c_get

put = sub.add_parser("put")
put.add_argument("filename").completer = c_put

argcomplete.autocomplete(parser)
args = parser.parse_args()

Arguments like --url show up after get and put, where they're not allowed:

./test.py get <tab>
expect: get1 get2
actual: --help --url -h get1 get2

./test.py put <tab>
expect: (no suggestions)
actual: --help --url -h
@kislyuk kislyuk closed this as completed in 7bd25c3 Mar 6, 2013
@kislyuk
Copy link
Owner

kislyuk commented Mar 6, 2013

Thanks for reporting (btw, -h/--help are valid completions in your examples, and are still produced after this fix).

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