Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion command_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ func (cmd *Command) parseFlags(args Args) (Args, error) {
return &stringSliceArgs{posArgs}, nil
}

posArgs = append(posArgs, firstArg)
// firstArg is a trimmed copy that classifies the argument; the
// argument itself is what the action receives, byte for byte.
posArgs = append(posArgs, rargs[0])
continue
}

Expand Down
16 changes: 16 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,22 @@ func TestCommand_CommandWithDash(t *testing.T) {
require.Equal(t, "-", args.Get(1))
}

func TestCommand_PositionalArgsKeepWhitespace(t *testing.T) {
var args Args

cmd := &Command{
Name: "prog",
Action: func(_ context.Context, cmd *Command) error {
args = cmd.Args()
return nil
},
}

require.NoError(t, cmd.Run(buildTestContext(t), []string{"prog", " padded ", "\ttabbed\t"}))
require.NotNil(t, args)
require.Equal(t, []string{" padded ", "\ttabbed\t"}, args.Slice())
}

func TestCommand_CommandWithNoFlagBeforeTerminator(t *testing.T) {
var args Args

Expand Down