Skip to content

Commit

Permalink
Remove redundant nil check in LocalFlagNames
Browse files Browse the repository at this point in the history
From the Go specification:

  "1. For a nil slice, the number of iterations is 0." [1]

Therefore, an additional nil check for before the loop is unnecessary.

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee committed Sep 16, 2023
1 parent a8de551 commit 3da6a64
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,9 @@ func (cmd *Command) LocalFlagNames() []string {
cmd.flagSet.Visit(makeFlagNameVisitor(&names))

// Check the flags which have been set via env or file
if cmd.Flags != nil {
for _, f := range cmd.Flags {
if f.IsSet() {
names = append(names, f.Names()...)
}
for _, f := range cmd.Flags {
if f.IsSet() {
names = append(names, f.Names()...)
}
}

Expand Down

0 comments on commit 3da6a64

Please sign in to comment.