diff --git a/altsrc/flag.go b/altsrc/flag.go index 084ba3f9e1..d252aba16a 100644 --- a/altsrc/flag.go +++ b/altsrc/flag.go @@ -79,7 +79,9 @@ func (f *GenericFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCo continue } for _, n := range f.Names() { - _ = f.set.Set(n, value.String()) + if err := f.set.Set(n, value.String()); err != nil { + return err + } } } @@ -109,10 +111,12 @@ func (f *StringSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSour continue } underlyingFlag.Value = &sliceValue - f.set.Set(n, sliceValue.Serialize()) + if err := f.set.Set(n, sliceValue.Serialize()); err != nil { + return err + } } if f.Destination != nil { - f.Destination.Set(sliceValue.Serialize()) + _ = f.Destination.Set(sliceValue.Serialize()) } } return nil @@ -143,7 +147,9 @@ func (f *IntSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC underlyingFlag.Value = &sliceValue } if f.Destination != nil { - f.Destination.Set(sliceValue.Serialize()) + if err := f.Destination.Set(sliceValue.Serialize()); err != nil { + return err + } } } return nil @@ -174,7 +180,9 @@ func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourc underlyingFlag.Value = &sliceValue } if f.Destination != nil { - f.Destination.Set(sliceValue.Serialize()) + if err := f.Destination.Set(sliceValue.Serialize()); err != nil { + return err + } } } return nil @@ -205,7 +213,9 @@ func (f *Float64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSou underlyingFlag.Value = &sliceValue } if f.Destination != nil { - f.Destination.Set(sliceValue.Serialize()) + if err := f.Destination.Set(sliceValue.Serialize()); err != nil { + return err + } } } return nil @@ -225,7 +235,9 @@ func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte return err } for _, n := range f.Names() { - _ = f.set.Set(n, strconv.FormatBool(value)) + if err := f.set.Set(n, strconv.FormatBool(value)); err != nil { + return err + } } } return nil @@ -245,7 +257,9 @@ func (f *StringFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCon return err } for _, n := range f.Names() { - _ = f.set.Set(n, value) + if err := f.set.Set(n, value); err != nil { + return err + } } } return nil @@ -275,7 +289,9 @@ func (f *PathFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte } value = filepath.Join(filepath.Dir(basePathAbs), value) } - _ = f.set.Set(n, value) + if err := f.set.Set(n, value); err != nil { + return err + } } } return nil @@ -295,7 +311,9 @@ func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContex return err } for _, n := range f.Names() { - _ = f.set.Set(n, strconv.FormatInt(int64(value), 10)) + if err := f.set.Set(n, strconv.FormatInt(int64(value), 10)); err != nil { + return err + } } } return nil @@ -314,7 +332,9 @@ func (f *Int64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCont return err } for _, n := range f.Names() { - _ = f.set.Set(n, strconv.FormatInt(value, 10)) + if err := f.set.Set(n, strconv.FormatInt(value, 10)); err != nil { + return err + } } } return nil @@ -333,7 +353,9 @@ func (f *UintFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte return err } for _, n := range f.Names() { - _ = f.set.Set(n, strconv.FormatUint(uint64(value), 10)) + if err := f.set.Set(n, strconv.FormatUint(uint64(value), 10)); err != nil { + return err + } } } return nil @@ -352,7 +374,9 @@ func (f *Uint64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCon return err } for _, n := range f.Names() { - _ = f.set.Set(n, strconv.FormatUint(value, 10)) + if err := f.set.Set(n, strconv.FormatUint(value, 10)); err != nil { + return err + } } } return nil @@ -372,7 +396,9 @@ func (f *DurationFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC return err } for _, n := range f.Names() { - _ = f.set.Set(n, value.String()) + if err := f.set.Set(n, value.String()); err != nil { + return err + } } } return nil @@ -393,7 +419,9 @@ func (f *Float64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCo } floatStr := float64ToString(value) for _, n := range f.Names() { - _ = f.set.Set(n, floatStr) + if err := f.set.Set(n, floatStr); err != nil { + return err + } } } return nil diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index 9341ff2f24..c41d6dbca2 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -65,6 +65,24 @@ func TestGenericApplyInputSourceValue(t *testing.T) { refute(t, v, c.Generic("test")) } +func TestGenericApplyInputSourceValueError(t *testing.T) { + set := flag.NewFlagSet("", flag.ContinueOnError) + c := cli.NewContext(nil, set, nil) + + testFlag := &GenericFlag{ + GenericFlag: &cli.GenericFlag{ + Name: "test", + Value: &cli.StringSlice{}, + }, + set: set, + } + + err := testFlag.ApplyInputSourceValue(c, NewMapInputSource("", map[interface{}]interface{}{ + "test": testFlag.Value, + })) + expect(t, err, fmt.Errorf("no such flag -test")) +} + func TestGenericApplyInputSourceMethodContextSet(t *testing.T) { p := &Parser{"abc", "def"} tis := testApplyInputSource{ diff --git a/app.go b/app.go index e07dd7b192..f69a1939b1 100644 --- a/app.go +++ b/app.go @@ -458,30 +458,6 @@ func (a *App) handleExitCoder(cCtx *Context, err error) { } } -func (a *App) commandNames() []string { - var cmdNames []string - - for _, cmd := range a.Commands { - cmdNames = append(cmdNames, cmd.Names()...) - } - - return cmdNames -} - -func (a *App) validCommandName(checkCmdName string) bool { - valid := false - allCommandNames := a.commandNames() - - for _, cmdName := range allCommandNames { - if checkCmdName == cmdName { - valid = true - break - } - } - - return valid -} - func (a *App) argsWithDefaultCommand(oldArgs Args) Args { if a.DefaultCommand != "" { rawArgs := append([]string{a.DefaultCommand}, oldArgs.Slice()...) diff --git a/app_test.go b/app_test.go index d07d2c0735..f27c3d5451 100644 --- a/app_test.go +++ b/app_test.go @@ -48,7 +48,9 @@ func ExampleApp_Run() { Authors: []*Author{{Name: "Oliver Allen", Email: "oliver@toyshop.example.com"}}, } - app.Run(os.Args) + if err := app.Run(os.Args); err != nil { + return + } // Output: // Hello Jeremy } @@ -2719,8 +2721,8 @@ func TestFlagAction(t *testing.T) { if v == "" { return fmt.Errorf("empty string") } - c.App.Writer.Write([]byte(v + " ")) - return nil + _, err := c.App.Writer.Write([]byte(v + " ")) + return err }, } app := &App{ @@ -2750,8 +2752,8 @@ func TestFlagAction(t *testing.T) { if v[0] == "err" { return fmt.Errorf("error string slice") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &BoolFlag{ @@ -2760,8 +2762,8 @@ func TestFlagAction(t *testing.T) { if !v { return fmt.Errorf("value is false") } - c.App.Writer.Write([]byte(fmt.Sprintf("%t ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%t ", v))) + return err }, }, &DurationFlag{ @@ -2770,8 +2772,8 @@ func TestFlagAction(t *testing.T) { if v == 0 { return fmt.Errorf("empty duration") } - c.App.Writer.Write([]byte(v.String() + " ")) - return nil + _, err := c.App.Writer.Write([]byte(v.String() + " ")) + return err }, }, &Float64Flag{ @@ -2780,8 +2782,8 @@ func TestFlagAction(t *testing.T) { if v < 0 { return fmt.Errorf("negative float64") } - c.App.Writer.Write([]byte(strconv.FormatFloat(v, 'f', -1, 64) + " ")) - return nil + _, err := c.App.Writer.Write([]byte(strconv.FormatFloat(v, 'f', -1, 64) + " ")) + return err }, }, &Float64SliceFlag{ @@ -2790,8 +2792,8 @@ func TestFlagAction(t *testing.T) { if len(v) > 0 && v[0] < 0 { return fmt.Errorf("invalid float64 slice") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &GenericFlag{ @@ -2806,8 +2808,8 @@ func TestFlagAction(t *testing.T) { } } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &IntFlag{ @@ -2816,8 +2818,8 @@ func TestFlagAction(t *testing.T) { if v < 0 { return fmt.Errorf("negative int") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &IntSliceFlag{ @@ -2826,8 +2828,8 @@ func TestFlagAction(t *testing.T) { if len(v) > 0 && v[0] < 0 { return fmt.Errorf("invalid int slice") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &Int64Flag{ @@ -2836,8 +2838,8 @@ func TestFlagAction(t *testing.T) { if v < 0 { return fmt.Errorf("negative int64") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &Int64SliceFlag{ @@ -2846,8 +2848,8 @@ func TestFlagAction(t *testing.T) { if len(v) > 0 && v[0] < 0 { return fmt.Errorf("invalid int64 slice") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &PathFlag{ @@ -2856,8 +2858,8 @@ func TestFlagAction(t *testing.T) { if v == "" { return fmt.Errorf("empty path") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &TimestampFlag{ @@ -2867,8 +2869,8 @@ func TestFlagAction(t *testing.T) { if v.IsZero() { return fmt.Errorf("zero timestamp") } - c.App.Writer.Write([]byte(v.Format(time.RFC3339) + " ")) - return nil + _, err := c.App.Writer.Write([]byte(v.Format(time.RFC3339) + " ")) + return err }, }, &UintFlag{ @@ -2877,8 +2879,8 @@ func TestFlagAction(t *testing.T) { if v == 0 { return fmt.Errorf("zero uint") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, &Uint64Flag{ @@ -2887,8 +2889,8 @@ func TestFlagAction(t *testing.T) { if v == 0 { return fmt.Errorf("zero uint64") } - c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return nil + _, err := c.App.Writer.Write([]byte(fmt.Sprintf("%v ", v))) + return err }, }, }, diff --git a/category.go b/category.go index ccc043c254..b1847eca18 100644 --- a/category.go +++ b/category.go @@ -111,7 +111,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories { } } - if categorized == true { + if categorized { for _, fl := range fs { if cf, ok := fl.(CategorizableFlag); ok { if cf.GetCategory() == "" { diff --git a/command_test.go b/command_test.go index d6e40c9a27..3aa2a45996 100644 --- a/command_test.go +++ b/command_test.go @@ -538,7 +538,8 @@ func TestCommand_PreservesSeparatorOnSubcommands(t *testing.T) { SliceFlagSeparator: ";", } - app.Run([]string{"app", "foo", "bar", "--my-flag", "1;2;3"}) + err := app.Run([]string{"app", "foo", "bar", "--my-flag", "1;2;3"}) + expect(t, err, nil) expect(t, values, []string{"1", "2", "3"}) } diff --git a/context_test.go b/context_test.go index 9faf157386..5dc4fae6d2 100644 --- a/context_test.go +++ b/context_test.go @@ -325,7 +325,7 @@ func TestContext_Set_InvalidFlagAccessHandler(t *testing.T) { }, } c := NewContext(app, set, nil) - c.Set("missing", "") + expect(t, c.Set("missing", "") != nil, true) expect(t, flagName, "missing") } @@ -411,10 +411,12 @@ func TestNonNilContext(t *testing.T) { // *cli.Context always has a valid // context.Context func TestContextPropagation(t *testing.T) { + type testKey struct{} + parent := NewContext(nil, nil, nil) - parent.Context = context.WithValue(context.Background(), "key", "val") + parent.Context = context.WithValue(context.Background(), testKey{}, "val") ctx := NewContext(nil, nil, parent) - val := ctx.Context.Value("key") + val := ctx.Context.Value(testKey{}) if val == nil { t.Fatal("expected a parent context to be inherited but got nil") } diff --git a/flag_test.go b/flag_test.go index 2e01766ecf..4971de624f 100644 --- a/flag_test.go +++ b/flag_test.go @@ -42,7 +42,9 @@ func TestBoolFlagApply_SetsAllNames(t *testing.T) { v := false fl := BoolFlag{Name: "wat", Aliases: []string{"W", "huh"}, Destination: &v} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--wat", "-W", "--huh"}) expect(t, err, nil) @@ -124,7 +126,8 @@ func TestBoolFlagCountFromContext(t *testing.T) { }, } - app.Run(bct.input) + err := app.Run(bct.input) + expect(t, err, nil) } } @@ -510,7 +513,9 @@ func TestStringFlagHelpOutput(t *testing.T) { fl := &StringFlag{Name: test.name, Aliases: test.aliases, Usage: test.usage, Value: test.value} // create a tmp flagset tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + } output := fl.String() if output != test.expected { @@ -577,7 +582,9 @@ func TestStringFlagApply_SetsAllNames(t *testing.T) { v := "mmm" fl := StringFlag{Name: "hay", Aliases: []string{"H", "hayyy"}, Destination: &v} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--hay", "u", "-H", "yuu", "--hayyy", "YUUUU"}) expect(t, err, nil) @@ -609,7 +616,10 @@ func TestPathFlagHelpOutput(t *testing.T) { // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() @@ -638,7 +648,10 @@ func TestPathFlagApply_SetsAllNames(t *testing.T) { v := "mmm" fl := PathFlag{Name: "path", Aliases: []string{"p", "PATH"}, Destination: &v} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + return + } err := set.Parse([]string{"--path", "/path/to/file/path", "-p", "/path/to/file/p", "--PATH", "/path/to/file/PATH"}) expect(t, err, nil) @@ -731,7 +744,9 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) { func TestStringSliceFlagApply_SetsAllNames(t *testing.T) { fl := StringSliceFlag{Name: "goat", Aliases: []string{"G", "gooots"}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--goat", "aaa", "-G", "bbb", "--gooots", "eeeee"}) expect(t, err, nil) @@ -744,7 +759,9 @@ func TestStringSliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { var val StringSlice fl := StringSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) @@ -759,7 +776,9 @@ func TestStringSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { val := NewStringSlice(`some default`, `values here`) fl := StringSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) expect(t, val.Value(), []string{`some default`, `values here`}) @@ -771,7 +790,9 @@ func TestStringSliceFlagApply_DefaultValueWithDestination(t *testing.T) { fl := StringSliceFlag{Name: "country", Value: NewStringSlice(defValue...), Destination: NewStringSlice("CA")} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{}) expect(t, err, nil) @@ -885,7 +906,10 @@ func TestIntFlagHelpOutput(t *testing.T) { // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() @@ -915,7 +939,9 @@ func TestIntFlagApply_SetsAllNames(t *testing.T) { v := 3 fl := IntFlag{Name: "banana", Aliases: []string{"B", "banannanana"}, Destination: &v} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--banana", "1", "-B", "2", "--banannanana", "5"}) expect(t, err, nil) @@ -944,7 +970,10 @@ func TestInt64FlagHelpOutput(t *testing.T) { // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() @@ -992,7 +1021,10 @@ func TestUintFlagHelpOutput(t *testing.T) { // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() @@ -1040,7 +1072,10 @@ func TestUint64FlagHelpOutput(t *testing.T) { // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() @@ -1088,7 +1123,10 @@ func TestDurationFlagHelpOutput(t *testing.T) { // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() @@ -1118,7 +1156,9 @@ func TestDurationFlagApply_SetsAllNames(t *testing.T) { v := time.Second * 20 fl := DurationFlag{Name: "howmuch", Aliases: []string{"H", "whyyy"}, Destination: &v} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--howmuch", "30s", "-H", "5m", "--whyyy", "30h"}) expect(t, err, nil) @@ -1174,7 +1214,9 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) { func TestIntSliceFlagApply_SetsAllNames(t *testing.T) { fl := IntSliceFlag{Name: "bits", Aliases: []string{"B", "bips"}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"}) expect(t, err, nil) @@ -1187,7 +1229,9 @@ func TestIntSliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { var val IntSlice fl := IntSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) @@ -1202,7 +1246,9 @@ func TestIntSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { val := NewIntSlice(3, 4) fl := IntSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) expect(t, val.Value(), []int{3, 4}) @@ -1214,7 +1260,9 @@ func TestIntSliceFlagApply_DefaultValueWithDestination(t *testing.T) { fl := IntSliceFlag{Name: "country", Value: NewIntSlice(defValue...), Destination: NewIntSlice(3)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{}) expect(t, err, nil) @@ -1247,7 +1295,9 @@ func TestIntSliceFlagApply_ParentContext(t *testing.T) { func TestIntSliceFlag_SetFromParentContext(t *testing.T) { fl := &IntSliceFlag{Name: "numbers", Aliases: []string{"n"}, Value: NewIntSlice(1, 2, 3, 4)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1310,7 +1360,9 @@ func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) { func TestInt64SliceFlagApply_SetsAllNames(t *testing.T) { fl := Int64SliceFlag{Name: "bits", Aliases: []string{"B", "bips"}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"}) expect(t, err, nil) @@ -1323,7 +1375,9 @@ func TestInt64SliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { var val Int64Slice fl := Int64SliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) @@ -1338,7 +1392,9 @@ func TestInt64SliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { val := NewInt64Slice(3, 4) fl := Int64SliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) expect(t, val.Value(), []int64{3, 4}) @@ -1350,7 +1406,9 @@ func TestInt64SliceFlagApply_DefaultValueWithDestination(t *testing.T) { fl := Int64SliceFlag{Name: "country", Value: NewInt64Slice(defValue...), Destination: NewInt64Slice(3)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{}) expect(t, err, nil) @@ -1383,7 +1441,9 @@ func TestInt64SliceFlagApply_ParentContext(t *testing.T) { func TestInt64SliceFlag_SetFromParentContext(t *testing.T) { fl := &Int64SliceFlag{Name: "numbers", Aliases: []string{"n"}, Value: NewInt64Slice(1, 2, 3, 4)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1398,7 +1458,9 @@ func TestInt64SliceFlag_SetFromParentContext(t *testing.T) { func TestInt64SliceFlag_ReturnNil(t *testing.T) { fl := &Int64SliceFlag{} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1461,7 +1523,9 @@ func TestUintSliceFlagWithEnvVarHelpOutput(t *testing.T) { func TestUintSliceFlagApply_SetsAllNames(t *testing.T) { fl := UintSliceFlag{Name: "bits", Aliases: []string{"B", "bips"}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"}) expect(t, err, nil) @@ -1474,7 +1538,9 @@ func TestUintSliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { var val UintSlice fl := UintSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) @@ -1489,7 +1555,9 @@ func TestUintSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { val := NewUintSlice(3, 4) fl := UintSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) expect(t, val.Value(), []uint{3, 4}) @@ -1501,7 +1569,9 @@ func TestUintSliceFlagApply_DefaultValueWithDestination(t *testing.T) { fl := UintSliceFlag{Name: "country", Value: NewUintSlice(defValue...), Destination: NewUintSlice(3)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{}) expect(t, err, nil) @@ -1534,7 +1604,9 @@ func TestUintSliceFlagApply_ParentContext(t *testing.T) { func TestUintSliceFlag_SetFromParentContext(t *testing.T) { fl := &UintSliceFlag{Name: "numbers", Aliases: []string{"n"}, Value: NewUintSlice(1, 2, 3, 4)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1549,7 +1621,9 @@ func TestUintSliceFlag_SetFromParentContext(t *testing.T) { func TestUintSliceFlag_ReturnNil(t *testing.T) { fl := &UintSliceFlag{} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1604,7 +1678,9 @@ func TestUint64SliceFlagWithEnvVarHelpOutput(t *testing.T) { func TestUint64SliceFlagApply_SetsAllNames(t *testing.T) { fl := Uint64SliceFlag{Name: "bits", Aliases: []string{"B", "bips"}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"}) expect(t, err, nil) @@ -1617,7 +1693,9 @@ func TestUint64SliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { var val Uint64Slice fl := Uint64SliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) @@ -1632,7 +1710,9 @@ func TestUint64SliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { val := NewUint64Slice(3, 4) fl := Uint64SliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) expect(t, val.Value(), []uint64{3, 4}) @@ -1644,7 +1724,9 @@ func TestUint64SliceFlagApply_DefaultValueWithDestination(t *testing.T) { fl := Uint64SliceFlag{Name: "country", Value: NewUint64Slice(defValue...), Destination: NewUint64Slice(3)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{}) expect(t, err, nil) @@ -1677,7 +1759,9 @@ func TestUint64SliceFlagApply_ParentContext(t *testing.T) { func TestUint64SliceFlag_SetFromParentContext(t *testing.T) { fl := &Uint64SliceFlag{Name: "numbers", Aliases: []string{"n"}, Value: NewUint64Slice(1, 2, 3, 4)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1692,7 +1776,9 @@ func TestUint64SliceFlag_SetFromParentContext(t *testing.T) { func TestUint64SliceFlag_ReturnNil(t *testing.T) { fl := &Uint64SliceFlag{} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } ctx := &Context{ parentContext: &Context{ flagSet: set, @@ -1744,7 +1830,9 @@ func TestFloat64FlagApply_SetsAllNames(t *testing.T) { v := 99.1 fl := Float64Flag{Name: "noodles", Aliases: []string{"N", "nurbles"}, Destination: &v} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--noodles", "1.3", "-N", "11", "--nurbles", "43.33333"}) expect(t, err, nil) @@ -1800,7 +1888,9 @@ func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) { func TestFloat64SliceFlagApply_SetsAllNames(t *testing.T) { fl := Float64SliceFlag{Name: "bits", Aliases: []string{"B", "bips"}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"}) expect(t, err, nil) @@ -1813,7 +1903,9 @@ func TestFloat64SliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { var val Float64Slice fl := Float64SliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) @@ -1828,7 +1920,9 @@ func TestFloat64SliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { val := NewFloat64Slice(3.0, 4.0) fl := Float64SliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: val} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse(nil) expect(t, err, nil) expect(t, val.Value(), []float64{3, 4}) @@ -1840,7 +1934,9 @@ func TestFloat64SliceFlagApply_DefaultValueWithDestination(t *testing.T) { fl := Float64SliceFlag{Name: "country", Value: NewFloat64Slice(defValue...), Destination: NewFloat64Slice(3)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{}) expect(t, err, nil) @@ -1892,7 +1988,10 @@ func TestGenericFlagHelpOutput(t *testing.T) { fl := &GenericFlag{Name: test.name, Value: test.value, Usage: "test flag"} // create a temporary flag set to apply tfs := flag.NewFlagSet("test", 0) - fl.Apply(tfs) + if err := fl.Apply(tfs); err != nil { + t.Error(err) + return + } output := fl.String() if output != test.expected { @@ -1920,7 +2019,9 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) { func TestGenericFlagApply_SetsAllNames(t *testing.T) { fl := GenericFlag{Name: "orbs", Aliases: []string{"O", "obrs"}, Value: &Parser{}} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--orbs", "eleventy,3", "-O", "4,bloop", "--obrs", "19,s"}) expect(t, err, nil) @@ -3071,7 +3172,9 @@ func TestTimestampFlagApply(t *testing.T) { expectedResult, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: time.RFC3339} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--time", "2006-01-02T15:04:05Z"}) expect(t, err, nil) @@ -3082,7 +3185,9 @@ func TestTimestampFlagApplyValue(t *testing.T) { expectedResult, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: time.RFC3339, Value: NewTimestamp(expectedResult)} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{""}) expect(t, err, nil) @@ -3093,7 +3198,9 @@ func TestTimestampFlagApply_Fail_Parse_Wrong_Layout(t *testing.T) { fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: "randomlayout"} set := flag.NewFlagSet("test", 0) set.SetOutput(io.Discard) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--time", "2006-01-02T15:04:05Z"}) expect(t, err, fmt.Errorf("invalid value \"2006-01-02T15:04:05Z\" for flag -time: parsing time \"2006-01-02T15:04:05Z\" as \"randomlayout\": cannot parse \"2006-01-02T15:04:05Z\" as \"randomlayout\"")) @@ -3103,7 +3210,9 @@ func TestTimestampFlagApply_Fail_Parse_Wrong_Time(t *testing.T) { fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: "Jan 2, 2006 at 3:04pm (MST)"} set := flag.NewFlagSet("test", 0) set.SetOutput(io.Discard) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--time", "2006-01-02T15:04:05Z"}) expect(t, err, fmt.Errorf("invalid value \"2006-01-02T15:04:05Z\" for flag -time: parsing time \"2006-01-02T15:04:05Z\" as \"Jan 2, 2006 at 3:04pm (MST)\": cannot parse \"2006-01-02T15:04:05Z\" as \"Jan\"")) @@ -3114,7 +3223,9 @@ func TestTimestampFlagApply_Timezoned(t *testing.T) { expectedResult, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: time.ANSIC, Timezone: pdt} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--time", "Mon Jan 2 08:04:05 2006"}) expect(t, err, nil) @@ -3452,7 +3563,9 @@ func TestTimestampFlagApply_WithDestination(t *testing.T) { expectedResult, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") fl := TimestampFlag{Name: "time", Aliases: []string{"t"}, Layout: time.RFC3339, Destination: &destination} set := flag.NewFlagSet("test", 0) - _ = fl.Apply(set) + if err := fl.Apply(set); err != nil { + t.Error(err) + } err := set.Parse([]string{"--time", "2006-01-02T15:04:05Z"}) expect(t, err, nil) diff --git a/help.go b/help.go index e855a72fc2..84bd77bc17 100644 --- a/help.go +++ b/help.go @@ -376,17 +376,26 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) - t.New("helpNameTemplate").Parse(helpNameTemplate) - t.New("usageTemplate").Parse(usageTemplate) - t.New("descriptionTemplate").Parse(descriptionTemplate) - t.New("visibleCommandTemplate").Parse(visibleCommandTemplate) - t.New("copyrightTemplate").Parse(copyrightTemplate) - t.New("versionTemplate").Parse(versionTemplate) - t.New("visibleFlagCategoryTemplate").Parse(visibleFlagCategoryTemplate) - t.New("visibleFlagTemplate").Parse(visibleFlagTemplate) - t.New("visibleGlobalFlagCategoryTemplate").Parse(strings.Replace(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS", -1)) - t.New("authorsTemplate").Parse(authorsTemplate) - t.New("visibleCommandCategoryTemplate").Parse(visibleCommandCategoryTemplate) + templates := map[string]string{ + "helpNameTemplate": helpNameTemplate, + "usageTemplate": usageTemplate, + "descriptionTemplate": descriptionTemplate, + "visibleCommandTemplate": visibleCommandTemplate, + "copyrightTemplate": copyrightTemplate, + "versionTemplate": versionTemplate, + "visibleFlagCategoryTemplate": visibleFlagCategoryTemplate, + "visibleFlagTemplate": visibleFlagTemplate, + "visibleGlobalFlagCategoryTemplate": strings.Replace(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS", -1), + "authorsTemplate": authorsTemplate, + "visibleCommandCategoryTemplate": visibleCommandCategoryTemplate, + } + for name, value := range templates { + if _, err := t.New(name).Parse(value); err != nil { + if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" { + _, _ = fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) + } + } + } err := t.Execute(w, data) if err != nil { diff --git a/help_test.go b/help_test.go index 1188f85e2d..80b38ac1d9 100644 --- a/help_test.go +++ b/help_test.go @@ -1330,7 +1330,7 @@ func TestDefaultCompleteWithFlags(t *testing.T) { tc.a.HideHelp = true tc.a.Writer = writer os.Args = tc.argv - tc.a.Run(tc.argv) + _ = tc.a.Run(tc.argv) written := writer.String() diff --git a/internal/build/build.go b/internal/build/build.go index 490edb3faa..4ffd2c4741 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -179,7 +179,9 @@ func sh(exe string, args ...string) (string, error) { func topRunAction(arg string, args ...string) cli.ActionFunc { return func(cCtx *cli.Context) error { - os.Chdir(cCtx.Path("top")) + if err := os.Chdir(cCtx.Path("top")); err != nil { + return err + } return runCmd(arg, args...) } @@ -283,7 +285,7 @@ func testCleanup(packages []string) error { lines := strings.Split(string(lineBytes), "\n") - fmt.Fprintf(out, strings.Join(lines[1:], "\n")) + fmt.Fprint(out, strings.Join(lines[1:], "\n")) if err := os.Remove(filename); err != nil { return err @@ -456,10 +458,10 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) { desiredMaxSizeString := fmt.Sprintf(mbStringFormatter, desiredMaxBinarySize) // show guidance - fmt.Println(fmt.Sprintf("\n%s is the current binary size", roundedFileSizeString)) + fmt.Printf("\n%s is the current binary size\n", roundedFileSizeString) // show guidance for min size if isLessThanDesiredMin { - fmt.Println(fmt.Sprintf(" %s %s is the target min size", goodNewsEmoji, desiredMinSizeString)) + fmt.Printf(" %s %s is the target min size\n", goodNewsEmoji, desiredMinSizeString) fmt.Println("") // visual spacing fmt.Println(" The binary is smaller than the target min size, which is great news!") fmt.Println(" That means that your changes are shrinking the binary size.") @@ -470,11 +472,11 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) { fmt.Println("") // visual spacing os.Exit(1) } else { - fmt.Println(fmt.Sprintf(" %s %s is the target min size", checksPassedEmoji, desiredMinSizeString)) + fmt.Printf(" %s %s is the target min size\n", checksPassedEmoji, desiredMinSizeString) } // show guidance for max size if isMoreThanDesiredMax { - fmt.Println(fmt.Sprintf(" %s %s is the target max size", badNewsEmoji, desiredMaxSizeString)) + fmt.Printf(" %s %s is the target max size\n", badNewsEmoji, desiredMaxSizeString) fmt.Println("") // visual spacing fmt.Println(" The binary is larger than the target max size.") fmt.Println(" That means that your changes are increasing the binary size.") @@ -488,7 +490,7 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) { fmt.Println("") // visual spacing os.Exit(1) } else { - fmt.Println(fmt.Sprintf(" %s %s is the target max size", checksPassedEmoji, desiredMaxSizeString)) + fmt.Printf(" %s %s is the target max size\n", checksPassedEmoji, desiredMaxSizeString) } return nil @@ -531,13 +533,17 @@ func YAMLFmtActionFunc(cCtx *cli.Context) error { return err } - os.Chdir(cCtx.Path("top")) + if err := os.Chdir(cCtx.Path("top")); err != nil { + return err + } return runCmd(yqBin, "eval", "--inplace", "flag-spec.yaml") } func DiffCheckActionFunc(cCtx *cli.Context) error { - os.Chdir(cCtx.Path("top")) + if err := os.Chdir(cCtx.Path("top")); err != nil { + return err + } if err := runCmd("git", "diff", "--exit-code"); err != nil { return err @@ -548,7 +554,9 @@ func DiffCheckActionFunc(cCtx *cli.Context) error { func EnsureGoimportsActionFunc(cCtx *cli.Context) error { top := cCtx.Path("top") - os.Chdir(top) + if err := os.Chdir(top); err != nil { + return err + } if err := runCmd( "goimports", @@ -567,7 +575,9 @@ func EnsureGfmrunActionFunc(cCtx *cli.Context) error { top := cCtx.Path("top") gfmrunExe := filepath.Join(top, ".local/bin/gfmrun") - os.Chdir(top) + if err := os.Chdir(top); err != nil { + return err + } if v, err := sh(gfmrunExe, "--version"); err == nil && strings.TrimSpace(v) == gfmrunVersion { return nil @@ -587,7 +597,9 @@ func EnsureGfmrunActionFunc(cCtx *cli.Context) error { } func EnsureMkdocsActionFunc(cCtx *cli.Context) error { - os.Chdir(cCtx.Path("top")) + if err := os.Chdir(cCtx.Path("top")); err != nil { + return err + } if err := runCmd("mkdocs", "--version"); err == nil { return nil @@ -608,7 +620,9 @@ func SetMkdocsRemoteActionFunc(cCtx *cli.Context) error { return errors.New("empty github token") } - os.Chdir(cCtx.Path("top")) + if err := os.Chdir(cCtx.Path("top")); err != nil { + return err + } if err := runCmd("git", "remote", "rm", "origin"); err != nil { return err @@ -622,7 +636,9 @@ func SetMkdocsRemoteActionFunc(cCtx *cli.Context) error { func LintActionFunc(cCtx *cli.Context) error { top := cCtx.Path("top") - os.Chdir(top) + if err := os.Chdir(top); err != nil { + return err + } out, err := sh(filepath.Join(top, ".local/bin/goimports"), "-l", ".") if err != nil { @@ -640,7 +656,9 @@ func LintActionFunc(cCtx *cli.Context) error { } func V2Diff(cCtx *cli.Context) error { - os.Chdir(cCtx.Path("top")) + if err := os.Chdir(cCtx.Path("top")); err != nil { + return err + } err := runCmd( "diff", diff --git a/internal/example-cli/example-cli.go b/internal/example-cli/example-cli.go index 06cbbfffcb..9d8c545b9c 100644 --- a/internal/example-cli/example-cli.go +++ b/internal/example-cli/example-cli.go @@ -7,5 +7,5 @@ import ( ) func main() { - (&cli.App{}).Run([]string{""}) + _ = (&cli.App{}).Run([]string{""}) } diff --git a/suggestions_test.go b/suggestions_test.go index 5efbc62695..2136acdc46 100644 --- a/suggestions_test.go +++ b/suggestions_test.go @@ -136,7 +136,9 @@ func ExampleApp_Suggest() { }, } - app.Run([]string{"greet", "--nema", "chipmunk"}) + if err := app.Run([]string{"greet", "--nema", "chipmunk"}); err == nil { + return + } // Output: // Incorrect Usage: flag provided but not defined: -nema // @@ -177,7 +179,9 @@ func ExampleApp_Suggest_command() { }, } - app.Run([]string{"greet", "neighbors", "--sliming"}) + if err := app.Run([]string{"greet", "neighbors", "--sliming"}); err == nil { + return + } // Output: // Incorrect Usage: flag provided but not defined: -sliming //