cobra icon indicating copy to clipboard operation
cobra copied to clipboard

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

Open metal3d opened this issue 1 year ago • 5 comments

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:

  • bash v5 + bash-completion
  • oh-my-posh (no special configuration)
  • Fedora 38
  • kitty-terminal
  • menu-complete option in inputrc

metal3d avatar Jun 07 '23 06:06 metal3d

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

marckhouzam avatar Jun 08 '23 01:06 marckhouzam

It's the 1.7.0 (latest release).

metal3d avatar Jun 10 '23 08:06 metal3d

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

marckhouzam avatar Jun 10 '23 23:06 marckhouzam

@metal3d Have you been able to resolve your issue?

marckhouzam avatar Oct 18 '23 20:10 marckhouzam

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.

metal3d avatar Oct 19 '23 15:10 metal3d