MCPcopy Create free account
hub / github.com/codnect/procyon / ParseArgs

Function ParseArgs

runtime/argument.go:34–57  ·  view source on GitHub ↗

ParseArgs function parses the given and the command line arguments and returns an Args.

(args []string)

Source from the content-addressed store, hash-verified

32
33// ParseArgs function parses the given and the command line arguments and returns an Args.
34func 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.
60func (a *Args) OptionNames() []string {

Calls 3

addOptionArgsMethod · 0.95
addNonOptionArgsMethod · 0.95
IndexMethod · 0.80