-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(influx): add completion command for users to generate the comple…
…tions for the influx cli
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func completionCmd(rootCmd *cobra.Command) *cobra.Command { | ||
writeZSH := func(w io.Writer) error { | ||
if err := rootCmd.GenZshCompletion(w); err != nil { | ||
return err | ||
} | ||
_, err := io.WriteString(w, "\ncompdef _influx influx\n") | ||
return err | ||
} | ||
|
||
return &cobra.Command{ | ||
Use: "completion [bash|zsh]", | ||
Short: "Generates completion scripts", | ||
Args: cobra.ExactValidArgs(1), | ||
ValidArgs: []string{"bash", "zsh"}, | ||
Long: ` | ||
Outputs shell completion for the given shell (bash or zsh) | ||
OS X: | ||
$ source $(brew --prefix)/etc/bash_completion | ||
$ influx completion bash > ~/.influx-completion # for bash users | ||
$ influx completion zsh > ~/.influx-completion # for zsh users | ||
$ source ~/.influx-completion | ||
Ubuntu: | ||
$ source /etc/bash-completion | ||
$ source <(influx completion bash) # for bash users | ||
$ source <(influx completion zsh) # for zsh users | ||
Additionally, you may want to output the completion to a file and source in your .bashrc/.zshrc | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
switch args[0] { | ||
case "bash": | ||
return rootCmd.GenBashCompletion(rootCmd.OutOrStdout()) | ||
case "zsh": | ||
return writeZSH(rootCmd.OutOrStdout()) | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
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