Merge pull request #583 from karalabe/invalidate-isset-cache

Invalidate context.setFlags cache on modification.
main
Jesse Szwedko 7 years ago committed by GitHub
commit b892ba3809

@ -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…
Cancel
Save