Invalidate context.setFlags cache on modification.
This commit is contained in:
parent
8ef3805c9d
commit
acc622e5fb
@ -39,11 +39,13 @@ func (c *Context) NumFlags() int {
|
||||
|
||||
// Set sets a context flag to a value.
|
||||
func (c *Context) Set(name, value string) error {
|
||||
c.setFlags = nil
|
||||
return c.flagSet.Set(name, value)
|
||||
}
|
||||
|
||||
// GlobalSet sets a context flag to a value on the global flagset
|
||||
func (c *Context) GlobalSet(name, value string) error {
|
||||
globalContext(c).setFlags = nil
|
||||
return globalContext(c).flagSet.Set(name, value)
|
||||
}
|
||||
|
||||
|
@ -375,8 +375,10 @@ func TestContext_Set(t *testing.T) {
|
||||
set.Int("int", 5, "an int")
|
||||
c := NewContext(nil, set, nil)
|
||||
|
||||
expect(t, c.IsSet("int"), false)
|
||||
c.Set("int", "1")
|
||||
expect(t, c.Int("int"), 1)
|
||||
expect(t, c.IsSet("int"), true)
|
||||
}
|
||||
|
||||
func TestContext_GlobalSet(t *testing.T) {
|
||||
@ -393,7 +395,9 @@ func TestContext_GlobalSet(t *testing.T) {
|
||||
expect(t, c.Int("int"), 1)
|
||||
expect(t, c.GlobalInt("int"), 5)
|
||||
|
||||
expect(t, c.GlobalIsSet("int"), false)
|
||||
c.GlobalSet("int", "1")
|
||||
expect(t, c.Int("int"), 1)
|
||||
expect(t, c.GlobalInt("int"), 1)
|
||||
expect(t, c.GlobalIsSet("int"), true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user