clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
13.94k stars 1.03k forks source link

Support excluding a subcommand from shell completion #1335

Closed kpcyrd closed 2 weeks ago

kpcyrd commented 6 years ago

Feature Request Summary

I would like to exclude some subcommands from the generated shell completion. For example, the command to generate those completions is usually only used during installation and shouldn't be suggested to the user. I've managed to hide the subcommand from the help text with AppSettings::Hidden, but it's still included in the shell completion.

Expected Behavior Summary

foo <tab><tab>

All commands that are marked with AppSettings::Hidden are not suggested

Actual Behavior Summary

foo <tab><tab>

All commands are suggested.

epage commented 2 years ago

Related:

pksunkara commented 2 years ago

Ideally, we would want this to be configured while creating the generator, but there's a lot more generation related work we would want to look at first to see if the current code is viable for future or not.

epage commented 2 years ago

See also #3951 for native completion support

fingolfin commented 7 months ago

This issue has labels marking it as "easy" and "help wanted". But at the same time it sounds like there are open fundamental questions about whether you want it: e.g. from issue #2541 @pksunkara said Jun 17, 2021:

Need the version you are looking at because this is fixed in master.

and then in Dec 10, 2021:

I think we went back on the decision regarding this and are currently generating hidden subcommands too.

And earlier on this issue, also on Dec 10, 2021

Ideally, we would want this to be configured while creating the generator, but there's a lot more generation related work we would want to look at first to see if the current code is viable for future or not.

So... which is it, is this "easy" and "help wanted", or is there in contrast actually need for design work and experiments and what not? In other words, if someone made a PR for this, would it actually have a chance of being merged?

epage commented 7 months ago

Its been a couple years and I unfortunately didn't take enough notes here. I think it'd be reasonable to emulate what we can from the proposal in #3951 would be reasonable. That basically means (1) don't suggest hidden items but (2) complete within them where we can. The part we likely can't emulate is "complete the hidden item if its the only choice left".

kpcyrd commented 7 months ago

For my specific use case it would be fine to have it fully excluded, without the need for (2). (however I wouldn't mind having (2)).

The subcommand is foo generate-completions ... and probably only ever used when generating a package. It's useful to have this subcommand available but the user would likely never want to invoke it themselves (if they really want to they could however).

epage commented 2 weeks ago

This was resolved in #5549. When using clap_complete::dynamic, we only show hidden subcommands if there is no other valid completion option.

To track stabilization, see #3166