X Tutup
Skip to content

Commit 76037ee

Browse files
committed
Update docs, simplify loop to append to command
1 parent 54265af commit 76037ee

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

internal/codespaces/ssh.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,11 @@ func newSSHCommand(ctx context.Context, port int, dst string, cmdArgs []string)
6464
return cmd, connArgs, nil
6565
}
6666

67-
// parseSSHArgs parses SSH arguments into two distinct slices of flags
68-
// and command. It returns an error if flags are found after a command
69-
// or if a unary flag is provided without an argument.
67+
// parseSSHArgs parses SSH arguments into two distinct slices of flags and command.
68+
// It returns an error if a unary flag is provided without an argument.
7069
func parseSSHArgs(args []string) (cmdArgs []string, command []string, err error) {
7170
for i := 0; i < len(args); i++ {
7271
arg := args[i]
73-
if command != nil {
74-
command = append(command, arg)
75-
continue
76-
}
7772

7873
if strings.HasPrefix(arg, "-") {
7974
cmdArgs = append(cmdArgs, arg)
@@ -84,9 +79,12 @@ func parseSSHArgs(args []string) (cmdArgs []string, command []string, err error)
8479

8580
cmdArgs = append(cmdArgs, args[i])
8681
}
87-
} else {
88-
command = append(command, arg)
82+
continue
8983
}
84+
85+
// if we've started parsing the command, append all further args to it
86+
command = append(command, args[i:]...)
87+
break
9088
}
9189

9290
return cmdArgs, command, nil

internal/codespaces/ssh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestParseSSHArgs(t *testing.T) {
6969

7070
for _, tcase := range testCases {
7171
args, command, err := parseSSHArgs(tcase.Args)
72-
if err != nil && !tcase.Error {
72+
if !tcase.Error && err != nil {
7373
t.Errorf("unexpected error: %v on test case: %#v", err, tcase)
7474
continue
7575
}

0 commit comments

Comments
 (0)
X Tutup