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

Bug: Not completing subparsers #54

Closed
shachargluska opened this issue Oct 11, 2021 · 1 comment · Fixed by #53
Closed

Bug: Not completing subparsers #54

shachargluska opened this issue Oct 11, 2021 · 1 comment · Fixed by #53
Assignees
Labels
documentation Markdown files

Comments

@shachargluska
Copy link

Hi, thanks for your great work.
I'm trying to get shtab to autocomplete my script, but I'm having trouble.
I don't seem to be able to get it to work with subparsers.

Env:
python: Python 3.6.9
shtab: shtab 1.4.1

A small example:

#!/usr/bin/env python
import argparse


def get_main_parser():
    parser = argparse.ArgumentParser(prog="pathcomplete")
    subs = parser.add_subparsers()
    sub = subs.add_parser('action')
    sub.add_argument("--sum", default=None)
    sub.add_argument("--other", default=None)
    return parser


if __name__ == "__main__":
    parser = get_main_parser()
    args = parser.parse_args()
    print(args)

shtab appears to work in the sense that it can complete "-h" and "--help" (so setup is most likely correct)
But I don't see "action" or its arguments.

@casperdcl casperdcl added the documentation Markdown files label Oct 11, 2021
@casperdcl casperdcl self-assigned this Oct 11, 2021
@casperdcl
Copy link
Collaborator

Ah this was introduced in shtab>=1.4.0 (#47) but forgot to update examples/customcomplete.py.

Basically you need to "unhide" your subparsers by giving them help messages:

-    subs.add_parser('action')
+    subs.add_parser('action', help="some useful functionality")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Markdown files
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants