in pkg/cli/flags.go [286:324]
func (cl *CommandLineInterface) ByteQuantityFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *bytequantity.ByteQuantity, description string) {
invalidInputMsg := fmt.Sprintf("Invalid input for --%s. A valid example is 16gb.", name)
byteQuantityProcessor := func(val interface{}) error {
if val == nil {
return nil
}
switch byteQuantityInput := val.(type) {
case *string:
bq, err := bytequantity.ParseToByteQuantity(*byteQuantityInput)
if err != nil {
return fmt.Errorf("%s Can't parse byte quantity %s", invalidInputMsg, *byteQuantityInput)
}
cl.Flags[name] = &bq
case *bytequantity.ByteQuantity:
return nil
default:
return fmt.Errorf("%s Input type is unsupported", invalidInputMsg)
}
return nil
}
byteQuantityValidator := func(val interface{}) error {
if val == nil {
return nil
}
switch val.(type) {
case *bytequantity.ByteQuantity:
return nil
default:
return fmt.Errorf("%s Processing failed", invalidInputMsg)
}
}
var stringDefaultValue *string
if defaultValue != nil {
stringDefaultValue = cl.StringMe(defaultValue.StringGiB())
} else {
stringDefaultValue = nil
}
cl.StringFlagOnFlagSet(flagSet, name, shorthand, stringDefaultValue, description, byteQuantityProcessor, byteQuantityValidator)
}