cobra
cobra copied to clipboard
fix: Prevent getCompletions from modifying os.Args
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")
}
}