Skip to content

Commit dafd175

Browse files
authored
Merge pull request #1783 from seipan/refactor-errors-numberOfMissingFlags
Refactor numberOfMissingFlags remove
2 parents 45b41c8 + 91b9029 commit dafd175

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

errors.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ type errRequiredFlags struct {
5555
}
5656

5757
func (e *errRequiredFlags) Error() string {
58-
numberOfMissingFlags := len(e.missingFlags)
59-
if numberOfMissingFlags == 1 {
58+
if len(e.missingFlags) == 1 {
6059
return fmt.Sprintf("Required flag %q not set", e.missingFlags[0])
6160
}
6261
joinedMissingFlags := strings.Join(e.missingFlags, ", ")

errors_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,15 @@ func TestMultiErrorErrorsCopy(t *testing.T) {
169169
me := newMultiError(errList...)
170170
expect(t, errList, me.Errors())
171171
}
172+
173+
func TestErrRequiredFlags_Error(t *testing.T) {
174+
missingFlags := []string{"flag1", "flag2"}
175+
err := &errRequiredFlags{missingFlags: missingFlags}
176+
expectedMsg := "Required flags \"flag1, flag2\" not set"
177+
expect(t, expectedMsg, err.Error())
178+
179+
missingFlags = []string{"flag1"}
180+
err = &errRequiredFlags{missingFlags: missingFlags}
181+
expectedMsg = "Required flag \"flag1\" not set"
182+
expect(t, expectedMsg, err.Error())
183+
}

0 commit comments

Comments
 (0)