update requiredFlagsErr interface, errRequiredFlags struct and associated functions to handle map
This commit is contained in:
parent
addd467e5b
commit
ed4ac1876d
25
context.go
25
context.go
@ -289,23 +289,34 @@ func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
|
|||||||
|
|
||||||
type requiredFlagsErr interface {
|
type requiredFlagsErr interface {
|
||||||
error
|
error
|
||||||
getMissingFlags() []string
|
getMissingFlags() map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type errRequiredFlags struct {
|
type errRequiredFlags struct {
|
||||||
missingFlags []string
|
missingFlags map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *errRequiredFlags) Error() string {
|
func (e *errRequiredFlags) Error() string {
|
||||||
numberOfMissingFlags := len(e.missingFlags)
|
var missingFlagNames []string
|
||||||
if numberOfMissingFlags == 1 {
|
var missingFlagNamesReqErr []string
|
||||||
return fmt.Sprintf("Required flag %q not set", e.missingFlags[0])
|
|
||||||
|
for k, v := range e.missingFlags {
|
||||||
|
if v == false {
|
||||||
|
missingFlagNames = append(missingFlagNames, k)
|
||||||
|
} else {
|
||||||
|
missingFlagNamesReqErr = append(missingFlagNamesReqErr, k)
|
||||||
}
|
}
|
||||||
joinedMissingFlags := strings.Join(e.missingFlags, ", ")
|
}
|
||||||
|
|
||||||
|
numberOfMissingFlags := len(missingFlagNames)
|
||||||
|
if numberOfMissingFlags == 1 {
|
||||||
|
return fmt.Sprintf("Required flag %q not set", missingFlagNames[0])
|
||||||
|
}
|
||||||
|
joinedMissingFlags := strings.Join(missingFlagNames, ", ")
|
||||||
return fmt.Sprintf("Required flags %q not set", joinedMissingFlags)
|
return fmt.Sprintf("Required flags %q not set", joinedMissingFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *errRequiredFlags) getMissingFlags() []string {
|
func (e *errRequiredFlags) getMissingFlags() map[string]bool {
|
||||||
return e.missingFlags
|
return e.missingFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user