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)
| 1207 | // accessed by the program. The return value will be ErrHelp if -help was set |
| 1208 | // but not defined. |
| 1209 | func (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. |
| 1232 | func (f *FlagSet) Parsed() bool { |