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

Method GetTime

time.go:60–78  ·  view source on GitHub ↗

GetTime return the time value of a flag with the given name

(name string)

Source from the content-addressed store, hash-verified

58
59// GetTime return the time value of a flag with the given name
60func (f *FlagSet) GetTime(name string) (time.Time, error) {
61 flag := f.Lookup(name)
62 if flag == nil {
63 err := fmt.Errorf("flag accessed but not defined: %s", name)
64 return time.Time{}, err
65 }
66
67 if flag.Value.Type() != "time" {
68 err := fmt.Errorf("trying to get %s value of flag of type %s", "time", flag.Value.Type())
69 return time.Time{}, err
70 }
71
72 val, ok := flag.Value.(*timeValue)
73 if !ok {
74 return time.Time{}, fmt.Errorf("value %s is not a time", flag.Value)
75 }
76
77 return *val.Time, nil
78}
79
80// TimeVar defines a time.Time flag with specified name, default value, and usage string.
81// The argument p points to a time.Time variable in which to store the value of the flag.

Callers 1

TestTimeFunction · 0.80

Calls 2

LookupMethod · 0.95
TypeMethod · 0.65

Tested by 1

TestTimeFunction · 0.64