-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
R4R: add command to generate bash completion for gaia{d,cli} #3334
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,38 @@ func UpgradeOldPrivValFile(config *cfg.Config) { | |
} | ||
} | ||
|
||
// NewCompletionCmd builds a cobra.Command that generate bash completion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this wants to live somewhere in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// scripts for the given root command. If hidden is true, the command | ||
// will not show up in the root command's list of available commands. | ||
func NewCompletionCmd(rootCmd *cobra.Command, hidden bool) *cobra.Command { | ||
flagZsh := "zsh" | ||
cmd := &cobra.Command{ | ||
Use: "completion", | ||
Short: "Generate Bash/Zsh completion script to STDOUT", | ||
Long: `To load completion script run | ||
|
||
. <(completion_script) | ||
|
||
To configure your bash shell to load completions for each session add to your bashrc | ||
|
||
# ~/.bashrc or ~/.profile | ||
. <(completion_script) | ||
`, | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
if viper.GetBool(flagZsh) { | ||
return rootCmd.GenZshCompletion(os.Stdout) | ||
} | ||
return rootCmd.GenBashCompletion(os.Stdout) | ||
}, | ||
Hidden: hidden, | ||
Args: cobra.NoArgs, | ||
} | ||
|
||
cmd.Flags().Bool(flagZsh, false, "Generate Zsh completion script") | ||
|
||
return cmd | ||
} | ||
|
||
func skipInterface(iface net.Interface) bool { | ||
if iface.Flags&net.FlagUp == 0 { | ||
return true // interface down | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is admirable, maybe we provide short examples of how to link it in your
bash
andzsh
profiles?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just link to docs: https://debian-administration.org/article/316/An_introduction_to_bash_completion_part_1
https://github.com/spf13/cobra/blob/master/bash_completions.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more info here: https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion