Add bash completion for gaiad and gaiacli (#3334)

This commit is contained in:
Alessio Treglia
2019-01-21 19:42:15 -08:00
committed by Jack Zampolin
parent 7f789d2ed3
commit cffa39cf44
5 changed files with 70 additions and 0 deletions
+33
View File
@@ -2,6 +2,7 @@ package client
import (
"fmt"
"os"
"strconv"
"github.com/spf13/cobra"
@@ -162,3 +163,35 @@ func ParseGas(gasStr string) (simulateAndExecute bool, gas uint64, err error) {
}
return
}
// NewCompletionCmd builds a cobra.Command that generate bash completion
// 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
}