Add experimental support for bash autocomplete
This commit is contained in:
parent
71946ada6f
commit
7fa01a2a74
31
cmd/basecli/commands/auto.go
Normal file
31
cmd/basecli/commands/auto.go
Normal file
@ -0,0 +1,31 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var AutoCompleteCmd = &cobra.Command{
|
||||
Use: "complete",
|
||||
Short: "generate bash autocompletions",
|
||||
RunE: doAutoComplete,
|
||||
}
|
||||
|
||||
const (
|
||||
FlagOutput = "file"
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutoCompleteCmd.Flags().String(FlagOutput, "", "file to output bash autocompletion")
|
||||
AutoCompleteCmd.MarkFlagFilename(FlagOutput)
|
||||
}
|
||||
|
||||
func doAutoComplete(cmd *cobra.Command, args []string) error {
|
||||
output := viper.GetString(FlagOutput)
|
||||
if output == "" {
|
||||
return cmd.Root().GenBashCompletion(os.Stdout)
|
||||
}
|
||||
return cmd.Root().GenBashCompletionFile(output)
|
||||
}
|
||||
@ -56,6 +56,7 @@ func main() {
|
||||
tr,
|
||||
proxy.RootCmd,
|
||||
coincmd.VersionCmd,
|
||||
bcmd.AutoCompleteCmd,
|
||||
)
|
||||
|
||||
cmd := cli.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user