Skip to content

Commit 6070e61

Browse files
committed
Omitted optional arg uses the given value
1 parent f7deded commit 6070e61

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

args.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) {
132132
*a.Values = values
133133
}
134134

135-
if a.Max == 1 && a.Destination != nil && len(values) > 0 {
136-
*a.Destination = values[0]
135+
if a.Max == 1 && a.Destination != nil {
136+
if len(values) > 0 {
137+
*a.Destination = values[0]
138+
} else {
139+
*a.Destination = t
140+
}
137141
}
138142
return s[count:], nil
139143
}

args_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ func TestSingleOptionalArg(t *testing.T) {
168168
require.Equal(t, "", s1)
169169

170170
arg.Value = "bar"
171-
require.NoError(t, cmd.Run(context.Background(), []string{"foo", "bar"}))
171+
require.NoError(t, cmd.Run(context.Background(), []string{"foo"}))
172172
require.Equal(t, "bar", s1)
173173
}

0 commit comments

Comments
 (0)