Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 56b4c77

Browse files
authored
Merge pull request #833 from docker/add-run-rm
Add --rm to run command (as not yet implemented)
2 parents 511df55 + 69083e0 commit 56b4c77

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cli/cmd/run/run.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package run
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"os"
@@ -43,7 +44,7 @@ func Command(contextType string) *cobra.Command {
4344
if len(args) > 1 {
4445
opts.Command = args[1:]
4546
}
46-
return runRun(cmd.Context(), args[0], opts)
47+
return runRun(cmd.Context(), args[0], contextType, opts)
4748
},
4849
}
4950
cmd.Flags().SetInterspersed(false)
@@ -58,15 +59,22 @@ func Command(contextType string) *cobra.Command {
5859
cmd.Flags().StringArrayVarP(&opts.Environment, "env", "e", []string{}, "Set environment variables")
5960
cmd.Flags().StringArrayVar(&opts.EnvironmentFiles, "env-file", []string{}, "Path to environment files to be translated as environment variables")
6061
cmd.Flags().StringVarP(&opts.RestartPolicyCondition, "restart", "", containers.RestartPolicyNone, "Restart policy to apply when a container exits")
62+
cmd.Flags().BoolVar(&opts.Rm, "rm", false, "Automatically remove the container when it exits")
6163

6264
if contextType == store.AciContextType {
6365
cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
6466
}
6567

68+
_ = cmd.Flags().MarkHidden("rm")
69+
6670
return cmd
6771
}
6872

69-
func runRun(ctx context.Context, image string, opts run.Opts) error {
73+
func runRun(ctx context.Context, image string, contextType string, opts run.Opts) error {
74+
if opts.Rm {
75+
return errors.New(`Option "rm" is not yet implemented for context type: ` + contextType)
76+
}
77+
7078
c, err := client.New(ctx)
7179
if err != nil {
7280
return err

cli/options/run/opts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Opts struct {
4646
EnvironmentFiles []string
4747
RestartPolicyCondition string
4848
DomainName string
49+
Rm bool
4950
}
5051

5152
// ToContainerConfig convert run options to a container configuration

0 commit comments

Comments
 (0)