Skip to content

Commit

Permalink
Merge pull request #1783 from seipan/refactor-errors-numberOfMissingF…
Browse files Browse the repository at this point in the history
…lags

Refactor numberOfMissingFlags remove
  • Loading branch information
dearchap authored Jun 26, 2023
2 parents 45b41c8 + 91b9029 commit dafd175
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ type errRequiredFlags struct {
}

func (e *errRequiredFlags) Error() string {
numberOfMissingFlags := len(e.missingFlags)
if numberOfMissingFlags == 1 {
if len(e.missingFlags) == 1 {
return fmt.Sprintf("Required flag %q not set", e.missingFlags[0])
}
joinedMissingFlags := strings.Join(e.missingFlags, ", ")
Expand Down
12 changes: 12 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,15 @@ func TestMultiErrorErrorsCopy(t *testing.T) {
me := newMultiError(errList...)
expect(t, errList, me.Errors())
}

func TestErrRequiredFlags_Error(t *testing.T) {
missingFlags := []string{"flag1", "flag2"}
err := &errRequiredFlags{missingFlags: missingFlags}
expectedMsg := "Required flags \"flag1, flag2\" not set"
expect(t, expectedMsg, err.Error())

missingFlags = []string{"flag1"}
err = &errRequiredFlags{missingFlags: missingFlags}
expectedMsg = "Required flag \"flag1\" not set"
expect(t, expectedMsg, err.Error())
}

0 comments on commit dafd175

Please sign in to comment.