-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
51 lines (38 loc) · 1.18 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package core
import "github.com/procyon-projects/goo"
type CommandLineArgs struct {
optionArgs map[string][]string
nonOptionArgs []string
}
func NewCommandLineArgs() CommandLineArgs {
return CommandLineArgs{
optionArgs: make(map[string][]string),
nonOptionArgs: make([]string, 0),
}
}
func (args CommandLineArgs) addOptionArgs(name string, value string) {
if args.optionArgs[name] == nil {
args.optionArgs[name] = make([]string, 0)
}
args.optionArgs[name] = append(args.optionArgs[name], value)
}
func (args CommandLineArgs) getOptionNames() []string {
argMapKeys := goo.GetType(args.optionArgs).GetGoValue().MapKeys()
mapKeys := make([]string, len(argMapKeys))
for i := 0; i < len(argMapKeys); i++ {
mapKeys[i] = argMapKeys[i].String()
}
return mapKeys
}
func (args CommandLineArgs) containsOption(name string) bool {
return args.optionArgs[name] != nil
}
func (args CommandLineArgs) getOptionValues(name string) []string {
return args.optionArgs[name]
}
func (args *CommandLineArgs) addNonOptionArgs(value string) {
args.nonOptionArgs = append(args.nonOptionArgs, value)
}
func (args CommandLineArgs) getNonOptionArgs() []string {
return args.nonOptionArgs
}