-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflags.go
46 lines (35 loc) · 865 Bytes
/
flags.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
package hcli
import (
"github.com/jtagcat/hcli/harg"
)
type (
Flag interface {
flag() flag
checkCondition(*harg.Definition) error
}
flag struct {
Level FlagLevel // Local/Global/Child/Parent
Type harg.Type
AlsoBool bool
Options []string
Env string
EnvCSV bool
Default any // value to set when nothing is set
Usage string
child *ChildFlag
}
)
type FlagLevel uint8 // enum:
const (
Local FlagLevel = iota // only available in the defined command
Global // available in the command, and all subcommands implementing it (with Child)
Parent // available in all subcommands implementing it, not available in the same command
) //
var flagLevelMax = Parent
func (f *flag) def() harg.Definition {
return harg.Definition{
Type: f.Type,
AlsoBool: f.AlsoBool,
EnvCSV: f.EnvCSV,
}
}