You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow hiding tab-completion values from help #1976
I have an argument for one of my commands which represents a path/ID to a resource. I want to be able to provide tab-completion to allow easily cycling between existing paths/IDs, but I don't want these values to be enumerated if I run --help for my command.
I'm thinking this could be an option on the CompletionItem object, like a boolean property called Hidden. You could then do something this like.
varmyarg=newOption<string>("--id","The id of the item to get");myarg.AddCompletions(ctx =>GetIdSuggestions(ctx));privateIEnumerable<CompletionItem>GetIdSuggestions(CompletionContextctx)=>GetExistingIds(prefix:ctx.WordToComplete).Select(id =>newCompletionItem(id){Hidden=true});
and then when you attempt to run the command from the terminal
app command --id <TAB>
it will cycle through existing IDs returned by my method, but when I run
app command --help
It will still only print out
Options:
--id <id> The id of the item to get
rather than
Options:
--id <id1|id2|id3|id4|...> The id of the item to get
You can hide the completions of the option argument from help by setting the ArgumentHelpName property. Help will still enumerate the completions though, just not display them. dotnet/sdk#27374 (comment), #2038
Thanks! For the benefit of those who stumble upon this issue trying to do the same thing, the solution is to do the following
varmyarg=newArgument<string>("arg","An argument with completions"){HelpName="arg"};myarg.AddCompletions(/*...*/);varmyopt=newOption<string>("--opt","An option with completions"){ArgumentHelpName="opt"};myopt.AddCompletions(/*...*/);
which will produce the following output when you run --help
Arguments:
<arg> An argument with completions
Options:
--opt <opt> An option with completions
Activity
KalleOlaviNiemitalo commentedon Nov 23, 2022
You can hide the completions of the option argument from help by setting the ArgumentHelpName property. Help will still enumerate the completions though, just not display them. dotnet/sdk#27374 (comment), #2038
CurtisLusmore commentedon Nov 23, 2022
Thanks! For the benefit of those who stumble upon this issue trying to do the same thing, the solution is to do the following
which will produce the following output when you run
--help