add simple test , fix errors and unused interface SliceFlag
This commit is contained in:
33
context.go
33
context.go
@@ -34,10 +34,16 @@ func (c *Context) String(name string) string {
|
||||
return c.lookupString(name, c.flagSet)
|
||||
}
|
||||
|
||||
func (c *Context) StringSlice(name string) flag.Value {
|
||||
// Looks up the value of a local string slice flag, returns nil if no string slice flag exists
|
||||
func (c *Context) StringSlice(name string) []string {
|
||||
return c.lookupStringSlice(name, c.flagSet)
|
||||
}
|
||||
|
||||
// Looks up the value of a local int slice flag, returns nil if no int slice flag exists
|
||||
func (c *Context) IntSlice(name string) []int {
|
||||
return c.lookupIntSlice(name, c.flagSet)
|
||||
}
|
||||
|
||||
// Looks up the value of a global int flag, returns 0 if no int flag exists
|
||||
func (c *Context) GlobalInt(name string) int {
|
||||
return c.lookupInt(name, c.globalSet)
|
||||
@@ -53,6 +59,16 @@ func (c *Context) GlobalString(name string) string {
|
||||
return c.lookupString(name, c.globalSet)
|
||||
}
|
||||
|
||||
// Looks up the value of a global string slice flag, returns nil if no string slice flag exists
|
||||
func (c *Context) GlobalStringSlice(name string) []string {
|
||||
return c.lookupStringSlice(name, c.globalSet)
|
||||
}
|
||||
|
||||
// Looks up the value of a global int slice flag, returns nil if no int slice flag exists
|
||||
func (c *Context) GlobalIntSlice(name string) []int {
|
||||
return c.lookupIntSlice(name, c.globalSet)
|
||||
}
|
||||
|
||||
func (c *Context) Args() []string {
|
||||
return c.flagSet.Args()
|
||||
}
|
||||
@@ -79,10 +95,21 @@ func (c *Context) lookupString(name string, set *flag.FlagSet) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *Context) lookupStringSlice(name string, set *flag.FlagSet) flag.Value {
|
||||
func (c *Context) lookupStringSlice(name string, set *flag.FlagSet) []string {
|
||||
f := set.Lookup(name)
|
||||
if f != nil {
|
||||
return f.Value
|
||||
return (f.Value.(*StringSlice)).Value()
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Context) lookupIntSlice(name string, set *flag.FlagSet) []int {
|
||||
f := set.Lookup(name)
|
||||
if f != nil {
|
||||
return (f.Value.(*IntSlice)).Value()
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user