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

Skip completion for specific argument #223

Closed
dirk-thomas opened this issue Aug 15, 2017 · 2 comments
Closed

Skip completion for specific argument #223

dirk-thomas opened this issue Aug 15, 2017 · 2 comments

Comments

@dirk-thomas
Copy link
Contributor

I would like a specific argument (e.g. --foo) to not appear in the completion. Since the application is pretty modular I can't configure e.g. the global CompletionFinder. I found the option to set help=argparse.SUPPRESS but I still want a help text to be shown for --help.

I was thinking if something like this would be feasible:

arg = parser.add_argument('--foo', help='awesome option')
arg.completer = False

If anyone could be give me some pointers I am happy to provide a PR for this feature idea.

@kislyuk
Copy link
Owner

kislyuk commented Aug 15, 2017

Sounds like a good idea. My preference would be to create a special completer class in https://github.com/kislyuk/argcomplete/blob/master/argcomplete/completers.py, class SuppressCompleter or something like that, and then its optional strings will be suppressed from completions. So you'd say:

arg = parser.add_argument('--foo', help='awesome option')
arg.completer = argcomplete.completers.SuppressCompleter

You need to add the new class, logic to

for action in parser._actions:
if action.help == argparse.SUPPRESS and not self.print_suppressed:
continue
(same branch path as the one triggered by argparse.SUPPRESS), and a test.

@dirk-thomas
Copy link
Contributor Author

@kislyuk Thank you for the detailed pointers. Based on that I was able to create #224. Beside on test related question on that PR it seemed pretty straight forward.

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