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

Method ParseAll

flag.go:1209–1229  ·  view source on GitHub ↗

ParseAll parses flag definitions from the argument list, which should not include the command name. The arguments for fn are flag and value. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help was set but n

(arguments []string, fn func(flag *Flag, value string) error)

Source from the content-addressed store, hash-verified

1207// accessed by the program. The return value will be ErrHelp if -help was set
1208// but not defined.
1209func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string) error) error {
1210 f.parsed = true
1211 f.args = make([]string, 0, len(arguments))
1212
1213 err := f.parseArgs(arguments, fn)
1214 if err != nil {
1215 switch f.errorHandling {
1216 case ContinueOnError:
1217 return err
1218 case ExitOnError:
1219 if err == ErrHelp {
1220 os.Exit(0)
1221 }
1222 fmt.Fprintln(f.Output(), err)
1223 os.Exit(2)
1224 case PanicOnError:
1225 panic(err)
1226 }
1227 }
1228 return nil
1229}
1230
1231// Parsed reports whether f.Parse has been called.
1232func (f *FlagSet) Parsed() bool {

Callers 3

testParseAllFunction · 0.80
ParseAllFunction · 0.80

Calls 2

parseArgsMethod · 0.95
OutputMethod · 0.95

Tested by 2

testParseAllFunction · 0.64