Revert "fix: set trailing positional arguments to active"

This reverts commit 575d5b1d34.
This commit is contained in:
Alec Thomas
2023-12-10 08:21:36 +11:00
parent b36879c6d4
commit 815ba68265
2 changed files with 0 additions and 33 deletions
-18
View File
@@ -520,26 +520,9 @@ func (c *Context) trace(node *Node) (err error) { // nolint: gocyclo
return fmt.Errorf("unexpected token %s", token)
}
}
if err := c.traceDefaults(); err != nil {
return fmt.Errorf("error tracing defaults: %w", err)
}
return c.maybeSelectDefault(flags, node)
}
func (c *Context) traceDefaults() error {
tail := c.Path[len(c.Path)-1]
for _, positional := range tail.Node().Positional {
if positional.DefaultValue.IsValid() {
positional.Active = true
c.Path = append(c.Path, &Path{
Parent: tail.Node(),
Positional: positional,
})
}
}
return nil
}
// End of the line, check for a default command, but only if we're not displaying help,
// otherwise we'd only ever display the help for the default command.
func (c *Context) maybeSelectDefault(flags []*Flag, node *Node) error {
@@ -549,7 +532,6 @@ func (c *Context) maybeSelectDefault(flags []*Flag, node *Node) error {
}
}
if node.DefaultCmd != nil {
node.Active = true
c.Path = append(c.Path, &Path{
Parent: node.DefaultCmd,
Command: node.DefaultCmd,
-15
View File
@@ -4,8 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
@@ -1986,16 +1984,3 @@ 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"))
}