From b7b2800f4ec20d4f3c790505752fd6deab739867 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sun, 1 Feb 2026 16:59:30 -0500 Subject: [PATCH 1/3] Fix:(issue_2254) Fix incorrect handling of arg after short option token --- command_parse.go | 1 + command_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/command_parse.go b/command_parse.go index aa95ae1677..0d22dae452 100644 --- a/command_parse.go +++ b/command_parse.go @@ -207,6 +207,7 @@ func (cmd *Command) parseFlags(args Args) (Args, error) { return &stringSliceArgs{posArgs}, fmt.Errorf("%s%s", argumentNotProvidedErrMsg, string(c)) } flagVal = rargs[1] + rargs = rargs[1:] } tracef("parseFlags (flagName %[1]q) (flagVal %[2]q)", flagName, flagVal) if err := cmd.set(flagName, sf, flagVal); err != nil { diff --git a/command_test.go b/command_test.go index efc64e9b56..258a7f3b67 100644 --- a/command_test.go +++ b/command_test.go @@ -1413,6 +1413,34 @@ func TestCommand_UseShortOptionAfterSliceFlag(t *testing.T) { assert.Equal(t, expected, name) } +func TestCommand_UseShortOptionWithRootArg(t *testing.T) { + + var rootPath string + cmd := &Command{ + UseShortOptionHandling: true, + Commands: []*Command{ + { + Name: "short", + Usage: "complete a task on the list", + Arguments: []Argument{ + &StringArg{Name: "root", UsageText: "Root path", Destination: &rootPath}, + }, + Flags: []Flag{ + &BoolFlag{Name: "serve", Aliases: []string{"s"}}, + &BoolFlag{Name: "option", Aliases: []string{"o"}}, + &StringFlag{Name: "message", Aliases: []string{"m"}}, + }, + Action: func(ctx context.Context, cmd *Command) error { + return nil + }, + }, + }, + } + err := cmd.Run(buildTestContext(t), []string{"app", "short", "-som", "hello", "/path/to/root"}) + require.NoError(t, err) + require.Equal(t, "/path/to/root", rootPath) +} + func TestCommand_Float64Flag(t *testing.T) { var meters float64 From a232f94aaad821643d0671a1466b81ba11c01912 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sun, 1 Feb 2026 17:01:44 -0500 Subject: [PATCH 2/3] Change test name --- command_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_test.go b/command_test.go index 258a7f3b67..b37b808a3b 100644 --- a/command_test.go +++ b/command_test.go @@ -1413,7 +1413,7 @@ func TestCommand_UseShortOptionAfterSliceFlag(t *testing.T) { assert.Equal(t, expected, name) } -func TestCommand_UseShortOptionWithRootArg(t *testing.T) { +func TestCommand_UseShortOptionWithArg(t *testing.T) { var rootPath string cmd := &Command{ From b81360aeaecf47dd93c907b2dd5b4a366befe8d6 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 2 Feb 2026 07:24:05 -0500 Subject: [PATCH 3/3] Run gofumpt --- command_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/command_test.go b/command_test.go index b37b808a3b..d9b70f52dd 100644 --- a/command_test.go +++ b/command_test.go @@ -1414,7 +1414,6 @@ func TestCommand_UseShortOptionAfterSliceFlag(t *testing.T) { } func TestCommand_UseShortOptionWithArg(t *testing.T) { - var rootPath string cmd := &Command{ UseShortOptionHandling: true,