Skip to content

Commit

Permalink
Fix zsh completion (#806)
Browse files Browse the repository at this point in the history
* revert hack: it was breaking flag description

* square brackets did not got escaped correctly in the completion script
  • Loading branch information
umbynos committed Jul 9, 2020
1 parent b148c00 commit b2ed18f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cli/cli.go
Expand Up @@ -96,9 +96,9 @@ func createCliCommandTree(cmd *cobra.Command) {
viper.BindPFlag("logging.level", cmd.PersistentFlags().Lookup("log-level"))
cmd.PersistentFlags().String("log-file", "", "Path to the file where logs will be written.")
viper.BindPFlag("logging.file", cmd.PersistentFlags().Lookup("log-file"))
cmd.PersistentFlags().String("log-format", "", "The output format for the logs, can be [text|json].")
cmd.PersistentFlags().String("log-format", "", "The output format for the logs, can be {text|json}.")
viper.BindPFlag("logging.format", cmd.PersistentFlags().Lookup("log-format"))
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be [text|json].")
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be {text|json}.")
cmd.PersistentFlags().StringVar(&configFile, "config-file", "", "The custom config file (if not specified the default will be used).")
cmd.PersistentFlags().StringSlice("additional-urls", []string{}, "Additional URLs for the board manager.")
viper.BindPFlag("board_manager.additional_urls", cmd.PersistentFlags().Lookup("additional-urls"))
Expand Down
9 changes: 1 addition & 8 deletions cli/completion/completion.go
Expand Up @@ -56,14 +56,7 @@ func run(cmd *cobra.Command, args []string) {
cmd.Root().GenBashCompletion(os.Stdout)
break
case "zsh":
buf := new(bytes.Buffer)
cmd.Root().GenZshCompletion(buf)
// Next 3 lines are Hack, we'll wait new version of cobra with ZshV2Completion https://github.com/spf13/cobra/pull/1070
//insert escaping before [ and ]
s := strings.ReplaceAll(buf.String(), "[", "\\[")
s = strings.ReplaceAll(s, "]", "\\]")
s = strings.ReplaceAll(s, "\\[1\\]", "[1]") // revert the case
os.Stdout.WriteString(s)
cmd.Root().GenZshCompletion(os.Stdout)
break
case "fish":
buf := new(bytes.Buffer)
Expand Down

0 comments on commit b2ed18f

Please sign in to comment.