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

Method GetText

text.go:52–61  ·  view source on GitHub ↗

GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name

(name string, out encoding.TextUnmarshaler)

Source from the content-addressed store, hash-verified

50
51// GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name
52func (f *FlagSet) GetText(name string, out encoding.TextUnmarshaler) error {
53 flag := f.Lookup(name)
54 if flag == nil {
55 return fmt.Errorf("flag accessed but not defined: %s", name)
56 }
57 if flag.Value.Type() != reflect.TypeOf(out).Name() {
58 return fmt.Errorf("trying to get %s value of flag of type %s", reflect.TypeOf(out).Name(), flag.Value.Type())
59 }
60 return out.UnmarshalText([]byte(flag.Value.String()))
61}
62
63// TextVar defines a flag with a specified name, default value, and usage string. The argument p must be a pointer to a variable that will hold the value of the flag, and p must implement encoding.TextUnmarshaler. If the flag is used, the flag value will be passed to p's UnmarshalText method. The type of the default value must be the same as the type of p.
64func (f *FlagSet) TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string) {

Callers 1

TestTextFunction · 0.80

Calls 4

LookupMethod · 0.95
NameMethod · 0.80
TypeMethod · 0.65
StringMethod · 0.65

Tested by 1

TestTextFunction · 0.64