MCPcopy Index your code
hub / github.com/docker/cli / runPrune

Function runPrune

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

Source from the content-addressed store, hash-verified

63Are you sure you want to continue?`
64
65func 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
97type cancelledErr struct{ error }
98

Callers 2

newPruneCommandFunction · 0.70
pruneFnFunction · 0.70

Calls 6

ValueMethod · 0.65
InMethod · 0.65
OutMethod · 0.65
ClientMethod · 0.65
StringMethod · 0.65
ContainerPruneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…