From e7186a11e82b765631f26cbfde1a19f94601f237 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 5 May 2024 09:03:36 +0200 Subject: [PATCH] Modernize code --- application_test.go | 5 ++--- command_test.go | 4 ++-- context_test.go | 2 +- flags_enhancement.go | 4 ++-- help_test.go | 4 ++-- output_flags.go | 4 ++-- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/application_test.go b/application_test.go index 51b0420..53b745f 100644 --- a/application_test.go +++ b/application_test.go @@ -25,7 +25,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "reflect" "strings" @@ -68,7 +67,7 @@ var ( func init() { OsExiter = fakeOsExiter - terminal.Stdout = terminal.NewBufferedConsoleOutput(ioutil.Discard, ioutil.Discard) + terminal.Stdout = terminal.NewBufferedConsoleOutput(io.Discard, io.Discard) terminal.Stderr = terminal.Stdout.Stderr } @@ -765,7 +764,7 @@ func TestAppNoHelpFlag(t *testing.T) { HelpFlag = nil - app := &Application{Writer: ioutil.Discard} + app := &Application{Writer: io.Discard} err := app.Run([]string{"test", "-h"}) if !strings.Contains(err.Error(), flag.ErrHelp.Error()) { diff --git a/command_test.go b/command_test.go index 4225d02..ca25e7e 100644 --- a/command_test.go +++ b/command_test.go @@ -22,7 +22,7 @@ package console import ( "errors" "flag" - "io/ioutil" + "io" "strings" "testing" @@ -113,7 +113,7 @@ func TestCommand_Run_DoesNotOverwriteErrorFromBefore(t *testing.T) { func TestFuzzyCommandNames(t *testing.T) { app := Application{} - app.ErrWriter = ioutil.Discard + app.ErrWriter = io.Discard projectList := &Command{Name: "project:list"} projectLink := &Command{Name: "project:link"} app.Commands = []*Command{ diff --git a/context_test.go b/context_test.go index 4d4f152..a31084b 100644 --- a/context_test.go +++ b/context_test.go @@ -228,7 +228,7 @@ func (cs *ContextSuite) TestContext_Set_AppFlags(c *C) { app := &Application{ Commands: []*Command{ - &Command{ + { Name: "foo", Action: func(ctx *Context) error { err := ctx.Set("log-level", "4") diff --git a/flags_enhancement.go b/flags_enhancement.go index 8330b6b..fe2bca5 100644 --- a/flags_enhancement.go +++ b/flags_enhancement.go @@ -22,7 +22,7 @@ package console import ( "flag" "fmt" - "io/ioutil" + "io" "os" "reflect" "strings" @@ -99,7 +99,7 @@ func (c *Command) fixArgs(args []string) []string { } func parseArgs(arguments []string, fs *flag.FlagSet) (*flag.FlagSet, error) { - fs.SetOutput(ioutil.Discard) + fs.SetOutput(io.Discard) err := errors.WithStack(fs.Parse(arguments)) if err != nil { return fs, err diff --git a/help_test.go b/help_test.go index 7cfd330..8e67c4f 100644 --- a/help_test.go +++ b/help_test.go @@ -22,7 +22,7 @@ package console import ( "bytes" "flag" - "io/ioutil" + "io" "strings" "testing" ) @@ -119,7 +119,7 @@ func Test_Version_Custom_Flags(t *testing.T) { func Test_helpCommand_Action_ErrorIfNoTopic(t *testing.T) { app := &Application{} - app.Writer, app.ErrWriter = ioutil.Discard, ioutil.Discard + app.Writer, app.ErrWriter = io.Discard, io.Discard set := flag.NewFlagSet("test", 0) set.Parse([]string{"foo"}) diff --git a/output_flags.go b/output_flags.go index 607c9a9..6d1c073 100644 --- a/output_flags.go +++ b/output_flags.go @@ -21,7 +21,7 @@ package console import ( "flag" - "io/ioutil" + "io" "os" "strconv" @@ -39,7 +39,7 @@ func (r *quietValue) Set(s string) error { return errors.WithStack(err) } if quiet { - terminal.Stdout = terminal.NewBufferedConsoleOutput(ioutil.Discard, ioutil.Discard) + terminal.Stdout = terminal.NewBufferedConsoleOutput(io.Discard, io.Discard) } else { terminal.Stdout = terminal.DefaultStdout }