fix: set trailing positional arguments to active

This fixes an issue where existingfile et al would not correctly apply
to positional arguments with defaults.
This commit is contained in:
Alec Thomas
2023-11-17 15:37:44 +11:00
parent 0ecd272e23
commit 575d5b1d34
2 changed files with 33 additions and 0 deletions
+15
View File
@@ -4,6 +4,8 @@ import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
@@ -1984,3 +1986,16 @@ func TestEnumPtrOmittedNoDefault(t *testing.T) {
assert.NotZero(t, ctx)
assert.Zero(t, cli.X)
}
func TestTrailingPositionalActive(t *testing.T) {
var cli struct {
Arg string `arg:"" default:"." existingdir:"testdata"`
}
pwd, err := os.Getwd()
assert.NoError(t, err)
k, err := kong.New(&cli)
assert.NoError(t, err)
_, err = k.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, cli.Arg, filepath.Join(pwd, "testdata"))
}