-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
52 lines (42 loc) · 1004 Bytes
/
context.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
package gommand
import (
"context"
"github.com/jimmykodes/gommand/flags"
)
type Context struct {
context.Context
cmd *Command
args []string
preRuns []func(*Context) error
postRuns []func(*Context) error
deferPost bool
silenceHelp bool
silenceError bool
depth int
persistentFlagSets []*flags.FlagSet
flagGetter *flags.FlagGetter
}
func (c *Context) addPersistentFlags(fs *flags.FlagSet) {
c.persistentFlagSets = append(c.persistentFlagSets, fs)
}
func (c *Context) persistentFlags() *flags.FlagSet {
fs := flags.NewFlagSet()
for _, pfs := range c.persistentFlagSets {
fs.AddFlagSet(pfs)
}
return fs
}
func (c *Context) Args() []string {
return c.args
}
// Arg will return the command line argument at the given index
// Returns an empty string if idx is out of range
func (c *Context) Arg(idx int) string {
if idx < len(c.args) {
return c.args[idx]
}
return ""
}
func (c *Context) Flags() *flags.FlagGetter {
return c.flagGetter
}