Skip to content

Commit

Permalink
Add flag --notty to run command.
Browse files Browse the repository at this point in the history
Summary:
VSCode remote SSH extension needs to run commands inside toolbox without a TTY, otherwise it fails.
  • Loading branch information
likan999 committed Oct 20, 2020
1 parent 03c6989 commit 24e0403
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
runFlags struct {
container string
release string
notty bool
}
)

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

flags.BoolVarP(&runFlags.notty,
"notty",
"T",
false,
"Run command without allocating a pseudo terminal.")

runCmd.SetHelpFunc(runHelp)
rootCmd.AddCommand(runCmd)
}
Expand Down Expand Up @@ -290,11 +297,14 @@ func runCommand(container string,

execArgs = append(execArgs, []string{
"--interactive",
"--tty",
"--user", currentUser.Username,
"--workdir", workingDirectory,
}...)

if !runFlags.notty {
execArgs = append(execArgs, "--tty")
}

execArgs = append(execArgs, envOptions...)

execArgs = append(execArgs, []string{
Expand Down
9 changes: 9 additions & 0 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ toolbox_image=""
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
user_id_real=$(id -ru 2>&3)
verbose=false
no_tty=false


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

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

extra_podman_args=()
if ! $no_tty; then
extra_podman_args+=(--tty)
fi
# shellcheck disable=SC2016
# for the command passed to capsh
# shellcheck disable=SC2086
$podman_command exec \
--interactive \
--tty \
--user "$USER" \
"${extra_podman_args[@]}" \
--workdir "$PWD" \
$set_environment \
"$toolbox_container" \
Expand Down Expand Up @@ -2611,6 +2617,9 @@ case $op in
exit_if_non_positive_argument --release "$arg"
release=$arg
;;
-T | --notty )
no_tty=true
;;
* )
exit_if_unrecognized_option "$1"
esac
Expand Down

0 comments on commit 24e0403

Please sign in to comment.