Skip to content

Commit 7b64399

Browse files
ulyssessouzandeloof
authored andcommitted
Fix output redirection on command run
Signed-off-by: Ulysses Souza <[email protected]>
1 parent d37b3fe commit 7b64399

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

cmd/compose/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func execCommand(p *projectOptions, backend api.Service) *cobra.Command {
7070
runCmd.Flags().IntVar(&opts.index, "index", 1, "index of the container if there are multiple instances of a service [default: 1].")
7171
runCmd.Flags().BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the process.")
7272
runCmd.Flags().StringVarP(&opts.user, "user", "u", "", "Run the command as this user.")
73-
runCmd.Flags().BoolVarP(&opts.noTty, "no-TTY", "T", notAtTTY(), "Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY.")
73+
runCmd.Flags().BoolVarP(&opts.noTty, "no-TTY", "T", false, "Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY.")
7474
runCmd.Flags().StringVarP(&opts.workingDir, "workdir", "w", "", "Path to workdir directory for this command.")
7575

7676
runCmd.Flags().SetInterspersed(false)

cmd/compose/run.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
cgo "github.com/compose-spec/compose-go/cli"
2626
"github.com/compose-spec/compose-go/loader"
2727
"github.com/compose-spec/compose-go/types"
28-
"github.com/mattn/go-isatty"
2928
"github.com/mattn/go-shellwords"
3029
"github.com/spf13/cobra"
3130
"github.com/spf13/pflag"
@@ -144,7 +143,7 @@ func runCommand(p *projectOptions, backend api.Service) *cobra.Command {
144143
flags.StringArrayVarP(&opts.environment, "env", "e", []string{}, "Set environment variables")
145144
flags.StringArrayVarP(&opts.labels, "label", "l", []string{}, "Add or override a label")
146145
flags.BoolVar(&opts.Remove, "rm", false, "Automatically remove the container when it exits")
147-
flags.BoolVarP(&opts.noTty, "no-TTY", "T", notAtTTY(), "Disable pseudo-noTty allocation. By default docker compose run allocates a TTY")
146+
flags.BoolVarP(&opts.noTty, "no-TTY", "T", false, "Disable pseudo-noTty allocation. By default docker compose run allocates a TTY")
148147
flags.StringVar(&opts.name, "name", "", " Assign a name to the container")
149148
flags.StringVarP(&opts.user, "user", "u", "", "Run as specified username or uid")
150149
flags.StringVarP(&opts.workdir, "workdir", "w", "", "Working directory inside the container")
@@ -171,11 +170,6 @@ func normalizeRunFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
171170
return pflag.NormalizedName(name)
172171
}
173172

174-
func notAtTTY() bool {
175-
b := isatty.IsTerminal(os.Stdout.Fd()) && isatty.IsTerminal(os.Stdin.Fd())
176-
return !b
177-
}
178-
179173
func runRun(ctx context.Context, backend api.Service, project *types.Project, opts runOptions) error {
180174
err := opts.apply(project)
181175
if err != nil {

pkg/e2e/networks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestNetworkModes(t *testing.T) {
122122
const projectName = "network_mode_service_run"
123123

124124
t.Run("run with service mode dependency", func(t *testing.T) {
125-
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/network-test/compose.yaml", "--project-name", projectName, "run", "mydb", "echo", "success")
125+
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/network-test/compose.yaml", "--project-name", projectName, "run", "-T", "mydb", "echo", "success")
126126
res.Assert(t, icmd.Expected{Out: "success"})
127127

128128
})

0 commit comments

Comments
 (0)