diff --git a/altsrc/flag.go b/altsrc/flag.go index 376733a..afb4ad4 100644 --- a/altsrc/flag.go +++ b/altsrc/flag.go @@ -72,7 +72,7 @@ func (f *GenericFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourc } if value != nil { eachName(f.Name, func(name string) { - f.set.Set(f.Name, value.String()) + _ = f.set.Set(f.Name, value.String()) }) } } @@ -135,7 +135,7 @@ func (f *BoolFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCo } if value { eachName(f.Name, func(name string) { - f.set.Set(f.Name, strconv.FormatBool(value)) + _ = f.set.Set(f.Name, strconv.FormatBool(value)) }) } } @@ -153,7 +153,7 @@ func (f *BoolTFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceC } if !value { eachName(f.Name, func(name string) { - f.set.Set(f.Name, strconv.FormatBool(value)) + _ = f.set.Set(f.Name, strconv.FormatBool(value)) }) } } @@ -171,7 +171,7 @@ func (f *StringFlag) ApplyInputSourceValue(context *cli.Context, isc InputSource } if value != "" { eachName(f.Name, func(name string) { - f.set.Set(f.Name, value) + _ = f.set.Set(f.Name, value) }) } } @@ -189,7 +189,7 @@ func (f *IntFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCon } if value > 0 { eachName(f.Name, func(name string) { - f.set.Set(f.Name, strconv.FormatInt(int64(value), 10)) + _ = f.set.Set(f.Name, strconv.FormatInt(int64(value), 10)) }) } } @@ -207,7 +207,7 @@ func (f *DurationFlag) ApplyInputSourceValue(context *cli.Context, isc InputSour } if value > 0 { eachName(f.Name, func(name string) { - f.set.Set(f.Name, value.String()) + _ = f.set.Set(f.Name, value.String()) }) } } @@ -226,7 +226,7 @@ func (f *Float64Flag) ApplyInputSourceValue(context *cli.Context, isc InputSourc if value > 0 { floatStr := float64ToString(value) eachName(f.Name, func(name string) { - f.set.Set(f.Name, floatStr) + _ = f.set.Set(f.Name, floatStr) }) } } diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index 5f293bb..90a96d3 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -239,30 +239,30 @@ func TestDurationApplyInputSourceMethodSet(t *testing.T) { c := runTest(t, testApplyInputSource{ Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}), FlagName: "test", - MapValue: time.Duration(30 * time.Second), + MapValue: 30 * time.Second, }) - expect(t, time.Duration(30*time.Second), c.Duration("test")) + expect(t, 30*time.Second, c.Duration("test")) } func TestDurationApplyInputSourceMethodContextSet(t *testing.T) { c := runTest(t, testApplyInputSource{ Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}), FlagName: "test", - MapValue: time.Duration(30 * time.Second), - ContextValueString: time.Duration(15 * time.Second).String(), + MapValue: 30 * time.Second, + ContextValueString: (15 * time.Second).String(), }) - expect(t, time.Duration(15*time.Second), c.Duration("test")) + expect(t, 15*time.Second, c.Duration("test")) } func TestDurationApplyInputSourceMethodEnvVarSet(t *testing.T) { c := runTest(t, testApplyInputSource{ Flag: NewDurationFlag(cli.DurationFlag{Name: "test", EnvVar: "TEST"}), FlagName: "test", - MapValue: time.Duration(30 * time.Second), + MapValue: 30 * time.Second, EnvVarName: "TEST", - EnvVarValue: time.Duration(15 * time.Second).String(), + EnvVarValue: (15 * time.Second).String(), }) - expect(t, time.Duration(15*time.Second), c.Duration("test")) + expect(t, 15*time.Second, c.Duration("test")) } func TestFloat64ApplyInputSourceMethodSet(t *testing.T) { @@ -300,19 +300,19 @@ func runTest(t *testing.T, test testApplyInputSource) *cli.Context { set := flag.NewFlagSet(test.FlagSetName, flag.ContinueOnError) c := cli.NewContext(nil, set, nil) if test.EnvVarName != "" && test.EnvVarValue != "" { - os.Setenv(test.EnvVarName, test.EnvVarValue) + _ = os.Setenv(test.EnvVarName, test.EnvVarValue) defer os.Setenv(test.EnvVarName, "") } test.Flag.Apply(set) if test.ContextValue != nil { - flag := set.Lookup(test.FlagName) - flag.Value = test.ContextValue + f := set.Lookup(test.FlagName) + f.Value = test.ContextValue } if test.ContextValueString != "" { - set.Set(test.FlagName, test.ContextValueString) + _ = set.Set(test.FlagName, test.ContextValueString) } - test.Flag.ApplyInputSourceValue(c, inputSource) + _ = test.Flag.ApplyInputSourceValue(c, inputSource) return c } diff --git a/altsrc/json_command_test.go b/altsrc/json_command_test.go index f24cae6..63c19b2 100644 --- a/altsrc/json_command_test.go +++ b/altsrc/json_command_test.go @@ -22,7 +22,7 @@ func TestCommandJSONFileTest(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -52,11 +52,11 @@ func TestCommandJSONFileTestGlobalEnvVarWins(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) - os.Setenv("THE_TEST", "10") + _ = os.Setenv("THE_TEST", "10") defer os.Setenv("THE_TEST", "") test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -87,11 +87,11 @@ func TestCommandJSONFileTestGlobalEnvVarWinsNested(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) - os.Setenv("THE_TEST", "10") + _ = os.Setenv("THE_TEST", "10") defer os.Setenv("THE_TEST", "") test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -123,7 +123,7 @@ func TestCommandJSONFileTestSpecifiedFlagWins(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) test := []string{"test-cmd", "--load", fileName, "--test", "7"} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -155,7 +155,7 @@ func TestCommandJSONFileTestSpecifiedFlagWinsNested(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) test := []string{"test-cmd", "--load", fileName, "--top.test", "7"} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -187,7 +187,7 @@ func TestCommandJSONFileTestDefaultValueFileWins(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -219,7 +219,7 @@ func TestCommandJSONFileTestDefaultValueFileWinsNested(t *testing.T) { app := cli.NewApp() set := flag.NewFlagSet("test", 0) test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -250,11 +250,11 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWins(t *testing.T app := cli.NewApp() set := flag.NewFlagSet("test", 0) - os.Setenv("THE_TEST", "11") + _ = os.Setenv("THE_TEST", "11") defer os.Setenv("THE_TEST", "") test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) @@ -284,11 +284,11 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWinsNested(t *tes app := cli.NewApp() set := flag.NewFlagSet("test", 0) - os.Setenv("THE_TEST", "11") + _ = os.Setenv("THE_TEST", "11") defer os.Setenv("THE_TEST", "") test := []string{"test-cmd", "--load", fileName} - set.Parse(test) + _ = set.Parse(test) c := cli.NewContext(app, set, nil) diff --git a/app.go b/app.go index 93c123d..76e869d 100644 --- a/app.go +++ b/app.go @@ -11,9 +11,10 @@ import ( ) var ( - changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" - appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) - runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) + changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" + appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) + // unused variable. commented for now. will remove in future if agreed upon by everyone + //runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." @@ -142,7 +143,7 @@ func (a *App) Setup() { a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email}) } - newCmds := []Command{} + var newCmds []Command for _, c := range a.Commands { if c.HelpName == "" { c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) @@ -207,8 +208,8 @@ func (a *App) Run(arguments []string) (err error) { nerr := normalizeFlags(a.Flags, set) context := NewContext(a, set, nil) if nerr != nil { - fmt.Fprintln(a.Writer, nerr) - ShowAppHelp(context) + _, _ = fmt.Fprintln(a.Writer, nerr) + _ = ShowAppHelp(context) return nerr } context.shellComplete = shellComplete @@ -223,13 +224,13 @@ func (a *App) Run(arguments []string) (err error) { a.handleExitCoder(context, err) return err } - fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) - ShowAppHelp(context) + _, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) + _ = ShowAppHelp(context) return err } if !a.HideHelp && checkHelp(context) { - ShowAppHelp(context) + _ = ShowAppHelp(context) return nil } @@ -240,7 +241,7 @@ func (a *App) Run(arguments []string) (err error) { cerr := checkRequiredFlags(a.Flags, context) if cerr != nil { - ShowAppHelp(context) + _ = ShowAppHelp(context) return cerr } @@ -259,8 +260,8 @@ func (a *App) Run(arguments []string) (err error) { if a.Before != nil { beforeErr := a.Before(context) if beforeErr != nil { - fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) - ShowAppHelp(context) + _, _ = fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) + _ = ShowAppHelp(context) a.handleExitCoder(context, beforeErr) err = beforeErr return err @@ -294,7 +295,7 @@ func (a *App) Run(arguments []string) (err error) { // code in the cli.ExitCoder func (a *App) RunAndExitOnError() { if err := a.Run(os.Args); err != nil { - fmt.Fprintln(a.errWriter(), err) + _, _ = fmt.Fprintln(a.errWriter(), err) OsExiter(1) } } @@ -331,12 +332,12 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { context := NewContext(a, set, ctx) if nerr != nil { - fmt.Fprintln(a.Writer, nerr) - fmt.Fprintln(a.Writer) + _, _ = fmt.Fprintln(a.Writer, nerr) + _, _ = fmt.Fprintln(a.Writer) if len(a.Commands) > 0 { - ShowSubcommandHelp(context) + _ = ShowSubcommandHelp(context) } else { - ShowCommandHelp(ctx, context.Args().First()) + _ = ShowCommandHelp(ctx, context.Args().First()) } return nerr } @@ -351,8 +352,8 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { a.handleExitCoder(context, err) return err } - fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) - ShowSubcommandHelp(context) + _, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) + _ = ShowSubcommandHelp(context) return err } @@ -368,7 +369,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { cerr := checkRequiredFlags(a.Flags, context) if cerr != nil { - ShowSubcommandHelp(context) + _ = ShowSubcommandHelp(context) return cerr } @@ -448,7 +449,7 @@ func (a *App) VisibleCategories() []*CommandCategory { // VisibleCommands returns a slice of the Commands with Hidden=false func (a *App) VisibleCommands() []Command { - ret := []Command{} + var ret []Command for _, command := range a.Commands { if !command.Hidden { ret = append(ret, command) diff --git a/app_test.go b/app_test.go index 48adf5e..1295467 100644 --- a/app_test.go +++ b/app_test.go @@ -47,7 +47,7 @@ func ExampleApp_Run() { app.Author = "Harrison" app.Email = "harrison@lolwut.com" app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}} - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // Hello Jeremy } @@ -85,7 +85,7 @@ func ExampleApp_Run_subcommand() { }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // Hello, Jeremy } @@ -117,7 +117,7 @@ func ExampleApp_Run_appHelp() { }, }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // NAME: // greet - A new cli application @@ -166,7 +166,7 @@ func ExampleApp_Run_commandHelp() { }, }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // NAME: // greet describeit - use it to see a description @@ -181,7 +181,7 @@ func ExampleApp_Run_commandHelp() { func ExampleApp_Run_noAction() { app := App{} app.Name = "greet" - app.Run([]string{"greet"}) + _ = app.Run([]string{"greet"}) // Output: // NAME: // greet @@ -208,7 +208,7 @@ func ExampleApp_Run_subcommandNoAction() { Description: "This is how we describe describeit the function", }, } - app.Run([]string{"greet", "describeit"}) + _ = app.Run([]string{"greet", "describeit"}) // Output: // NAME: // describeit - use it to see a description @@ -236,7 +236,7 @@ func ExampleApp_Run_bashComplete_withShortFlag() { }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // --other // -o @@ -269,7 +269,7 @@ func ExampleApp_Run_bashComplete_withLongFlag() { }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // --some-flag // --similar-flag @@ -298,7 +298,7 @@ func ExampleApp_Run_bashComplete_withMultipleLongFlag() { }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // --string // --string-flag-2 @@ -332,7 +332,7 @@ func ExampleApp_Run_bashComplete() { }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // describeit // d @@ -344,7 +344,7 @@ func ExampleApp_Run_bashComplete() { func ExampleApp_Run_zshComplete() { // set args for examples sake os.Args = []string{"greet", "--generate-bash-completion"} - os.Setenv("_CLI_ZSH_AUTOCOMPLETE_HACK", "1") + _ = os.Setenv("_CLI_ZSH_AUTOCOMPLETE_HACK", "1") app := NewApp() app.Name = "greet" @@ -370,7 +370,7 @@ func ExampleApp_Run_zshComplete() { }, } - app.Run(os.Args) + _ = app.Run(os.Args) // Output: // describeit:use it to see a description // d:use it to see a description @@ -444,7 +444,7 @@ func TestApp_CommandWithArgBeforeFlags(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"}) + _ = app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"}) expect(t, parsedOption, "my-option") expect(t, firstArg, "my-arg") @@ -474,7 +474,7 @@ func TestApp_CommandWithArgBeforeBoolFlags(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "--boolflag", "--option", "my-option", "-b", "--secondOption", "fancy-option"}) + _ = app.Run([]string{"", "cmd", "my-arg", "--boolflag", "--option", "my-option", "-b", "--secondOption", "fancy-option"}) expect(t, parsedOption, "my-option") expect(t, parsedSecondOption, "fancy-option") @@ -504,7 +504,7 @@ func TestApp_RunAsSubcommandParseFlags(t *testing.T) { Before: func(_ *Context) error { return nil }, }, } - a.Run([]string{"", "foo", "--lang", "spanish", "abcd"}) + _ = a.Run([]string{"", "foo", "--lang", "spanish", "abcd"}) expect(t, context.Args().Get(0), "abcd") expect(t, context.String("lang"), "spanish") @@ -519,7 +519,7 @@ func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { } set := flag.NewFlagSet("", flag.ContinueOnError) - set.Parse([]string{"", "---foo"}) + _ = set.Parse([]string{"", "---foo"}) c := &Context{flagSet: set} err := a.RunAsSubcommand(c) @@ -545,7 +545,7 @@ func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "--option", "my-option", "--", "--notARealFlag"}) + _ = app.Run([]string{"", "cmd", "my-arg", "--option", "my-option", "--", "--notARealFlag"}) expect(t, parsedOption, "my-option") expect(t, args[0], "my-arg") @@ -566,7 +566,7 @@ func TestApp_CommandWithDash(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "-"}) + _ = app.Run([]string{"", "cmd", "my-arg", "-"}) expect(t, args[0], "my-arg") expect(t, args[1], "-") @@ -585,7 +585,7 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "--", "notAFlagAtAll"}) + _ = app.Run([]string{"", "cmd", "my-arg", "--", "notAFlagAtAll"}) expect(t, args[0], "my-arg") expect(t, args[1], "--") @@ -734,7 +734,7 @@ func TestApp_Float64Flag(t *testing.T) { return nil } - app.Run([]string{"", "--height", "1.93"}) + _ = app.Run([]string{"", "--height", "1.93"}) expect(t, meters, 1.93) } @@ -757,7 +757,7 @@ func TestApp_ParseSliceFlags(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"}) + _ = app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"}) IntsEquals := func(a, b []int) bool { if len(a) != len(b) { @@ -813,7 +813,7 @@ func TestApp_ParseSliceFlagsWithMissingValue(t *testing.T) { } app.Commands = []Command{command} - app.Run([]string{"", "cmd", "my-arg", "-a", "2", "-str", "A"}) + _ = app.Run([]string{"", "cmd", "my-arg", "-a", "2", "-str", "A"}) var expectedIntSlice = []int{2} var expectedStringSlice = []string{"A"} @@ -1199,7 +1199,7 @@ func TestAppHelpPrinter(t *testing.T) { } app := NewApp() - app.Run([]string{"-h"}) + _ = app.Run([]string{"-h"}) if wasCalled == false { t.Errorf("Help printer expected to be called, but was not") @@ -1246,7 +1246,7 @@ func TestApp_CommandNotFound(t *testing.T) { }, } - app.Run([]string{"command", "foo"}) + _ = app.Run([]string{"command", "foo"}) expect(t, counts.CommandNotFound, 1) expect(t, counts.SubCommand, 0) @@ -1656,7 +1656,7 @@ func TestApp_Run_Categories(t *testing.T) { buf := new(bytes.Buffer) app.Writer = buf - app.Run([]string{"categories"}) + _ = app.Run([]string{"categories"}) expect := CommandCategories{ &CommandCategory{ @@ -2075,7 +2075,7 @@ func TestHandleExitCoder_Custom(t *testing.T) { } app.ExitErrHandler = func(_ *Context, _ error) { - fmt.Fprintln(ErrWriter, "I'm a Custom error handler, I print what I want!") + _, _ = fmt.Fprintln(ErrWriter, "I'm a Custom error handler, I print what I want!") } ctx := NewContext(app, fs, nil) @@ -2094,14 +2094,14 @@ func TestHandleAction_WithUnknownPanic(t *testing.T) { app := NewApp() app.Action = func(ctx *Context) error { - fn(ctx) + _ = fn(ctx) return nil } fs, err := flagSet(app.Name, app.Flags) if err != nil { t.Errorf("error creating FlagSet: %s", err) } - HandleAction(app.Action, NewContext(app, fs, nil)) + _ = HandleAction(app.Action, NewContext(app, fs, nil)) } func TestShellCompletionForIncompleteFlags(t *testing.T) { @@ -2119,12 +2119,12 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) { } for _, name := range command.Names() { - fmt.Fprintln(ctx.App.Writer, name) + _, _ = fmt.Fprintln(ctx.App.Writer, name) } } - for _, flag := range ctx.App.Flags { - for _, name := range strings.Split(flag.GetName(), ",") { + for _, f := range ctx.App.Flags { + for _, name := range strings.Split(f.GetName(), ",") { if name == BashCompletionFlag.GetName() { continue } @@ -2132,9 +2132,9 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) { switch name = strings.TrimSpace(name); len(name) { case 0: case 1: - fmt.Fprintln(ctx.App.Writer, "-"+name) + _, _ = fmt.Fprintln(ctx.App.Writer, "-"+name) default: - fmt.Fprintln(ctx.App.Writer, "--"+name) + _, _ = fmt.Fprintln(ctx.App.Writer, "--"+name) } } } diff --git a/command.go b/command.go index c74baeb..f55043f 100644 --- a/command.go +++ b/command.go @@ -128,9 +128,9 @@ func (c Command) Run(ctx *Context) (err error) { context.App.handleExitCoder(context, err) return err } - fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) - fmt.Fprintln(context.App.Writer) - ShowCommandHelp(context, c.Name) + _, _ = fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) + _, _ = fmt.Fprintln(context.App.Writer) + _ = ShowCommandHelp(context, c.Name) return err } @@ -140,7 +140,7 @@ func (c Command) Run(ctx *Context) (err error) { cerr := checkRequiredFlags(c.Flags, context) if cerr != nil { - ShowCommandHelp(context, c.Name) + _ = ShowCommandHelp(context, c.Name) return cerr } @@ -161,7 +161,7 @@ func (c Command) Run(ctx *Context) (err error) { if c.Before != nil { err = c.Before(context) if err != nil { - ShowCommandHelp(context, c.Name) + _ = ShowCommandHelp(context, c.Name) context.App.handleExitCoder(context, err) return err } diff --git a/command_test.go b/command_test.go index 8c2650e..56698fe 100644 --- a/command_test.go +++ b/command_test.go @@ -35,7 +35,7 @@ func TestCommandFlagParsing(t *testing.T) { app := NewApp() app.Writer = ioutil.Discard set := flag.NewFlagSet("test", 0) - set.Parse(c.testArgs) + _ = set.Parse(c.testArgs) context := NewContext(app, set, nil) @@ -59,9 +59,9 @@ func TestCommandFlagParsing(t *testing.T) { func TestParseAndRunShortOpts(t *testing.T) { cases := []struct { - testArgs []string - expectedErr error - expectedArgs []string + testArgs []string + expectedErr error + expectedArgs []string }{ {[]string{"foo", "test", "-a"}, nil, []string{}}, {[]string{"foo", "test", "-c", "arg1", "arg2"}, nil, []string{"arg1", "arg2"}}, @@ -71,18 +71,18 @@ func TestParseAndRunShortOpts(t *testing.T) { {[]string{"foo", "test", "-cf"}, nil, []string{}}, {[]string{"foo", "test", "-acf"}, nil, []string{}}, {[]string{"foo", "test", "-invalid"}, errors.New("flag provided but not defined: -invalid"), []string{}}, - {[]string{"foo", "test", "-acf", "arg1", "-invalid"}, nil, []string{"arg1" ,"-invalid"}}, + {[]string{"foo", "test", "-acf", "arg1", "-invalid"}, nil, []string{"arg1", "-invalid"}}, } var args []string cmd := Command{ - Name: "test", - Usage: "this is for testing", - Description: "testing", - Action: func(c *Context) error { - args = c.Args() - return nil - }, + Name: "test", + Usage: "this is for testing", + Description: "testing", + Action: func(c *Context) error { + args = c.Args() + return nil + }, SkipArgReorder: true, UseShortOptionHandling: true, Flags: []Flag{ @@ -304,7 +304,7 @@ func TestCommandFlagReordering(t *testing.T) { for _, c := range cases { value := "" - args := []string{} + var args []string app := &App{ Commands: []Command{ { @@ -339,7 +339,7 @@ func TestCommandSkipFlagParsing(t *testing.T) { } for _, c := range cases { - args := []string{} + var args []string app := &App{ Commands: []Command{ { diff --git a/context.go b/context.go index 3e516c8..db7cd69 100644 --- a/context.go +++ b/context.go @@ -139,8 +139,8 @@ func (c *Context) GlobalIsSet(name string) bool { // FlagNames returns a slice of flag names used in this context. func (c *Context) FlagNames() (names []string) { - for _, flag := range c.Command.Flags { - name := strings.Split(flag.GetName(), ",")[0] + for _, f := range c.Command.Flags { + name := strings.Split(f.GetName(), ",")[0] if name == "help" { continue } @@ -151,8 +151,8 @@ func (c *Context) FlagNames() (names []string) { // GlobalFlagNames returns a slice of global flag names used by the app. func (c *Context) GlobalFlagNames() (names []string) { - for _, flag := range c.App.Flags { - name := strings.Split(flag.GetName(), ",")[0] + for _, f := range c.App.Flags { + name := strings.Split(f.GetName(), ",")[0] if name == "help" || name == "version" { continue } @@ -250,7 +250,7 @@ func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { switch ff.Value.(type) { case *StringSlice: default: - set.Set(name, ff.Value.String()) + _ = set.Set(name, ff.Value.String()) } } diff --git a/context_test.go b/context_test.go index f329dc7..9e594dd 100644 --- a/context_test.go +++ b/context_test.go @@ -99,9 +99,9 @@ func TestContext_GlobalFloat64(t *testing.T) { func TestContext_Duration(t *testing.T) { set := flag.NewFlagSet("test", 0) - set.Duration("myflag", time.Duration(12*time.Second), "doc") + set.Duration("myflag", 12*time.Second, "doc") c := NewContext(nil, set, nil) - expect(t, c.Duration("myflag"), time.Duration(12*time.Second)) + expect(t, c.Duration("myflag"), 12*time.Second) } func TestContext_String(t *testing.T) { @@ -153,7 +153,7 @@ func TestContext_Args(t *testing.T) { set := flag.NewFlagSet("test", 0) set.Bool("myflag", false, "doc") c := NewContext(nil, set, nil) - set.Parse([]string{"--myflag", "bat", "baz"}) + _ = set.Parse([]string{"--myflag", "bat", "baz"}) expect(t, len(c.Args()), 2) expect(t, c.Bool("myflag"), true) } @@ -162,7 +162,7 @@ func TestContext_NArg(t *testing.T) { set := flag.NewFlagSet("test", 0) set.Bool("myflag", false, "doc") c := NewContext(nil, set, nil) - set.Parse([]string{"--myflag", "bat", "baz"}) + _ = set.Parse([]string{"--myflag", "bat", "baz"}) expect(t, c.NArg(), 2) } @@ -174,8 +174,8 @@ func TestContext_IsSet(t *testing.T) { globalSet.Bool("myflagGlobal", true, "doc") globalCtx := NewContext(nil, globalSet, nil) c := NewContext(nil, set, globalCtx) - set.Parse([]string{"--myflag", "bat", "baz"}) - globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"}) + _ = set.Parse([]string{"--myflag", "bat", "baz"}) + _ = globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"}) expect(t, c.IsSet("myflag"), true) expect(t, c.IsSet("otherflag"), false) expect(t, c.IsSet("bogusflag"), false) @@ -193,8 +193,8 @@ func TestContext_IsSet_fromEnv(t *testing.T) { ) clearenv() - os.Setenv("APP_TIMEOUT_SECONDS", "15.5") - os.Setenv("APP_PASSWORD", "") + _ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5") + _ = os.Setenv("APP_PASSWORD", "") a := App{ Flags: []Flag{ Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"}, @@ -214,7 +214,7 @@ func TestContext_IsSet_fromEnv(t *testing.T) { return nil }, } - a.Run([]string{"run"}) + _ = a.Run([]string{"run"}) expect(t, timeoutIsSet, true) expect(t, tIsSet, true) expect(t, passwordIsSet, true) @@ -222,8 +222,8 @@ func TestContext_IsSet_fromEnv(t *testing.T) { expect(t, noEnvVarIsSet, false) expect(t, nIsSet, false) - os.Setenv("APP_UNPARSABLE", "foobar") - a.Run([]string{"run"}) + _ = os.Setenv("APP_UNPARSABLE", "foobar") + _ = a.Run([]string{"run"}) expect(t, unparsableIsSet, false) expect(t, uIsSet, false) } @@ -237,8 +237,8 @@ func TestContext_GlobalIsSet(t *testing.T) { globalSet.Bool("myflagGlobalUnset", true, "doc") globalCtx := NewContext(nil, globalSet, nil) c := NewContext(nil, set, globalCtx) - set.Parse([]string{"--myflag", "bat", "baz"}) - globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"}) + _ = set.Parse([]string{"--myflag", "bat", "baz"}) + _ = globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"}) expect(t, c.GlobalIsSet("myflag"), false) expect(t, c.GlobalIsSet("otherflag"), false) expect(t, c.GlobalIsSet("bogusflag"), false) @@ -261,9 +261,9 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) { ) clearenv() - os.Setenv("APP_TIMEOUT_SECONDS", "15.5") - os.Setenv("APP_PASSWORD", "badpass") - os.Setenv("APP_OVERRIDE", "overridden") + _ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5") + _ = os.Setenv("APP_PASSWORD", "badpass") + _ = os.Setenv("APP_OVERRIDE", "overridden") a := App{ Flags: []Flag{ Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"}, @@ -308,7 +308,7 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) { expect(t, oIsSet, true) expect(t, overrideValue, "overridden") - os.Setenv("APP_UNPARSABLE", "foobar") + _ = os.Setenv("APP_UNPARSABLE", "foobar") if err := a.Run([]string{"run"}); err != nil { t.Logf("error running Run(): %+v", err) } @@ -324,8 +324,8 @@ func TestContext_NumFlags(t *testing.T) { globalSet.Bool("myflagGlobal", true, "doc") globalCtx := NewContext(nil, globalSet, nil) c := NewContext(nil, set, globalCtx) - set.Parse([]string{"--myflag", "--otherflag=foo"}) - globalSet.Parse([]string{"--myflagGlobal"}) + _ = set.Parse([]string{"--myflag", "--otherflag=foo"}) + _ = globalSet.Parse([]string{"--myflagGlobal"}) expect(t, c.NumFlags(), 2) } @@ -341,7 +341,7 @@ func TestContext_GlobalFlag(t *testing.T) { globalFlagSet = c.GlobalIsSet("global") return nil } - app.Run([]string{"command", "-g", "foo"}) + _ = app.Run([]string{"command", "-g", "foo"}) expect(t, globalFlag, "foo") expect(t, globalFlagSet, true) @@ -379,7 +379,7 @@ func TestContext_GlobalFlagsInSubcommands(t *testing.T) { }, } - app.Run([]string{"command", "-d", "foo", "-p", "bar"}) + _ = app.Run([]string{"command", "-d", "foo", "-p", "bar"}) expect(t, subcommandRun, true) expect(t, parentFlag, true) @@ -391,7 +391,7 @@ func TestContext_Set(t *testing.T) { c := NewContext(nil, set, nil) expect(t, c.IsSet("int"), false) - c.Set("int", "1") + _ = c.Set("int", "1") expect(t, c.Int("int"), 1) expect(t, c.IsSet("int"), true) } @@ -406,12 +406,12 @@ func TestContext_GlobalSet(t *testing.T) { pc := NewContext(nil, gSet, nil) c := NewContext(nil, set, pc) - c.Set("int", "1") + _ = c.Set("int", "1") expect(t, c.Int("int"), 1) expect(t, c.GlobalInt("int"), 5) expect(t, c.GlobalIsSet("int"), false) - c.GlobalSet("int", "1") + _ = c.GlobalSet("int", "1") expect(t, c.Int("int"), 1) expect(t, c.GlobalInt("int"), 1) expect(t, c.GlobalIsSet("int"), true) @@ -525,10 +525,10 @@ func TestCheckRequiredFlags(t *testing.T) { for _, flags := range test.flags { flags.Apply(set) } - set.Parse(test.parseInput) + _ = set.Parse(test.parseInput) if test.envVarInput[0] != "" { os.Clearenv() - os.Setenv(test.envVarInput[0], test.envVarInput[1]) + _ = os.Setenv(test.envVarInput[0], test.envVarInput[1]) } ctx := &Context{} context := NewContext(ctx.App, set, ctx) diff --git a/flag.go b/flag.go index 04f463a..be55a33 100644 --- a/flag.go +++ b/flag.go @@ -142,7 +142,7 @@ type Generic interface { // provided by the user for parsing by the flag // Ignores parsing errors func (f GenericFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError takes the flagset and calls Set on the generic flag with the value @@ -189,7 +189,7 @@ func (f *StringSlice) Get() interface{} { // Apply populates the flag given the flag set and environment // Ignores errors func (f StringSliceFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -250,7 +250,7 @@ func (f *IntSlice) Get() interface{} { // Apply populates the flag given the flag set and environment // Ignores errors func (f IntSliceFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -311,7 +311,7 @@ func (f *Int64Slice) Get() interface{} { // Apply populates the flag given the flag set and environment // Ignores errors func (f Int64SliceFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -343,7 +343,7 @@ func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f BoolFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -375,7 +375,7 @@ func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f BoolTFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -408,7 +408,7 @@ func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f StringFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -431,7 +431,7 @@ func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f IntFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -458,7 +458,7 @@ func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f Int64Flag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -486,7 +486,7 @@ func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f UintFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -514,7 +514,7 @@ func (f UintFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f Uint64Flag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -525,7 +525,7 @@ func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err) } - f.Value = uint64(envValInt) + f.Value = envValInt } eachName(f.Name, func(name string) { @@ -542,7 +542,7 @@ func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f DurationFlag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -570,7 +570,7 @@ func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { // Apply populates the flag given the flag set and environment // Ignores errors func (f Float64Flag) Apply(set *flag.FlagSet) { - f.ApplyWithError(set) + _ = f.ApplyWithError(set) } // ApplyWithError populates the flag given the flag set and environment @@ -581,7 +581,7 @@ func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err) } - f.Value = float64(envValFloat) + f.Value = envValFloat } eachName(f.Name, func(name string) { @@ -596,11 +596,11 @@ func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { } func visibleFlags(fl []Flag) []Flag { - visible := []Flag{} - for _, flag := range fl { - field := flagValue(flag).FieldByName("Hidden") + var visible []Flag + for _, f := range fl { + field := flagValue(f).FieldByName("Hidden") if !field.IsValid() || !field.Bool() { - visible = append(visible, flag) + visible = append(visible, f) } } return visible @@ -745,7 +745,7 @@ func stringifyFlag(f Flag) string { } func stringifyIntSliceFlag(f IntSliceFlag) string { - defaultVals := []string{} + var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, i := range f.Value.Value() { defaultVals = append(defaultVals, strconv.Itoa(i)) @@ -756,7 +756,7 @@ func stringifyIntSliceFlag(f IntSliceFlag) string { } func stringifyInt64SliceFlag(f Int64SliceFlag) string { - defaultVals := []string{} + var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, i := range f.Value.Value() { defaultVals = append(defaultVals, strconv.FormatInt(i, 10)) @@ -767,7 +767,7 @@ func stringifyInt64SliceFlag(f Int64SliceFlag) string { } func stringifyStringSliceFlag(f StringSliceFlag) string { - defaultVals := []string{} + var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, s := range f.Value.Value() { if len(s) > 0 { diff --git a/flag_test.go b/flag_test.go index da9fd73..f4a24c2 100644 --- a/flag_test.go +++ b/flag_test.go @@ -89,7 +89,7 @@ func TestFlagsFromEnv(t *testing.T) { for _, test := range flagTests { os.Clearenv() - os.Setenv(reflect.ValueOf(test.flag).FieldByName("EnvVar").String(), test.input) + _ = os.Setenv(reflect.ValueOf(test.flag).FieldByName("EnvVar").String(), test.input) a := App{ Flags: []Flag{test.flag}, Action: func(ctx *Context) error { @@ -145,7 +145,7 @@ func TestStringFlagHelpOutput(t *testing.T) { func TestStringFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_FOO", "derp") + _ = os.Setenv("APP_FOO", "derp") for _, test := range stringFlagTests { flag := StringFlag{Name: test.name, Value: test.value, EnvVar: "APP_FOO"} output := flag.String() @@ -244,22 +244,22 @@ var stringSliceFlagTests = []struct { }{ {"foo", func() *StringSlice { s := &StringSlice{} - s.Set("") + _ = s.Set("") return s }(), "--foo value\t"}, {"f", func() *StringSlice { s := &StringSlice{} - s.Set("") + _ = s.Set("") return s }(), "-f value\t"}, {"f", func() *StringSlice { s := &StringSlice{} - s.Set("Lipstick") + _ = s.Set("Lipstick") return s }(), "-f value\t(default: \"Lipstick\")"}, {"test", func() *StringSlice { s := &StringSlice{} - s.Set("Something") + _ = s.Set("Something") return s }(), "--test value\t(default: \"Something\")"}, } @@ -277,7 +277,7 @@ func TestStringSliceFlagHelpOutput(t *testing.T) { func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_QWWX", "11,4") + _ = os.Setenv("APP_QWWX", "11,4") for _, test := range stringSliceFlagTests { flag := StringSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_QWWX"} output := flag.String() @@ -313,7 +313,7 @@ func TestIntFlagHelpOutput(t *testing.T) { func TestIntFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_BAR", "2") + _ = os.Setenv("APP_BAR", "2") for _, test := range intFlagTests { flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"} output := flag.String() @@ -349,7 +349,7 @@ func TestInt64FlagHelpOutput(t *testing.T) { func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_BAR", "2") + _ = os.Setenv("APP_BAR", "2") for _, test := range int64FlagTests { flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"} output := flag.String() @@ -385,7 +385,7 @@ func TestUintFlagHelpOutput(t *testing.T) { func TestUintFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_BAR", "2") + _ = os.Setenv("APP_BAR", "2") for _, test := range uintFlagTests { flag := UintFlag{Name: test.name, EnvVar: "APP_BAR"} output := flag.String() @@ -421,7 +421,7 @@ func TestUint64FlagHelpOutput(t *testing.T) { func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_BAR", "2") + _ = os.Setenv("APP_BAR", "2") for _, test := range uint64FlagTests { flag := UintFlag{Name: test.name, EnvVar: "APP_BAR"} output := flag.String() @@ -457,7 +457,7 @@ func TestDurationFlagHelpOutput(t *testing.T) { func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_BAR", "2h3m6s") + _ = os.Setenv("APP_BAR", "2h3m6s") for _, test := range durationFlagTests { flag := DurationFlag{Name: test.name, EnvVar: "APP_BAR"} output := flag.String() @@ -481,8 +481,8 @@ var intSliceFlagTests = []struct { {"H", &IntSlice{}, "-H value\t"}, {"H, heads", func() *IntSlice { i := &IntSlice{} - i.Set("9") - i.Set("3") + _ = i.Set("9") + _ = i.Set("3") return i }(), "-H value, --heads value\t(default: 9, 3)"}, } @@ -500,7 +500,7 @@ func TestIntSliceFlagHelpOutput(t *testing.T) { func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_SMURF", "42,3") + _ = os.Setenv("APP_SMURF", "42,3") for _, test := range intSliceFlagTests { flag := IntSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"} output := flag.String() @@ -524,8 +524,8 @@ var int64SliceFlagTests = []struct { {"H", &Int64Slice{}, "-H value\t"}, {"H, heads", func() *Int64Slice { i := &Int64Slice{} - i.Set("2") - i.Set("17179869184") + _ = i.Set("2") + _ = i.Set("17179869184") return i }(), "-H value, --heads value\t(default: 2, 17179869184)"}, } @@ -543,7 +543,7 @@ func TestInt64SliceFlagHelpOutput(t *testing.T) { func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_SMURF", "42,17179869184") + _ = os.Setenv("APP_SMURF", "42,17179869184") for _, test := range int64SliceFlagTests { flag := Int64SliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"} output := flag.String() @@ -568,7 +568,7 @@ var float64FlagTests = []struct { func TestFloat64FlagHelpOutput(t *testing.T) { for _, test := range float64FlagTests { - flag := Float64Flag{Name: test.name, Value: float64(0.1)} + flag := Float64Flag{Name: test.name, Value: 0.1} output := flag.String() if output != test.expected { @@ -579,7 +579,7 @@ func TestFloat64FlagHelpOutput(t *testing.T) { func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_BAZ", "99.4") + _ = os.Setenv("APP_BAZ", "99.4") for _, test := range float64FlagTests { flag := Float64Flag{Name: test.name, EnvVar: "APP_BAZ"} output := flag.String() @@ -616,7 +616,7 @@ func TestGenericFlagHelpOutput(t *testing.T) { func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) { os.Clearenv() - os.Setenv("APP_ZAP", "3") + _ = os.Setenv("APP_ZAP", "3") for _, test := range genericFlagTests { flag := GenericFlag{Name: test.name, EnvVar: "APP_ZAP"} output := flag.String() @@ -632,7 +632,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) { } func TestParseMultiString(t *testing.T) { - (&App{ + _ = (&App{ Flags: []Flag{ StringFlag{Name: "serve, s"}, }, @@ -650,7 +650,7 @@ func TestParseMultiString(t *testing.T) { func TestParseDestinationString(t *testing.T) { var dest string - a := App{ + _ = (&App{ Flags: []Flag{ StringFlag{ Name: "dest", @@ -663,14 +663,13 @@ func TestParseDestinationString(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--dest", "10"}) + }).Run([]string{"run", "--dest", "10"}) } func TestParseMultiStringFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_COUNT", "20") - (&App{ + _ = os.Setenv("APP_COUNT", "20") + _ = (&App{ Flags: []Flag{ StringFlag{Name: "count, c", EnvVar: "APP_COUNT"}, }, @@ -688,8 +687,8 @@ func TestParseMultiStringFromEnv(t *testing.T) { func TestParseMultiStringFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_COUNT", "20") - (&App{ + _ = os.Setenv("APP_COUNT", "20") + _ = (&App{ Flags: []Flag{ StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"}, }, @@ -706,7 +705,7 @@ func TestParseMultiStringFromEnvCascade(t *testing.T) { } func TestParseMultiStringSlice(t *testing.T) { - (&App{ + _ = (&App{ Flags: []Flag{ StringSliceFlag{Name: "serve, s", Value: &StringSlice{}}, }, @@ -724,9 +723,9 @@ func TestParseMultiStringSlice(t *testing.T) { func TestParseMultiStringSliceFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_INTERVALS", "20,30,40") + _ = os.Setenv("APP_INTERVALS", "20,30,40") - (&App{ + _ = (&App{ Flags: []Flag{ StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "APP_INTERVALS"}, }, @@ -744,9 +743,9 @@ func TestParseMultiStringSliceFromEnv(t *testing.T) { func TestParseMultiStringSliceFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_INTERVALS", "20,30,40") + _ = os.Setenv("APP_INTERVALS", "20,30,40") - (&App{ + _ = (&App{ Flags: []Flag{ StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"}, }, @@ -763,7 +762,7 @@ func TestParseMultiStringSliceFromEnvCascade(t *testing.T) { } func TestParseMultiInt(t *testing.T) { - a := App{ + _ = (&App{ Flags: []Flag{ IntFlag{Name: "serve, s"}, }, @@ -776,13 +775,12 @@ func TestParseMultiInt(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "-s", "10"}) + }).Run([]string{"run", "-s", "10"}) } func TestParseDestinationInt(t *testing.T) { var dest int - a := App{ + _ = (&App{ Flags: []Flag{ IntFlag{ Name: "dest", @@ -795,14 +793,13 @@ func TestParseDestinationInt(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--dest", "10"}) + }).Run([]string{"run", "--dest", "10"}) } func TestParseMultiIntFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_TIMEOUT_SECONDS", "10") - a := App{ + _ = os.Setenv("APP_TIMEOUT_SECONDS", "10") + _ = (&App{ Flags: []Flag{ IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"}, }, @@ -815,14 +812,13 @@ func TestParseMultiIntFromEnv(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseMultiIntFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_TIMEOUT_SECONDS", "10") - a := App{ + _ = os.Setenv("APP_TIMEOUT_SECONDS", "10") + _ = (&App{ Flags: []Flag{ IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"}, }, @@ -835,12 +831,11 @@ func TestParseMultiIntFromEnvCascade(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseMultiIntSlice(t *testing.T) { - (&App{ + _ = (&App{ Flags: []Flag{ IntSliceFlag{Name: "serve, s", Value: &IntSlice{}}, }, @@ -858,9 +853,9 @@ func TestParseMultiIntSlice(t *testing.T) { func TestParseMultiIntSliceFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_INTERVALS", "20,30,40") + _ = os.Setenv("APP_INTERVALS", "20,30,40") - (&App{ + _ = (&App{ Flags: []Flag{ IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "APP_INTERVALS"}, }, @@ -878,9 +873,9 @@ func TestParseMultiIntSliceFromEnv(t *testing.T) { func TestParseMultiIntSliceFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_INTERVALS", "20,30,40") + _ = os.Setenv("APP_INTERVALS", "20,30,40") - (&App{ + _ = (&App{ Flags: []Flag{ IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"}, }, @@ -897,7 +892,7 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) { } func TestParseMultiInt64Slice(t *testing.T) { - (&App{ + _ = (&App{ Flags: []Flag{ Int64SliceFlag{Name: "serve, s", Value: &Int64Slice{}}, }, @@ -915,9 +910,9 @@ func TestParseMultiInt64Slice(t *testing.T) { func TestParseMultiInt64SliceFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_INTERVALS", "20,30,17179869184") + _ = os.Setenv("APP_INTERVALS", "20,30,17179869184") - (&App{ + _ = (&App{ Flags: []Flag{ Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "APP_INTERVALS"}, }, @@ -935,9 +930,9 @@ func TestParseMultiInt64SliceFromEnv(t *testing.T) { func TestParseMultiInt64SliceFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_INTERVALS", "20,30,17179869184") + _ = os.Setenv("APP_INTERVALS", "20,30,17179869184") - (&App{ + _ = (&App{ Flags: []Flag{ Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"}, }, @@ -954,7 +949,7 @@ func TestParseMultiInt64SliceFromEnvCascade(t *testing.T) { } func TestParseMultiFloat64(t *testing.T) { - a := App{ + _ = (&App{ Flags: []Flag{ Float64Flag{Name: "serve, s"}, }, @@ -967,13 +962,12 @@ func TestParseMultiFloat64(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "-s", "10.2"}) + }).Run([]string{"run", "-s", "10.2"}) } func TestParseDestinationFloat64(t *testing.T) { var dest float64 - a := App{ + _ = (&App{ Flags: []Flag{ Float64Flag{ Name: "dest", @@ -986,14 +980,13 @@ func TestParseDestinationFloat64(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--dest", "10.2"}) + }).Run([]string{"run", "--dest", "10.2"}) } func TestParseMultiFloat64FromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_TIMEOUT_SECONDS", "15.5") - a := App{ + _ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5") + _ = (&App{ Flags: []Flag{ Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"}, }, @@ -1006,14 +999,13 @@ func TestParseMultiFloat64FromEnv(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseMultiFloat64FromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_TIMEOUT_SECONDS", "15.5") - a := App{ + _ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5") + _ = (&App{ Flags: []Flag{ Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"}, }, @@ -1026,12 +1018,11 @@ func TestParseMultiFloat64FromEnvCascade(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseMultiBool(t *testing.T) { - a := App{ + _ = (&App{ Flags: []Flag{ BoolFlag{Name: "serve, s"}, }, @@ -1044,15 +1035,14 @@ func TestParseMultiBool(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--serve"}) + }).Run([]string{"run", "--serve"}) } func TestParseBoolShortOptionHandle(t *testing.T) { - a := App{ + _ = (&App{ Commands: []Command{ { - Name: "foobar", + Name: "foobar", UseShortOptionHandling: true, Action: func(ctx *Context) error { if ctx.Bool("serve") != true { @@ -1069,13 +1059,12 @@ func TestParseBoolShortOptionHandle(t *testing.T) { }, }, }, - } - a.Run([]string{"run", "foobar", "-so"}) + }).Run([]string{"run", "foobar", "-so"}) } func TestParseDestinationBool(t *testing.T) { var dest bool - a := App{ + _ = (&App{ Flags: []Flag{ BoolFlag{ Name: "dest", @@ -1088,14 +1077,13 @@ func TestParseDestinationBool(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--dest"}) + }).Run([]string{"run", "--dest"}) } func TestParseMultiBoolFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_DEBUG", "1") - a := App{ + _ = os.Setenv("APP_DEBUG", "1") + _ = (&App{ Flags: []Flag{ BoolFlag{Name: "debug, d", EnvVar: "APP_DEBUG"}, }, @@ -1108,14 +1096,13 @@ func TestParseMultiBoolFromEnv(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseMultiBoolFromEnvCascade(t *testing.T) { os.Clearenv() os.Setenv("APP_DEBUG", "1") - a := App{ + _ = (&App{ Flags: []Flag{ BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"}, }, @@ -1128,8 +1115,7 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseBoolTFromEnv(t *testing.T) { @@ -1145,8 +1131,8 @@ func TestParseBoolTFromEnv(t *testing.T) { for _, test := range boolTFlagTests { os.Clearenv() - os.Setenv("DEBUG", test.input) - a := App{ + _ = os.Setenv("DEBUG", test.input) + _ = (&App{ Flags: []Flag{ BoolTFlag{Name: "debug, d", EnvVar: "DEBUG"}, }, @@ -1159,13 +1145,12 @@ func TestParseBoolTFromEnv(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } } func TestParseMultiBoolT(t *testing.T) { - a := App{ + _ = (&App{ Flags: []Flag{ BoolTFlag{Name: "serve, s"}, }, @@ -1178,13 +1163,12 @@ func TestParseMultiBoolT(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--serve"}) + }).Run([]string{"run", "--serve"}) } func TestParseDestinationBoolT(t *testing.T) { var dest bool - a := App{ + _ = (&App{ Flags: []Flag{ BoolTFlag{ Name: "dest", @@ -1197,14 +1181,13 @@ func TestParseDestinationBoolT(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "--dest"}) + }).Run([]string{"run", "--dest"}) } func TestParseMultiBoolTFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_DEBUG", "0") - a := App{ + _ = os.Setenv("APP_DEBUG", "0") + _ = (&App{ Flags: []Flag{ BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"}, }, @@ -1217,14 +1200,13 @@ func TestParseMultiBoolTFromEnv(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseMultiBoolTFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_DEBUG", "0") - a := App{ + _ = os.Setenv("APP_DEBUG", "0") + _ = (&App{ Flags: []Flag{ BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"}, }, @@ -1237,8 +1219,7 @@ func TestParseMultiBoolTFromEnvCascade(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } type Parser [2]string @@ -1264,7 +1245,7 @@ func (p *Parser) Get() interface{} { } func TestParseGeneric(t *testing.T) { - a := App{ + _ = (&App{ Flags: []Flag{ GenericFlag{Name: "serve, s", Value: &Parser{}}, }, @@ -1277,14 +1258,13 @@ func TestParseGeneric(t *testing.T) { } return nil }, - } - a.Run([]string{"run", "-s", "10,20"}) + }).Run([]string{"run", "-s", "10,20"}) } func TestParseGenericFromEnv(t *testing.T) { os.Clearenv() - os.Setenv("APP_SERVE", "20,30") - a := App{ + _ = os.Setenv("APP_SERVE", "20,30") + _ = (&App{ Flags: []Flag{ GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"}, }, @@ -1297,14 +1277,13 @@ func TestParseGenericFromEnv(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestParseGenericFromEnvCascade(t *testing.T) { os.Clearenv() - os.Setenv("APP_FOO", "99,2000") - a := App{ + _ = os.Setenv("APP_FOO", "99,2000") + _ = (&App{ Flags: []Flag{ GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"}, }, @@ -1314,8 +1293,7 @@ func TestParseGenericFromEnvCascade(t *testing.T) { } return nil }, - } - a.Run([]string{"run"}) + }).Run([]string{"run"}) } func TestFlagFromFile(t *testing.T) { @@ -1327,10 +1305,10 @@ func TestFlagFromFile(t *testing.T) { t.Error(err) return } - io.WriteString(temp, "abc") - temp.Close() + _, _ = io.WriteString(temp, "abc") + _ = temp.Close() defer func() { - os.Remove(temp.Name()) + _ = os.Remove(temp.Name()) }() var filePathTests = []struct { diff --git a/help.go b/help.go index 33985d3..7a4ef69 100644 --- a/help.go +++ b/help.go @@ -21,7 +21,7 @@ var helpCommand = Command{ return ShowCommandHelp(c, args.First()) } - ShowAppHelp(c) + _ = ShowAppHelp(c) return nil }, } @@ -61,7 +61,7 @@ var VersionPrinter = printVersion // ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. func ShowAppHelpAndExit(c *Context, exitCode int) { - ShowAppHelp(c) + _ = ShowAppHelp(c) os.Exit(exitCode) } @@ -95,11 +95,11 @@ func printCommandSuggestions(commands []Command, writer io.Writer) { } if os.Getenv("_CLI_ZSH_AUTOCOMPLETE_HACK") == "1" { for _, name := range command.Names() { - fmt.Fprintf(writer, "%s:%s\n", name, command.Usage) + _, _ = fmt.Fprintf(writer, "%s:%s\n", name, command.Usage) } } else { for _, name := range command.Names() { - fmt.Fprintf(writer, "%s\n", name) + _, _ = fmt.Fprintf(writer, "%s\n", name) } } } @@ -144,7 +144,7 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) { // match if last argument matches this flag and it is not repeated if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(flag.GetName()) { flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name) - fmt.Fprintln(writer, flagCompletion) + _, _ = fmt.Fprintln(writer, flagCompletion) } } } @@ -172,7 +172,7 @@ func DefaultCompleteWithFlags(cmd *Command) func(c *Context) { // ShowCommandHelpAndExit - exits with code after showing help func ShowCommandHelpAndExit(c *Context, command string, code int) { - ShowCommandHelp(c, command) + _ = ShowCommandHelp(c, command) os.Exit(code) } @@ -214,7 +214,7 @@ func ShowVersion(c *Context) { } func printVersion(c *Context) { - fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version) + _, _ = fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version) } // ShowCompletions prints the lists of commands within a given context @@ -253,11 +253,11 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc m // If the writer is closed, t.Execute will fail, and there's nothing // we can do to recover. if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" { - fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) + _, _ = fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) } return } - w.Flush() + _ = w.Flush() } func printHelp(out io.Writer, templ string, data interface{}) { @@ -290,7 +290,7 @@ func checkHelp(c *Context) bool { func checkCommandHelp(c *Context, name string) bool { if c.Bool("h") || c.Bool("help") { - ShowCommandHelp(c, name) + _ = ShowCommandHelp(c, name) return true } @@ -299,7 +299,7 @@ func checkCommandHelp(c *Context, name string) bool { func checkSubcommandHelp(c *Context) bool { if c.Bool("h") || c.Bool("help") { - ShowSubcommandHelp(c) + _ = ShowSubcommandHelp(c) return true } diff --git a/help_test.go b/help_test.go index 70b6300..b13eef4 100644 --- a/help_test.go +++ b/help_test.go @@ -16,9 +16,9 @@ func Test_ShowAppHelp_NoAuthor(t *testing.T) { c := NewContext(app, nil, nil) - ShowAppHelp(c) + _ = ShowAppHelp(c) - if bytes.Index(output.Bytes(), []byte("AUTHOR(S):")) != -1 { + if bytes.Contains(output.Bytes(), []byte("AUTHOR(S):")) { t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):") } } @@ -32,9 +32,9 @@ func Test_ShowAppHelp_NoVersion(t *testing.T) { c := NewContext(app, nil, nil) - ShowAppHelp(c) + _ = ShowAppHelp(c) - if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 { + if bytes.Contains(output.Bytes(), []byte("VERSION:")) { t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:") } } @@ -48,9 +48,9 @@ func Test_ShowAppHelp_HideVersion(t *testing.T) { c := NewContext(app, nil, nil) - ShowAppHelp(c) + _ = ShowAppHelp(c) - if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 { + if bytes.Contains(output.Bytes(), []byte("VERSION:")) { t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:") } } @@ -79,7 +79,7 @@ func Test_Help_Custom_Flags(t *testing.T) { } output := new(bytes.Buffer) app.Writer = output - app.Run([]string{"test", "-h"}) + _ = app.Run([]string{"test", "-h"}) if output.Len() > 0 { t.Errorf("unexpected output: %s", output.String()) } @@ -109,7 +109,7 @@ func Test_Version_Custom_Flags(t *testing.T) { } output := new(bytes.Buffer) app.Writer = output - app.Run([]string{"test", "-v"}) + _ = app.Run([]string{"test", "-v"}) if output.Len() > 0 { t.Errorf("unexpected output: %s", output.String()) } @@ -119,7 +119,7 @@ func Test_helpCommand_Action_ErrorIfNoTopic(t *testing.T) { app := NewApp() set := flag.NewFlagSet("test", 0) - set.Parse([]string{"foo"}) + _ = set.Parse([]string{"foo"}) c := NewContext(app, set, nil) @@ -147,7 +147,7 @@ func Test_helpCommand_InHelpOutput(t *testing.T) { app := NewApp() output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"test", "--help"}) + _ = app.Run([]string{"test", "--help"}) s := output.String() @@ -164,7 +164,7 @@ func Test_helpSubcommand_Action_ErrorIfNoTopic(t *testing.T) { app := NewApp() set := flag.NewFlagSet("test", 0) - set.Parse([]string{"foo"}) + _ = set.Parse([]string{"foo"}) c := NewContext(app, set, nil) @@ -203,7 +203,7 @@ func TestShowAppHelp_CommandAliases(t *testing.T) { output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"foo", "--help"}) + _ = app.Run([]string{"foo", "--help"}) if !strings.Contains(output.String(), "frobbly, fr, frob") { t.Errorf("expected output to include all command aliases; got: %q", output.String()) @@ -225,7 +225,7 @@ func TestShowCommandHelp_CommandAliases(t *testing.T) { output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"foo", "help", "fr"}) + _ = app.Run([]string{"foo", "help", "fr"}) if !strings.Contains(output.String(), "frobbly") { t.Errorf("expected output to include command name; got: %q", output.String()) @@ -251,7 +251,7 @@ func TestShowSubcommandHelp_CommandAliases(t *testing.T) { output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"foo", "help"}) + _ = app.Run([]string{"foo", "help"}) if !strings.Contains(output.String(), "frobbly, fr, frob, bork") { t.Errorf("expected output to include all command aliases; got: %q", output.String()) @@ -285,7 +285,7 @@ EXAMPLES: } output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"foo", "help", "frobbly"}) + _ = app.Run([]string{"foo", "help", "frobbly"}) if strings.Contains(output.String(), "2. Frobbly runs without this param locally.") { t.Errorf("expected output to exclude \"2. Frobbly runs without this param locally.\"; got: %q", output.String()) @@ -313,7 +313,7 @@ func TestShowSubcommandHelp_CommandUsageText(t *testing.T) { output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"foo", "frobbly", "--help"}) + _ = app.Run([]string{"foo", "frobbly", "--help"}) if !strings.Contains(output.String(), "this is usage text") { t.Errorf("expected output to include usage text; got: %q", output.String()) @@ -337,7 +337,7 @@ func TestShowSubcommandHelp_SubcommandUsageText(t *testing.T) { output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"foo", "frobbly", "bobbly", "--help"}) + _ = app.Run([]string{"foo", "frobbly", "bobbly", "--help"}) if !strings.Contains(output.String(), "this is usage text") { t.Errorf("expected output to include usage text; got: %q", output.String()) @@ -365,7 +365,7 @@ func TestShowAppHelp_HiddenCommand(t *testing.T) { output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"app", "--help"}) + _ = app.Run([]string{"app", "--help"}) if strings.Contains(output.String(), "secretfrob") { t.Errorf("expected output to exclude \"secretfrob\"; got: %q", output.String()) @@ -423,7 +423,7 @@ VERSION: output := &bytes.Buffer{} app.Writer = output - app.Run([]string{"app", "--help"}) + _ = app.Run([]string{"app", "--help"}) if strings.Contains(output.String(), "secretfrob") { t.Errorf("expected output to exclude \"secretfrob\"; got: %q", output.String())