-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag_options.go
61 lines (53 loc) · 1.59 KB
/
flag_options.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
57
58
59
60
61
package cli
import (
"github.com/bobg/errors"
"github.com/broothie/option"
)
// AddFlagAlias adds an alias to the flag.
func AddFlagAlias(alias string) option.Func[*Flag] {
return func(flag *Flag) (*Flag, error) {
flag.aliases = append(flag.aliases, alias)
return flag, nil
}
}
// AddFlagShort adds a short flag to the flag.
func AddFlagShort(short rune) option.Func[*Flag] {
return func(flag *Flag) (*Flag, error) {
flag.shorts = append(flag.shorts, short)
return flag, nil
}
}
// SetFlagIsHidden controls whether the flag is hidden from the help message.
func SetFlagIsHidden(isHidden bool) option.Func[*Flag] {
return func(flag *Flag) (*Flag, error) {
flag.isHidden = isHidden
return flag, nil
}
}
// SetFlagIsInherited controls whether the flag is inherited by child commands.
func SetFlagIsInherited(isInherited bool) option.Func[*Flag] {
return func(flag *Flag) (*Flag, error) {
flag.isInherited = isInherited
return flag, nil
}
}
// SetFlagDefault sets the default value of the flag.
func SetFlagDefault[T Parseable](defaultValue T) option.Func[*Flag] {
return func(flag *Flag) (*Flag, error) {
argParser, err := argParserFromParseable[T]()
if err != nil {
return nil, errors.Wrapf(err, "")
}
flag.parser = argParser
flag.defaultValue = defaultValue
return flag, nil
}
}
// SetFlagDefaultAndParser sets the default value and parser of the flag.
func SetFlagDefaultAndParser[T any](defaultValue T, argParser ArgParser[T]) option.Func[*Flag] {
return func(flag *Flag) (*Flag, error) {
flag.parser = argParser
flag.defaultValue = defaultValue
return flag, nil
}
}