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