Skip to content
Myr

Create new buffer if not present yet (#549)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes a nil dereference when TraverseChildren is used with multiple subcommands.

authored by Thomas Cyron · committed by Albert Nigmatzianov · parent 7cd9cc6 · Browse files · 2 files+29 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−0 removed

  • other:+29 added−0 removed

2 files+29 added−0 removed

modified:command_test.go+26 added
437 unmodified lines
438 t.Fatalf("wrong command %q expected %q", c.Name(), sub.Name())439 }440}441442func TestTraverseWithTwoSubcommands(t *testing.T) {443 cmd := &Command{444 Use: "do",445 TraverseChildren: true,446 }447448 sub := &Command{449 Use: "sub",450 TraverseChildren: true,451 }452 cmd.AddCommand(sub)453454 subsub := &Command{455 Use: "subsub",456 }457 sub.AddCommand(subsub)458459 c, _, err := cmd.Traverse([]string{"sub", "subsub"})460 if err != nil {461 t.Fatalf("Expected no error: %s", err)462 }463 if c.Name() != subsub.Name() {464 t.Fatalf("wrong command %q expected %q", c.Name(), subsub.Name())465 }466}467468func TestRequiredFlags(t *testing.T) {469 c := &Command{Use: "c", Run: func(*Command, []string) {}}470 output := new(bytes.Buffer)471 c.SetOutput(output)
55 unmodified lines
modified:command.go+3 added
1358 unmodified lines
1359 if c.DisableFlagParsing {1360 return nil1361 }13621363 if c.flagErrorBuf == nil {1364 c.flagErrorBuf = new(bytes.Buffer)1365 }1366 beforeErrorBufLen := c.flagErrorBuf.Len()1367 c.mergePersistentFlags()1368 err := c.Flags().Parse(args)1369 // Print warnings if they occurred (e.g. deprecated flag messages).
40 unmodified lines