-
Notifications
You must be signed in to change notification settings - Fork 5
/
args.go
45 lines (37 loc) · 1 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
package flags
import (
"github.com/spf13/pflag"
)
// Args contains cli argument state
type Args struct {
items []string
}
// NewArgs returns new instance with empty arguments
func NewArgs() *Args {
return &Args{
items: []string{},
}
}
// Append adds argument --argument with corresponding value to state
func (a *Args) Append(argument, value string) *Args {
a.items = append(a.items, "--"+argument, value)
return a
}
// AppendRaw adds string item to state
func (a *Args) AppendRaw(item string) *Args {
a.items = append(a.items, item)
return a
}
// AppendKey adds argument --argument without value to state
func (a *Args) AppendKey(argument string) *Args {
a.items = append(a.items, "--"+argument)
return a
}
// AppendFlag adds argument pflag.Value.Type() with corresponding value pflag.Value.String() to state
func (a *Args) AppendFlag(flag pflag.Value) *Args {
return a.Append(flag.Type(), flag.String())
}
// Get returns args state as slice of strings
func (a *Args) Get() []string {
return a.items
}