clap icon indicating copy to clipboard operation
clap copied to clipboard

Support excluding a subcommand from shell completion

Open kpcyrd opened this issue 5 years ago • 6 comments

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.

kpcyrd avatar Aug 27 '18 21:08 kpcyrd

Related:

  • https://github.com/clap-rs/clap/issues/2541

epage avatar Dec 08 '21 20:12 epage

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.

pksunkara avatar Dec 10 '21 16:12 pksunkara

See also #3951 for native completion support

epage avatar Jul 19 '22 14:07 epage

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?

fingolfin avatar Jan 15 '24 12:01 fingolfin

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".

epage avatar Jan 15 '24 22:01 epage

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).

kpcyrd avatar Jan 16 '24 18:01 kpcyrd