Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting issues #1696

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions altsrc/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
continue
}
for _, n := range f.Names() {
_ = f.set.Set(n, value.String())
if err := f.set.Set(n, value.String()); err != nil {
skelouse marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}
}

Expand Down Expand Up @@ -109,10 +111,12 @@
continue
}
underlyingFlag.Value = &sliceValue
f.set.Set(n, sliceValue.Serialize())
if err := f.set.Set(n, sliceValue.Serialize()); err != nil {
dearchap marked this conversation as resolved.
Show resolved Hide resolved
return err
}

Check warning on line 116 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
_ = f.Destination.Set(sliceValue.Serialize())
skelouse marked this conversation as resolved.
Show resolved Hide resolved
}
}
return nil
Expand Down Expand Up @@ -143,7 +147,9 @@
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}

Check warning on line 152 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L151-L152

Added lines #L151 - L152 were not covered by tests
}
}
return nil
Expand Down Expand Up @@ -174,7 +180,9 @@
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}

Check warning on line 185 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L184-L185

Added lines #L184 - L185 were not covered by tests
}
}
return nil
Expand Down Expand Up @@ -205,7 +213,9 @@
underlyingFlag.Value = &sliceValue
}
if f.Destination != nil {
f.Destination.Set(sliceValue.Serialize())
if err := f.Destination.Set(sliceValue.Serialize()); err != nil {
return err
}

Check warning on line 218 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L217-L218

Added lines #L217 - L218 were not covered by tests
}
}
return nil
Expand All @@ -225,7 +235,9 @@
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
}

Check warning on line 240 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L239-L240

Added lines #L239 - L240 were not covered by tests
}
}
return nil
Expand All @@ -245,7 +257,9 @@
return err
}
for _, n := range f.Names() {
_ = f.set.Set(n, value)
if err := f.set.Set(n, value); err != nil {
return err
}

Check warning on line 262 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L261-L262

Added lines #L261 - L262 were not covered by tests
}
}
return nil
Expand Down Expand Up @@ -275,7 +289,9 @@
}
value = filepath.Join(filepath.Dir(basePathAbs), value)
}
_ = f.set.Set(n, value)
if err := f.set.Set(n, value); err != nil {
return err
}

Check warning on line 294 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L293-L294

Added lines #L293 - L294 were not covered by tests
}
}
return nil
Expand All @@ -295,7 +311,9 @@
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
}

Check warning on line 316 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L315-L316

Added lines #L315 - L316 were not covered by tests
}
}
return nil
Expand All @@ -314,7 +332,9 @@
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
}

Check warning on line 337 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L336-L337

Added lines #L336 - L337 were not covered by tests
}
}
return nil
Expand All @@ -333,7 +353,9 @@
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
}

Check warning on line 358 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L357-L358

Added lines #L357 - L358 were not covered by tests
}
}
return nil
Expand All @@ -352,7 +374,9 @@
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
}

Check warning on line 379 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L378-L379

Added lines #L378 - L379 were not covered by tests
}
}
return nil
Expand All @@ -372,7 +396,9 @@
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
}

Check warning on line 401 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L400-L401

Added lines #L400 - L401 were not covered by tests
}
}
return nil
Expand All @@ -393,7 +419,9 @@
}
floatStr := float64ToString(value)
for _, n := range f.Names() {
_ = f.set.Set(n, floatStr)
if err := f.set.Set(n, floatStr); err != nil {
return err
}

Check warning on line 424 in altsrc/flag.go

View check run for this annotation

Codecov / codecov/patch

altsrc/flag.go#L423-L424

Added lines #L423 - L424 were not covered by tests
}
}
return nil
Expand Down
18 changes: 18 additions & 0 deletions altsrc/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
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
Loading