MCPcopy Create free account
hub / github.com/docker/cli / runPrune

Function runPrune

cli/command/volume/prune.go:72–110  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, options pruneOptions)

Source from the content-addressed store, hash-verified

70)
71
72func 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
112type invalidParamErr struct{ error }
113

Callers 2

newPruneCommandFunction · 0.70
pruneFnFunction · 0.70

Calls 6

VolumePruneMethod · 0.80
ValueMethod · 0.65
InMethod · 0.65
OutMethod · 0.65
ClientMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…