Skip to content

Question: complement debug give correct output, but the normal usage fails #1264

@Yiyiyimu

Description

@Yiyiyimu

Hi community,

Thanks for the work, it's brilliant! My main part of code would be like

func init() {
	o := &DebugOptions{}
	validArgs := []string{"networkchaos", "stresschaos"}

	var debugCmd = &cobra.Command{
		Use:   `debug (CHAOSTYPE) [-c CHAOSNAME] [-n NAMESPACE]`,
		Short: `Print the debug information for certain chaos`,
		Long: `Print the debug information for certain chaos`
	}
	debugCmd.Flags().StringVarP(&o.Namespace, "namespace", "n", "default", "namespace to find chaos")

	if err := flagCompletion(debugCmd); err != nil {
		log.Fatal(err)
	}

	rootCmd.AddCommand(debugCmd)
}

And I use the default template for completion.go in shell-completion

So there would be two part of completion, one for noun and another one for flags. Both were tested correctly using debug like

~ chaosctl __complete debug -n ""
chaos-testing
default
kube-node-lease
kube-public
kube-system
local-path-storage
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

~ chaosctl __complete debug ""
networkchaos
stresschaos
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

And since I'm using zsh, I do source <(chaosctl completion zsh) to activate completion. But when I really use it, the completion would just showing files and dirs, so it seems not working. However when I use the same method to activate completion for helm, everything works fine.

Is there any way to test if completion is working?

cobra version: v1.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions