Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
skelouse committed Oct 7, 2023
1 parent 488e77c commit d7bd472
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 102 deletions.
10 changes: 5 additions & 5 deletions altsrc/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func (f *StringSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSour
continue
}
underlyingFlag.Value = &sliceValue
f.set.Set(n, sliceValue.Serialize())
_ = f.set.Set(n, sliceValue.Serialize())
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
_ = f.Destination.Set(sliceValue.Serialize())
}
}
return nil
Expand Down Expand Up @@ -143,7 +143,7 @@ func (f *IntSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
_ = f.Destination.Set(sliceValue.Serialize())
}
}
return nil
Expand Down Expand Up @@ -174,7 +174,7 @@ func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourc
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
_ = f.Destination.Set(sliceValue.Serialize())
}
}
return nil
Expand Down Expand Up @@ -205,7 +205,7 @@ func (f *Float64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSou
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
_ = f.Destination.Set(sliceValue.Serialize())
}
}
return nil
Expand Down
24 changes: 0 additions & 24 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)
Expand Down
64 changes: 33 additions & 31 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() == "" {
Expand Down
8 changes: 5 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}
Expand Down
42 changes: 33 additions & 9 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ 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)
_ = fl.Apply(tfs)
output := fl.String()

if output != test.expected {
Expand Down Expand Up @@ -609,7 +609,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()

Expand Down Expand Up @@ -638,7 +641,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)
Expand Down Expand Up @@ -885,7 +891,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()

Expand Down Expand Up @@ -944,7 +953,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()

Expand Down Expand Up @@ -992,7 +1004,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()

Expand Down Expand Up @@ -1040,7 +1055,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()

Expand Down Expand Up @@ -1088,7 +1106,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()

Expand Down Expand Up @@ -1892,7 +1913,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 {
Expand Down

0 comments on commit d7bd472

Please sign in to comment.