From 6a174752baac0c77696092d7a261bba3a6f702ad Mon Sep 17 00:00:00 2001 From: John McBride Date: Fri, 3 Apr 2020 13:02:05 -0600 Subject: [PATCH] Still include SetOutput as it is exported This reverts commit 6291af1f4d5e747bc0b6f268f19baf6526f7f9d3. --- command.go | 8 ++++++++ command_test.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/command.go b/command.go index b8057e0b..fdac9d27 100644 --- a/command.go +++ b/command.go @@ -218,6 +218,14 @@ func (c *Command) SetArgs(a []string) { c.args = a } +// SetOutput sets the destination for usage and error messages. +// If output is nil, os.Stderr is used. +// Deprecated: Use SetOut and/or SetErr instead +func (c *Command) SetOutput(output io.Writer) { + c.outWriter = output + c.errWriter = output +} + // SetOut sets the destination for usage messages. // If newOut is nil, os.Stdout is used. func (c *Command) SetOut(newOut io.Writer) { diff --git a/command_test.go b/command_test.go index f8c2ae30..ec8e2aef 100644 --- a/command_test.go +++ b/command_test.go @@ -1557,6 +1557,14 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) { EnableCommandSorting = true } +func TestSetOutput(t *testing.T) { + c := &Command{} + c.SetOutput(nil) + if out := c.OutOrStdout(); out != os.Stdout { + t.Errorf("Expected setting output to nil to revert back to stdout") + } +} + func TestSetOut(t *testing.T) { c := &Command{} c.SetOut(nil)