| 70 | ) |
| 71 | |
| 72 | func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, _ error) { |
| 73 | pruneFilters := command.PruneFilters(dockerCli, options.filter.Value()) |
| 74 | |
| 75 | warning := unusedVolumesWarning |
| 76 | if options.all { |
| 77 | if _, ok := pruneFilters["all"]; ok { |
| 78 | return 0, "", invalidParamErr{errors.New("conflicting options: cannot specify both --all and --filter all=1")} |
| 79 | } |
| 80 | pruneFilters.Add("all", "true") |
| 81 | warning = allVolumesWarning |
| 82 | } |
| 83 | if !options.force { |
| 84 | r, err := prompt.Confirm(ctx, dockerCli.In(), dockerCli.Out(), warning) |
| 85 | if err != nil { |
| 86 | return 0, "", err |
| 87 | } |
| 88 | if !r { |
| 89 | return 0, "", cancelledErr{errors.New("volume prune has been cancelled")} |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | res, err := dockerCli.Client().VolumePrune(ctx, client.VolumePruneOptions{ |
| 94 | Filters: pruneFilters, |
| 95 | }) |
| 96 | if err != nil { |
| 97 | return 0, "", err |
| 98 | } |
| 99 | |
| 100 | var out strings.Builder |
| 101 | if len(res.Report.VolumesDeleted) > 0 { |
| 102 | out.WriteString("Deleted Volumes:\n") |
| 103 | for _, id := range res.Report.VolumesDeleted { |
| 104 | out.WriteString(id + "\n") |
| 105 | } |
| 106 | spaceReclaimed = res.Report.SpaceReclaimed |
| 107 | } |
| 108 | |
| 109 | return spaceReclaimed, out.String(), nil |
| 110 | } |
| 111 | |
| 112 | type invalidParamErr struct{ error } |
| 113 | |