-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
44 lines (40 loc) · 1.03 KB
/
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
package commander
type Context interface {
// _Argv
GetArg(index int) string
GetArgs(offsets ...int) []string
ArgsString() string
ArgsStringSeparator(sep string, offsets ...int) string
// DocoptMap
Map() map[string]interface{}
Get(key string) interface{}
Contain(key string) bool
GetString(key string) (string, bool)
MustString(key string) string
GetStrings(key string) ([]string, bool)
MustStrings(key string) []string
GetBool(key string) (bool, bool)
MustBool(key string) bool
GetInt64(key string) (int64, bool)
MustInt64(key string) int64
GetInt(key string) (int, bool)
MustInt(key string) int
GetFloat64(key string) (float64, bool)
MustFloat64(key string) float64
GetFloat(key string) (float32, bool)
MustFloat(key string) float32
}
// _Context
type _Context struct {
_Argv `json:"argv"`
DocoptMap `json:"docopt"`
}
func newContext(args []string, d DocoptMap) *_Context {
return &_Context{
_Argv: newArgv(args),
DocoptMap: d,
}
}
func (c _Context) Contain(key string) bool {
return c.DocoptMap.Contain(key)
}