Fix issue with negatable flag being negated twice (#171)

This commit is contained in:
Mary Fesenko
2021-05-22 13:50:50 +02:00
committed by GitHub
parent b3bdeb18e2
commit 1f5bbd5559
2 changed files with 63 additions and 27 deletions
+6 -6
View File
@@ -635,12 +635,7 @@ func (c *Context) Apply() (string, error) {
panic("unsupported path ?!")
}
if value != nil {
v := c.getValue(value)
if value.Flag != nil && value.Flag.Negated {
v.SetBool(!v.Bool())
}
value.Apply(v)
value.Apply(c.getValue(value))
}
}
@@ -673,6 +668,11 @@ func (c *Context) parseFlag(flags []*Flag, match string) (err error) {
}
return err
}
if flag.Negated {
value := c.getValue(flag.Value)
value.SetBool(!value.Bool())
flag.Value.Apply(value)
}
c.Path = append(c.Path, &Path{Flag: flag})
return nil
}