Skip to content
This repository

subparsers show arguments from the main parser #15

Closed
jimparis opened this Issue · 1 comment

2 participants

jimparis Andrey Kislyuk
jimparis

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
Andrey Kislyuk kislyuk closed this in 7bd25c3
Andrey Kislyuk
Owner

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
Something went wrong with that request. Please try again.