Skip to content

Commit

Permalink
ctr/run: flags --detach and --rm cannot be specified together
Browse files Browse the repository at this point in the history
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
(cherry picked from commit 0b9313c)
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
  • Loading branch information
Iceber committed Feb 13, 2023
1 parent 839086b commit 2b4b35a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/ctr/commands/run/run.go
Expand Up @@ -97,7 +97,7 @@ var Command = cli.Command{
Flags: append([]cli.Flag{
cli.BoolFlag{
Name: "rm",
Usage: "remove the container after running",
Usage: "remove the container after running, cannot be used with --detach",
},
cli.BoolFlag{
Name: "null-io",
Expand All @@ -109,7 +109,7 @@ var Command = cli.Command{
},
cli.BoolFlag{
Name: "detach,d",
Usage: "detach from the task after it has started execution",
Usage: "detach from the task after it has started execution, cannot be used with --rm",
},
cli.StringFlag{
Name: "fifo-dir",
Expand All @@ -136,6 +136,7 @@ var Command = cli.Command{
id string
ref string

rm = context.Bool("rm")
tty = context.Bool("tty")
detach = context.Bool("detach")
config = context.IsSet("config")
Expand All @@ -158,6 +159,10 @@ var Command = cli.Command{
if id == "" {
return errors.New("container id must be provided")
}
if rm && detach {
return errors.New("flags --detach and --rm cannot be specified together")
}

client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
Expand All @@ -167,7 +172,7 @@ var Command = cli.Command{
if err != nil {
return err
}
if context.Bool("rm") && !detach {
if rm && !detach {
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
}
var con console.Console
Expand Down

0 comments on commit 2b4b35a

Please sign in to comment.