-
Notifications
You must be signed in to change notification settings - Fork 10
/
argument.go
56 lines (47 loc) · 1.27 KB
/
argument.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
52
53
54
55
56
package cmds
type ArgumentType int
const (
ArgString ArgumentType = iota
ArgFile
)
type Argument struct {
Name string
Type ArgumentType
Required bool // error if no value is specified
Variadic bool // unlimited values can be specfied
SupportsStdin bool // can accept stdin as a value
Recursive bool // supports recursive file adding (with '-r' flag)
Description string
}
func StringArg(name string, required, variadic bool, description string) Argument {
return Argument{
Name: name,
Type: ArgString,
Required: required,
Variadic: variadic,
Description: description,
}
}
func FileArg(name string, required, variadic bool, description string) Argument {
return Argument{
Name: name,
Type: ArgFile,
Required: required,
Variadic: variadic,
Description: description,
}
}
// TODO: modifiers might need a different API?
// e.g. passing enum values into arg constructors variadically
// (`FileArg("file", ArgRequired, ArgStdin, ArgRecursive)`)
func (a Argument) EnableStdin() Argument {
a.SupportsStdin = true
return a
}
func (a Argument) EnableRecursive() Argument {
if a.Type != ArgFile {
panic("Only FileArgs can enable recursive")
}
a.Recursive = true
return a
}