diff --git a/cmd/compose/exec.go b/cmd/compose/exec.go index 231691563..a978b65ff 100644 --- a/cmd/compose/exec.go +++ b/cmd/compose/exec.go @@ -29,6 +29,7 @@ import ( "github.com/docker/compose/v2/pkg/compose" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/spf13/pflag" ) type execOpts struct { @@ -81,7 +82,7 @@ func execCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) runCmd.Flags().IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas") runCmd.Flags().BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the process") runCmd.Flags().StringVarP(&opts.user, "user", "u", "", "Run the command as this user") - runCmd.Flags().BoolVarP(&opts.noTty, "no-TTY", "T", !dockerCli.Out().IsTerminal(), "Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY.") + runCmd.Flags().BoolVarP(&opts.noTty, "no-tty", "T", !dockerCli.Out().IsTerminal(), "Disable pseudo-TTY allocation. By default `docker compose exec` allocates a TTY.") runCmd.Flags().StringVarP(&opts.workingDir, "workdir", "w", "", "Path to workdir directory for this command") runCmd.Flags().BoolVarP(&opts.interactive, "interactive", "i", true, "Keep STDIN open even if not attached") @@ -90,6 +91,12 @@ func execCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) runCmd.Flags().MarkHidden("tty") //nolint:errcheck runCmd.Flags().SetInterspersed(false) + runCmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { + if name == "no-TTY" { // legacy + name = "no-tty" + } + return pflag.NormalizedName(name) + }) return runCmd }