newPruneCommand returns a new cobra prune command for networks
(dockerCLI command.Cli)
| 29 | |
| 30 | // newPruneCommand returns a new cobra prune command for networks |
| 31 | func newPruneCommand(dockerCLI command.Cli) *cobra.Command { |
| 32 | options := pruneOptions{filter: opts.NewFilterOpt()} |
| 33 | |
| 34 | cmd := &cobra.Command{ |
| 35 | Use: "prune [OPTIONS]", |
| 36 | Short: "Remove all unused networks", |
| 37 | Args: cli.NoArgs, |
| 38 | RunE: func(cmd *cobra.Command, args []string) error { |
| 39 | output, err := runPrune(cmd.Context(), dockerCLI, options) |
| 40 | if err != nil { |
| 41 | return err |
| 42 | } |
| 43 | if output != "" { |
| 44 | _, _ = fmt.Fprintln(dockerCLI.Out(), output) |
| 45 | } |
| 46 | return nil |
| 47 | }, |
| 48 | Annotations: map[string]string{"version": "1.25"}, |
| 49 | DisableFlagsInUseLine: true, |
| 50 | } |
| 51 | |
| 52 | flags := cmd.Flags() |
| 53 | flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") |
| 54 | flags.Var(&options.filter, "filter", `Provide filter values (e.g. "until=<timestamp>")`) |
| 55 | |
| 56 | return cmd |
| 57 | } |
| 58 | |
| 59 | const warning = `WARNING! This will remove all custom networks not used by at least one container. |
| 60 | Are you sure you want to continue?` |
searching dependent graphs…