Implement code review feedback
This commit is contained in:
+1
-1
@@ -649,7 +649,7 @@ func (c *Context) parseFlag(flags []*Flag, match string) (err error) {
|
|||||||
if flag.Short != 0 {
|
if flag.Short != 0 {
|
||||||
candidates = append(candidates, short)
|
candidates = append(candidates, short)
|
||||||
}
|
}
|
||||||
if short != match && long != match && neg != match {
|
if short != match && long != match && !(match == neg && flag.Tag.Negatable) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Found a matching flag.
|
// Found a matching flag.
|
||||||
|
|||||||
@@ -382,6 +382,21 @@ func TestInvertedNegatedBooleanFlag(t *testing.T) {
|
|||||||
require.Equal(t, true, cli.Cmd.Flag)
|
require.Equal(t, true, cli.Cmd.Flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExistingNoFlag(t *testing.T) {
|
||||||
|
var cli struct {
|
||||||
|
Cmd struct {
|
||||||
|
Flag bool `kong:"default='true'"`
|
||||||
|
NoFlag string
|
||||||
|
} `kong:"cmd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
p := mustNew(t, &cli)
|
||||||
|
_, err := p.Parse([]string{"cmd", "--no-flag=none"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, true, cli.Cmd.Flag)
|
||||||
|
require.Equal(t, "none", cli.Cmd.NoFlag)
|
||||||
|
}
|
||||||
|
|
||||||
func TestInvalidNegatedNonBool(t *testing.T) {
|
func TestInvalidNegatedNonBool(t *testing.T) {
|
||||||
var cli struct {
|
var cli struct {
|
||||||
Cmd struct {
|
Cmd struct {
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
|
|||||||
t.Prefix = t.Get("prefix")
|
t.Prefix = t.Get("prefix")
|
||||||
t.Embed = t.Has("embed")
|
t.Embed = t.Has("embed")
|
||||||
negatable := t.Has("negatable")
|
negatable := t.Has("negatable")
|
||||||
if negatable && ft.Type.Name() != "bool" {
|
if negatable && ft.Type.Kind() != reflect.Bool {
|
||||||
fail("negatable can only be set on booleans")
|
fail("negatable can only be set on booleans")
|
||||||
}
|
}
|
||||||
t.Negatable = negatable
|
t.Negatable = negatable
|
||||||
|
|||||||
Reference in New Issue
Block a user