Skip to content

Commit 24e0403

Browse files
committed
Add flag --notty to run command.
Summary: VSCode remote SSH extension needs to run commands inside toolbox without a TTY, otherwise it fails.
1 parent 03c6989 commit 24e0403

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/cmd/run.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
runFlags struct {
3535
container string
3636
release string
37+
notty bool
3738
}
3839
)
3940

@@ -59,6 +60,12 @@ func init() {
5960
"",
6061
"Run command inside a toolbox container for a different operating system release than the host.")
6162

63+
flags.BoolVarP(&runFlags.notty,
64+
"notty",
65+
"T",
66+
false,
67+
"Run command without allocating a pseudo terminal.")
68+
6269
runCmd.SetHelpFunc(runHelp)
6370
rootCmd.AddCommand(runCmd)
6471
}
@@ -290,11 +297,14 @@ func runCommand(container string,
290297

291298
execArgs = append(execArgs, []string{
292299
"--interactive",
293-
"--tty",
294300
"--user", currentUser.Username,
295301
"--workdir", workingDirectory,
296302
}...)
297303

304+
if !runFlags.notty {
305+
execArgs = append(execArgs, "--tty")
306+
}
307+
298308
execArgs = append(execArgs, envOptions...)
299309

300310
execArgs = append(execArgs, []string{

toolbox

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ toolbox_image=""
7272
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
7373
user_id_real=$(id -ru 2>&3)
7474
verbose=false
75+
no_tty=false
7576

7677

7778
LGC='\033[1;32m' # Light Green Color
@@ -1582,13 +1583,18 @@ run()
15821583

15831584
$emit_escape_sequence && printf "\033]777;container;push;%s;toolbox\033\\" "$toolbox_container"
15841585

1586+
extra_podman_args=()
1587+
if ! $no_tty; then
1588+
extra_podman_args+=(--tty)
1589+
fi
15851590
# shellcheck disable=SC2016
15861591
# for the command passed to capsh
15871592
# shellcheck disable=SC2086
15881593
$podman_command exec \
15891594
--interactive \
15901595
--tty \
15911596
--user "$USER" \
1597+
"${extra_podman_args[@]}" \
15921598
--workdir "$PWD" \
15931599
$set_environment \
15941600
"$toolbox_container" \
@@ -2611,6 +2617,9 @@ case $op in
26112617
exit_if_non_positive_argument --release "$arg"
26122618
release=$arg
26132619
;;
2620+
-T | --notty )
2621+
no_tty=true
2622+
;;
26142623
* )
26152624
exit_if_unrecognized_option "$1"
26162625
esac

0 commit comments

Comments
 (0)