Skip to content

Commit 2e1ec2e

Browse files
committed
Remove -- from arg slice
1 parent 32910cb commit 2e1ec2e

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

command_parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (cmd *Command) parseFlags(args Args) (Args, error) {
8484

8585
// stop parsing once we see a "--"
8686
if firstArg == "--" {
87-
posArgs = append(posArgs, rargs...)
87+
posArgs = append(posArgs, rargs[1:]...)
8888
return &stringSliceArgs{posArgs}, nil
8989
}
9090

command_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,7 @@ func TestCommand_CommandWithFlagBeforeTerminator(t *testing.T) {
946946

947947
require.Equal(t, "my-option", parsedOption)
948948
require.Equal(t, "my-arg", args.Get(0))
949-
require.Equal(t, "--", args.Get(1))
950-
require.Equal(t, "--notARealFlag", args.Get(2))
949+
require.Equal(t, "--notARealFlag", args.Get(1))
951950
}
952951

953952
func TestCommand_CommandWithDash(t *testing.T) {
@@ -990,8 +989,7 @@ func TestCommand_CommandWithNoFlagBeforeTerminator(t *testing.T) {
990989

991990
require.NotNil(t, args)
992991
require.Equal(t, "my-arg", args.Get(0))
993-
require.Equal(t, "--", args.Get(1))
994-
require.Equal(t, "notAFlagAtAll", args.Get(2))
992+
require.Equal(t, "notAFlagAtAll", args.Get(1))
995993
}
996994

997995
func TestCommand_SkipFlagParsing(t *testing.T) {

completion_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"bytes"
5+
"context"
56
"fmt"
67
"testing"
78

@@ -149,6 +150,7 @@ func TestCompletionSubcommand(t *testing.T) {
149150
Name: "l1",
150151
},
151152
},
153+
Action: func(ctx context.Context, c *Command) error { return nil },
152154
Commands: []*Command{
153155
{
154156
Name: "xyz",
@@ -160,6 +162,7 @@ func TestCompletionSubcommand(t *testing.T) {
160162
},
161163
},
162164
},
165+
Action: func(ctx context.Context, c *Command) error { return nil },
163166
},
164167
},
165168
},

help.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ func helpCommandAction(ctx context.Context, cmd *Command) error {
8989
// Case 4. $ app help foo
9090
// foo is the command for which help needs to be shown
9191
if firstArg != "" {
92-
if firstArg == "--" {
92+
/* if firstArg == "--" {
9393
return nil
94-
}
94+
}*/
9595
tracef("returning ShowCommandHelp with %[1]q", firstArg)
9696
return ShowCommandHelp(ctx, cmd, firstArg)
9797
}
@@ -243,7 +243,7 @@ func DefaultCompleteWithFlags(ctx context.Context, cmd *Command) {
243243
}
244244

245245
if lastArg == "--" {
246-
tracef("not printing flag suggestion as last arg is --")
246+
tracef("No completions due to termination")
247247
return
248248
}
249249

help_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ func TestDefaultCompleteWithFlags(t *testing.T) {
12911291
},
12921292
},
12931293
},
1294-
argv: []string{"putz", "-e", completionFlag},
1294+
argv: []string{"cmd", "putz", "-e", completionFlag},
12951295
env: map[string]string{"SHELL": "zsh"},
12961296
expected: "--excitement:an exciting flag\n",
12971297
},
@@ -1311,7 +1311,7 @@ func TestDefaultCompleteWithFlags(t *testing.T) {
13111311
},
13121312
},
13131313
},
1314-
argv: []string{"putz", "-e", completionFlag},
1314+
argv: []string{"cmd", "putz", "-e", completionFlag},
13151315
env: map[string]string{"SHELL": "zsh"},
13161316
expected: "--excitement\n",
13171317
},

0 commit comments

Comments
 (0)