spf13 / cobra

A Commander for modern Go CLI interactions
https://cobra.dev
Apache License 2.0
37.58k stars 2.83k forks source link

Description in completion in double (not sure it's a Cobra issue) #1973

Open metal3d opened 1 year ago

metal3d commented 1 year ago

First, thanks a lot to develop this package. It makes all our work so smooth :)

Now, I've got a little problem.

I generate the completion command this way:

func generateCompletionCommand(name string) *cobra.Command {
    bashV1 := false
    cmd := &cobra.Command{
        Use:                   "completion",
        DisableFlagsInUseLine: true,
        ValidArgs:             []string{"bash", "zsh", "fish", "powershell"},
        Args:                  cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
        Short:                 "Generates completion scripts",
        Long:                  fmt.Sprintf(completionHelp, name),
        Run: func(cmd *cobra.Command, args []string) {
            if len(args) == 0 {
                cmd.Help()
                return
            }
            switch args[0] {
            case "bash":
                // get the bash version
                if cmd.Flags().Changed("bash-v1") {
                    cmd.Root().GenBashCompletion(os.Stdout)
                    return
                }
                cmd.Root().GenBashCompletionV2(os.Stdout, true)
            case "zsh":
                cmd.Root().GenZshCompletion(os.Stdout)
            case "fish":
                cmd.Root().GenFishCompletion(os.Stdout, true)
            case "powershell":
                cmd.Root().GenPowerShellCompletion(os.Stdout)
            }
        },
    }

    // add a flag to force bash completion v1
    cmd.Flags().Bool("bash-v1", bashV1, "Force bash completion v1")

    return cmd
}

No need to use \t to get completion and it works... excepting that the descriptions are display in double. The left column is OK, while the second breaks the shell command.

See this screencast: capture

I don't understand why this breaks.

Note:

marckhouzam commented 1 year ago

What version of Cobra are you using @metal3d ? This looks like #1508 which I thought we'd fixed...

metal3d commented 1 year ago

It's the 1.7.0 (latest release).

marckhouzam commented 1 year ago

can you remove the menu-complete option in inputrc and see if things work properly that way?

marckhouzam commented 11 months ago

@metal3d Have you been able to resolve your issue?

metal3d commented 11 months ago

Sorry, a lot of troubles to manage for weeks... I'll try as soon as I can. I put this in my TODO list for the next days.