(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 42 | } |
| 43 | |
| 44 | func downCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 45 | opts := downOptions{ |
| 46 | ProjectOptions: p, |
| 47 | } |
| 48 | downCmd := &cobra.Command{ |
| 49 | Use: "down [OPTIONS] [SERVICES]", |
| 50 | Short: "Stop and remove containers, networks", |
| 51 | PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error { |
| 52 | opts.timeChanged = cmd.Flags().Changed("timeout") |
| 53 | if opts.images != "" { |
| 54 | if opts.images != "all" && opts.images != "local" { |
| 55 | return fmt.Errorf("invalid value for --rmi: %q", opts.images) |
| 56 | } |
| 57 | } |
| 58 | return nil |
| 59 | }), |
| 60 | RunE: Adapt(func(ctx context.Context, args []string) error { |
| 61 | return runDown(ctx, dockerCli, backendOptions, opts, args) |
| 62 | }), |
| 63 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 64 | } |
| 65 | flags := downCmd.Flags() |
| 66 | removeOrphans := utils.StringToBool(os.Getenv(ComposeRemoveOrphans)) |
| 67 | flags.BoolVar(&opts.removeOrphans, "remove-orphans", removeOrphans, "Remove containers for services not defined in the Compose file") |
| 68 | flags.IntVarP(&opts.timeout, "timeout", "t", 0, "Specify a shutdown timeout in seconds") |
| 69 | flags.BoolVarP(&opts.volumes, "volumes", "v", false, `Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers`) |
| 70 | flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`) |
| 71 | flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { |
| 72 | if name == "volume" { |
| 73 | name = "volumes" |
| 74 | logrus.Warn("--volume is deprecated, please use --volumes") |
| 75 | } |
| 76 | return pflag.NormalizedName(name) |
| 77 | }) |
| 78 | return downCmd |
| 79 | } |
| 80 | |
| 81 | func runDown(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts downOptions, services []string) error { |
| 82 | project, name, err := opts.projectOrName(ctx, dockerCli, services...) |
no test coverage detected