GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name
(name string, out encoding.TextUnmarshaler)
| 50 | |
| 51 | // GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name |
| 52 | func (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. |
| 64 | func (f *FlagSet) TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string) { |