Skip to content

Commit d7f0e29

Browse files
author
wryyyds7
committed
fix: allow -t flag to be used independently in compose run
Previously, -t (tty) was not available as a standalone flag in 'nerdctl compose run' — it was hardcoded to follow -i (interactive). This meant users could not allocate a TTY without also enabling STDIN, and any use of -t or --tty would result in 'unknown flag'. This change: - Adds a standalone -t/--tty flag to 'compose run' - Removes the restriction that StdinOpen and Tty must be equal - Allows -i and -t to be specified independently Ref: #1604 Signed-off-by: wryyyds7 <wry@code.alipay.com>
1 parent 4381782 commit d7f0e29

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

cmd/nerdctl/compose/compose_run.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func runCommand() *cobra.Command {
5151
cmd.Flags().Bool("no-deps", false, "Don't start dependencies")
5252
// TODO: no-TTY flag
5353
// In docker-compose's documentation, no-TTY is automatically detected
54-
// But, it follows `-i` flag because currently `run` command needs `-it` simultaneously.
5554
cmd.Flags().BoolP("interactive", "i", true, "Keep STDIN open even if not attached")
55+
cmd.Flags().BoolP("tty", "t", false, "Allocate a pseudo-TTY")
5656
cmd.Flags().Bool("rm", false, "Automatically remove the container when it exits")
5757
cmd.Flags().StringP("user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
5858
cmd.Flags().StringArrayP("volume", "v", nil, "Bind mount a volume")
@@ -119,8 +119,10 @@ func runAction(cmd *cobra.Command, args []string) error {
119119
if err != nil {
120120
return err
121121
}
122-
// FIXME : https://github.com/containerd/nerdctl/blob/v0.22.2/cmd/nerdctl/run.go#L100
123-
tty := interactive
122+
tty, err := cmd.Flags().GetBool("tty")
123+
if err != nil {
124+
return err
125+
}
124126
rm, err := cmd.Flags().GetBool("rm")
125127
if err != nil {
126128
return err

pkg/composer/up_service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ func (c *Composer) upServiceContainer(ctx context.Context, service *serviceparse
133133
return "", fmt.Errorf("error while checking for containers with name %q: %w", container.Name, err)
134134
}
135135

136-
// FIXME
137-
if service.Unparsed.StdinOpen != service.Unparsed.Tty {
138-
return "", fmt.Errorf("currently StdinOpen(-i) and Tty(-t) should be same")
139-
}
136+
// StdinOpen(-i) and Tty(-t) can be specified independently
140137

141138
var runFlagD bool
142139
if !service.Unparsed.StdinOpen && !service.Unparsed.Tty {

0 commit comments

Comments
 (0)