cobra icon indicating copy to clipboard operation
cobra copied to clipboard

fix: Prevent getCompletions from modifying os.Args

Open jonathan-conder opened this issue 8 months ago • 1 comments

Possible fix for https://github.com/spf13/cobra/issues/2257.

Tested using this test case:

func TestModifiedArgs(t *testing.T) {
	cmd := &Command{TraverseChildren: true}
	args := []string{"__complete", ""}
	cmd.SetArgs(args)
	if err := cmd.Execute(); err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if len(args) != 2 || args[1] != "" {
		t.Error("Modified args")
	}
}

jonathan-conder avatar Mar 12 '25 00:03 jonathan-conder