MCPcopy
hub / github.com/spf13/pflag / getFlagType

Method getFlagType

flag.go:404–422  ·  flag.go::FlagSet.getFlagType

func to return a given type for a given flag name

(name string, ftype string, convFunc func(sval string) (interface{}, error))

Source from the content-addressed store, hash-verified

402
403// func to return a given type for a given flag name
404func (f *FlagSet) getFlagType(name string, ftype string, convFunc func(sval string) (interface{}, error)) (interface{}, error) {
405 flag := f.Lookup(name)
406 if flag == nil {
407 err := &NotExistError{name: name, messageType: flagNotDefinedMessage}
408 return nil, err
409 }
410
411 if flag.Value.Type() != ftype {
412 err := fmt.Errorf("trying to get %s value of flag of type %s", ftype, flag.Value.Type())
413 return nil, err
414 }
415
416 sval := flag.Value.String()
417 result, err := convFunc(sval)
418 if err != nil {
419 return nil, err
420 }
421 return result, nil
422}
423
424// ArgsLenAtDash will return the length of f.Args at the moment when a -- was
425// found during arg parsing. This allows your program to know which args were

Callers 15

GetIPv4MaskMethod · 0.95
GetStringToIntMethod · 0.95
GetUintMethod · 0.95
GetDurationSliceMethod · 0.95
GetIPNetSliceMethod · 0.95
GetBoolMethod · 0.95
GetUint16Method · 0.95
GetStringArrayMethod · 0.95
GetInt64Method · 0.95
GetStringToInt64Method · 0.95
GetFloat64Method · 0.95
GetCountMethod · 0.95

Calls 3

LookupMethod · 0.95
TypeMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected