-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Hide auto-generated completion command #1507
Comments
Hi @blacktop, there is currently no way to hide the I think it would be nice to add such an option to Cobra. |
one of the ways to keep for example if you just copy the template from Line 501 in de187e8
...into this1: Available commands:
{{range .Commands}}
{{if and (ne .Name "completion") .IsAvailableCommand}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}
{{end}}
{{end}}
{{if .HasAvailableLocalFlags}} it should hide completion from listing it under "Available commands:".. Footnotes
|
@marckhouzam - is this something we could tackle in the next release? That would be great |
I was hoping to make the command public so that people could adapt it any way they want, but IIRC it is not that easy. I'll try again and if I can't figure it out, I'll add an new completionOption to allow hiding the command. Glad to have you back @jpmcb 😄 |
Fixes spf13#1507 This allows a program to set whatever field it wants on the default completion command before calling rootCmd.Execute(). For example, cobra.CompletionCmd.Hidden = true // To make the command hidden or/and cobra.CompletionCmd.Use = "shellcomplete" // To rename the command Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 This allows a program to set whatever field it wants on the default completion command before calling rootCmd.Execute(). For example, cobra.CompletionCmd.Hidden = true // To make the command hidden or/and cobra.CompletionCmd.Use = "shellcomplete" // To rename the command Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 This allows a program to set whatever field it wants on the default completion command before calling rootCmd.Execute(). For example, cobra.CompletionCmd.Hidden = true // To make the command hidden or/and cobra.CompletionCmd.Use = "shellcomplete" // To rename the command Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes spf13#1507 Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Fixes #1507 Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
@blacktop i rewrite the completion command, can hide the completion subcommand, code examples: func completionCommand() *cobra.Command {
return &cobra.Command{
Use: "completion",
Short: "Generate the autocompletion script for the specified shell",
}
}
func init() {
completion := completionCommand()
// mark completion hidden
completion.Hidden = true
rootCommand.AddCommand(completion)
// other subcommands
rootCommand.AddCommand(...)
} |
@marckhouzam Are there new docs explaining how to hide the "completion" sub-command? AFAI can see, the line: |
Is there a way to hide the
completion
cmd? I like having it, but don't want it to show up in --helpThanks!
The text was updated successfully, but these errors were encountered: