subparsers show arguments from the main parser #15

jimparis opened this Issue Mar 2, 2013 · 1 comment

2 participants


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

args = parser.parse_args()

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

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

./ put <tab>
expect: (no suggestions)
actual: --help --url -h
@kislyuk kislyuk closed this in 7bd25c3 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