Skip to content

Commit

Permalink
Add autocomplete generator to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
shapeshed committed Jul 5, 2024
1 parent dabafd6 commit b57e66c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmd/neutrond/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
},
}

genAutoCompleteCmd(rootCmd)

initRootCmd(rootCmd, encodingConfig)
initClientCtx, err := config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
if err != nil {
Expand Down Expand Up @@ -385,3 +387,35 @@ func setCustomEnvVariablesFromClientToml(ctx client.Context) {
// memo
setEnvFromConfig("note", "NEUTROND_NOTE")
}

func genAutoCompleteCmd(rootCmd *cobra.Command) {
rootCmd.AddCommand(&cobra.Command{
Use: "enable-cli-autocomplete [bash|zsh|fish|powershell]",
Short: "Generates cli completion scripts",
Long: `To configure your shell to load completions for each session, add to your profile:
# bash example
echo '. <(neutrond enable-cli-autocomplete bash)' >> ~/.bash_profile
source ~/.bash_profile
# zsh example
echo '. <(neutrond enable-cli-autocomplete zsh)' >> ~/.zshrc
source ~/.zshrc
`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
_ = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
_ = cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
_ = cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
_ = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
},
})
}

0 comments on commit b57e66c

Please sign in to comment.