Repository navigation
Expand file tree
/
Copy pathgroup.go
More file actions
82 lines (69 loc) · 1.83 KB
/
Copy pathgroup.go
File metadata and controls
82 lines (69 loc) · 1.83 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package applause
// GroupType represents the type of argument group
type GroupType int
const (
// MutuallyExclusiveGroup means only one argument from the group can be provided
MutuallyExclusiveGroup GroupType = iota
// RequiredGroup means at least one argument from the group must be provided
RequiredGroup
)
// ArgGroup represents a group of related arguments
type ArgGroup struct {
name string
groupType GroupType
args []string // argument names in this group
help string
}
// NewArgGroup creates a new argument group
func NewArgGroup(name string) *ArgGroup {
return &ArgGroup{
name: name,
groupType: MutuallyExclusiveGroup, // default
args: make([]string, 0),
}
}
// Type sets the group type
func (g *ArgGroup) Type(groupType GroupType) *ArgGroup {
g.groupType = groupType
return g
}
// Help sets the help text for the group
func (g *ArgGroup) Help(help string) *ArgGroup {
g.help = help
return g
}
// AddArg adds an argument to the group by name
func (g *ArgGroup) AddArg(argName string) *ArgGroup {
g.args = append(g.args, argName)
return g
}
// AddArgs adds multiple arguments to the group by name
func (g *ArgGroup) AddArgs(argNames ...string) *ArgGroup {
g.args = append(g.args, argNames...)
return g
}
// GetName returns the group name
func (g *ArgGroup) GetName() string {
return g.name
}
// GetType returns the group type
func (g *ArgGroup) GetType() GroupType {
return g.groupType
}
// GetArgs returns the argument names in this group
func (g *ArgGroup) GetArgs() []string {
return g.args
}
// GetHelp returns the help text for the group
func (g *ArgGroup) GetHelp() string {
return g.help
}
// ContainsArg checks if the group contains a specific argument
func (g *ArgGroup) ContainsArg(argName string) bool {
for _, name := range g.args {
if name == argName {
return true
}
}
return false
}