use strings.Join
@@ -308,16 +308,8 @@ func checkRequiredFlags(flags []Flag, set *flag.FlagSet) error {
return fmt.Errorf("Required flag %q not set", missingFlags[0])
}
if numberOfMissingFlags >= 2 {
- var missingFlagsOutput string
- for idx, f := range missingFlags {
- // if not the last item, append with a ", "
- if idx != numberOfMissingFlags-1 {
- missingFlagsOutput = fmt.Sprintf("%s%s, ", missingFlagsOutput, f)
- } else {
- missingFlagsOutput = fmt.Sprintf("%s%s", missingFlagsOutput, f)
- }
- }
- return fmt.Errorf("Required flags %q not set", missingFlagsOutput)
+ joinedMissingFlags := strings.Join(missingFlags, ", ")
+ return fmt.Errorf("Required flags %q not set", joinedMissingFlags)
}
return nil
