| 60 | Are you sure you want to continue?` |
| 61 | |
| 62 | func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (output string, _ error) { |
| 63 | pruneFilters := command.PruneFilters(dockerCli, options.filter.Value()) |
| 64 | |
| 65 | if !options.force { |
| 66 | r, err := prompt.Confirm(ctx, dockerCli.In(), dockerCli.Out(), warning) |
| 67 | if err != nil { |
| 68 | return "", err |
| 69 | } |
| 70 | if !r { |
| 71 | return "", cancelledErr{errors.New("network prune has been cancelled")} |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | res, err := dockerCli.Client().NetworkPrune(ctx, client.NetworkPruneOptions{ |
| 76 | Filters: pruneFilters, |
| 77 | }) |
| 78 | if err != nil { |
| 79 | return "", err |
| 80 | } |
| 81 | |
| 82 | var out strings.Builder |
| 83 | if len(res.Report.NetworksDeleted) > 0 { |
| 84 | out.WriteString("Deleted Networks:\n") |
| 85 | for _, id := range res.Report.NetworksDeleted { |
| 86 | out.WriteString(id + "\n") |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return out.String(), nil |
| 91 | } |
| 92 | |
| 93 | type cancelledErr struct{ error } |
| 94 | |