ParseArgs function parses the given and the command line arguments and returns an Args.
(args []string)
| 32 | |
| 33 | // ParseArgs function parses the given and the command line arguments and returns an Args. |
| 34 | func ParseArgs(args []string) (*Args, error) { |
| 35 | cmdLineArgs := &Args{ |
| 36 | optArgs: make(map[string][]string), |
| 37 | nonOptsArgs: make([]string, 0), |
| 38 | } |
| 39 | |
| 40 | for _, arg := range args { |
| 41 | if strings.HasPrefix(arg, "--") { |
| 42 | indexOfEqualSign := strings.Index(arg, "=") |
| 43 | |
| 44 | if indexOfEqualSign == -1 { |
| 45 | return nil, fmt.Errorf("wrong argument format '%s'", arg) |
| 46 | } else { |
| 47 | cmdLineArgs.addOptionArgs(arg[2:indexOfEqualSign], arg[indexOfEqualSign+1:]) |
| 48 | } |
| 49 | |
| 50 | } else { |
| 51 | cmdLineArgs.addNonOptionArgs(arg) |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | |
| 56 | return cmdLineArgs, nil |
| 57 | } |
| 58 | |
| 59 | // OptionNames method returns the names of the option arguments. |
| 60 | func (a *Args) OptionNames() []string { |