Matching arg field (#1)

Check if the first field of an argument branch matches the parent struct field.
This commit is contained in:
Gerald Kaszuba
2018-05-18 18:38:53 +10:00
committed by Alec Thomas
parent 67b1a12059
commit b4b5827044
2 changed files with 16 additions and 1 deletions
+4
View File
@@ -79,6 +79,10 @@ func buildNode(v reflect.Value, cmd bool) *Node {
child.Help = value.Help
}
child.Name = value.Name
if child.Name != name {
fail("first field in positional branch %s.%s must have the same name as the parent field (%s).",
v.Type().Name(), ft.Name, child.Name)
}
node.Children = append(node.Children, &Branch{Argument: &Argument{
Node: *child,
Argument: value,
+12 -1
View File
@@ -98,10 +98,21 @@ func TestArgSlice(t *testing.T) {
require.Equal(t, true, cli.Flag)
}
func TestUnsupportedfieldErrors(t *testing.T) {
func TestUnsupportedFieldErrors(t *testing.T) {
var cli struct {
Keys map[string]string
}
_, err := New("", "", &cli)
require.Error(t, err)
}
func TestMatchingArgField(t *testing.T) {
var cli struct {
ID struct {
NotID int `arg:""`
} `arg:""`
}
_, err := New("", "", &cli)
require.Error(t, err)
}