Merge branch 'bryanl-set-context-values' of https://github.com/bryanl/cli into bryanl-bryanl-set-context-values

This commit is contained in:
Dan Buch 2016-04-30 11:25:05 -04:00
commit 4edb5c9a6b
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC
2 changed files with 14 additions and 0 deletions

View File

@ -141,6 +141,11 @@ func (c *Context) NumFlags() int {
return c.flagSet.NFlag() return c.flagSet.NFlag()
} }
// Set sets a context flag to a value.
func (c *Context) Set(name, value string) error {
return c.flagSet.Set(name, value)
}
// Determines if the flag was actually set // Determines if the flag was actually set
func (c *Context) IsSet(name string) bool { func (c *Context) IsSet(name string) bool {
if c.setFlags == nil { if c.setFlags == nil {

View File

@ -202,3 +202,12 @@ func TestContext_GlobalFlagsInSubcommands(t *testing.T) {
expect(t, subcommandRun, true) expect(t, subcommandRun, true)
expect(t, parentFlag, true) expect(t, parentFlag, true)
} }
func TestContext_Set(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("int", 5, "an int")
c := NewContext(nil, set, nil)
c.Set("int", "1")
expect(t, c.Int("int"), 1)
}