diff --git a/cmd/neutrond/root.go b/cmd/neutrond/root.go index 112182eba..2c5c7a940 100644 --- a/cmd/neutrond/root.go +++ b/cmd/neutrond/root.go @@ -113,6 +113,8 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { }, } + genAutoCompleteCmd(rootCmd) + initRootCmd(rootCmd, encodingConfig) initClientCtx, err := config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx) if err != nil { @@ -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) + } + }, + }) +}