Skip to content

Commit 0b9313c

Browse files
committed
ctr/run: flags --detach and --rm cannot be specified together
Signed-off-by: Iceber Gu <[email protected]>
1 parent 9bfe1d9 commit 0b9313c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

cmd/ctr/commands/run/run.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var Command = cli.Command{
9393
Flags: append([]cli.Flag{
9494
cli.BoolFlag{
9595
Name: "rm",
96-
Usage: "remove the container after running",
96+
Usage: "remove the container after running, cannot be used with --detach",
9797
},
9898
cli.BoolFlag{
9999
Name: "null-io",
@@ -105,7 +105,7 @@ var Command = cli.Command{
105105
},
106106
cli.BoolFlag{
107107
Name: "detach,d",
108-
Usage: "detach from the task after it has started execution",
108+
Usage: "detach from the task after it has started execution, cannot be used with --rm",
109109
},
110110
cli.StringFlag{
111111
Name: "fifo-dir",
@@ -132,6 +132,7 @@ var Command = cli.Command{
132132
id string
133133
ref string
134134

135+
rm = context.Bool("rm")
135136
tty = context.Bool("tty")
136137
detach = context.Bool("detach")
137138
config = context.IsSet("config")
@@ -154,6 +155,10 @@ var Command = cli.Command{
154155
if id == "" {
155156
return errors.New("container id must be provided")
156157
}
158+
if rm && detach {
159+
return errors.New("flags --detach and --rm cannot be specified together")
160+
}
161+
157162
client, ctx, cancel, err := commands.NewClient(context)
158163
if err != nil {
159164
return err
@@ -163,7 +168,7 @@ var Command = cli.Command{
163168
if err != nil {
164169
return err
165170
}
166-
if context.Bool("rm") && !detach {
171+
if rm && !detach {
167172
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
168173
}
169174
var con console.Console

0 commit comments

Comments
 (0)