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:
@@ -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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user