Skip to content
Myr

considering stderr in UsageString

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

authored by Juan Leni · committed by Steve Francia · parent e35034f · Browse files · 2 files+26 added−1 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+26 added−1 removed

  • other:+26 added−1 removed

2 files+26 added−1 removed

modified:command_test.go+16 added
1403 unmodified lines
1404 t.Errorf("Expected setting input to nil to revert back to stdin")1405 }1406}14071408func TestUsageStringRedirected(t *testing.T) {1409 c := &Command{}14101411 c.usageFunc = func(cmd *Command) error {1412 cmd.Print("[stdout1]")1413 cmd.PrintErr("[stderr2]")1414 cmd.Print("[stdout3]")1415 return nil;1416 }14171418 expected := "[stdout1][stderr2][stdout3]"1419 if got := c.UsageString(); got != expected {1420 t.Errorf("Expected usage string to consider both stdout and stderr")1421 }1422}14231424func TestFlagErrorFunc(t *testing.T) {1425 c := &Command{Use: "c", Run: emptyRun}14261427 expectedFmt := "This is expected: %v"
348 unmodified lines
modified:command.go+10 added-1 removed
382 unmodified lines
383 c.HelpFunc()(c, []string{})384 return nil385}386387// UsageString return usage string.387// UsageString returns usage string.388func (c *Command) UsageString() string {389 // Storing normal writers390 tmpOutput := c.outWriter391 tmpErr := c.errWriter392393 bb := new(bytes.Buffer)394 c.outWriter = bb395 c.errWriter = bb396397 c.Usage()398399 // Setting things back to normal400 c.outWriter = tmpOutput401 c.errWriter = tmpErr402403 return bb.String()404}405406// FlagErrorFunc returns either the function set by SetFlagErrorFunc for this
1188 unmodified lines