Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
metal3d opened this issue Jun 7, 2023 · 5 comments
Open

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

metal3d opened this issue Jun 7, 2023 · 5 comments

Comments

@metal3d
Copy link

metal3d commented Jun 7, 2023

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
@marckhouzam
Copy link
Collaborator

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

@metal3d
Copy link
Author

metal3d commented Jun 10, 2023

It's the 1.7.0 (latest release).

@marckhouzam
Copy link
Collaborator

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

@marckhouzam
Copy link
Collaborator

@metal3d Have you been able to resolve your issue?

@metal3d
Copy link
Author

metal3d commented Oct 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants