remove tty attribute from run options and use dedicated variable to avoid confusion

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2025-09-18 15:28:00 +02:00
parent a429c09dfa
commit da72230c39

View File

@ -50,7 +50,6 @@ type runOptions struct {
Detach bool Detach bool
Remove bool Remove bool
noTty bool noTty bool
tty bool
interactive bool interactive bool
user string user string
workdir string workdir string
@ -155,6 +154,10 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
buildOpts := buildOptions{ buildOpts := buildOptions{
ProjectOptions: p, ProjectOptions: p,
} }
// We remove the attribute from the option struct and use a dedicated var, to limit confusion and avoid anyone to use options.tty.
// The tty flag is here for convenience and let user do "docker compose run -it" the same way as they use the "docker run" command.
var ttyFlag bool
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "run [OPTIONS] SERVICE [COMMAND] [ARGS...]", Use: "run [OPTIONS] SERVICE [COMMAND] [ARGS...]",
Short: "Run a one-off command on a service", Short: "Run a one-off command on a service",
@ -178,7 +181,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
if cmd.Flags().Changed("no-TTY") { if cmd.Flags().Changed("no-TTY") {
return fmt.Errorf("--tty and --no-TTY can't be used together") return fmt.Errorf("--tty and --no-TTY can't be used together")
} else { } else {
options.noTty = !options.tty options.noTty = !ttyFlag
} }
} }
if options.quiet { if options.quiet {
@ -238,7 +241,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file")
cmd.Flags().BoolVarP(&options.interactive, "interactive", "i", true, "Keep STDIN open even if not attached") cmd.Flags().BoolVarP(&options.interactive, "interactive", "i", true, "Keep STDIN open even if not attached")
cmd.Flags().BoolVarP(&options.tty, "tty", "t", true, "Allocate a pseudo-TTY") cmd.Flags().BoolVarP(&ttyFlag, "tty", "t", true, "Allocate a pseudo-TTY")
cmd.Flags().MarkHidden("tty") //nolint:errcheck cmd.Flags().MarkHidden("tty") //nolint:errcheck
flags.SetNormalizeFunc(normalizeRunFlags) flags.SetNormalizeFunc(normalizeRunFlags)