system prune: use register function for prune functions
Introduce a "prune" package in which we maintain a list of prune functions that are registered. Known prune "content-types" are included in a pre-defined order, after which additional content can be registered. Using this approach no longer requires the "RunPrune" functions to be exported, and allows additional content-types to be introduced without having to import those packages into the system package, so keeping things more decoupled. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/completion"
|
||||
"github.com/docker/cli/cli/command/system/pruner"
|
||||
"github.com/docker/cli/internal/prompt"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/go-units"
|
||||
@ -14,6 +15,13 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Register the prune command to run as part of "docker system prune"
|
||||
if err := pruner.Register(pruner.TypeContainer, pruneFn); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
type pruneOptions struct {
|
||||
force bool
|
||||
filter opts.FilterOpt
|
||||
@ -87,6 +95,17 @@ func (cancelledErr) Cancelled() {}
|
||||
|
||||
// RunPrune calls the Container Prune API
|
||||
// This returns the amount of space reclaimed and a detailed output string
|
||||
//
|
||||
// Deprecated: this function was only used internally and will be removed in the next release.
|
||||
func RunPrune(ctx context.Context, dockerCli command.Cli, _ bool, filter opts.FilterOpt) (uint64, string, error) {
|
||||
return runPrune(ctx, dockerCli, pruneOptions{force: true, filter: filter})
|
||||
}
|
||||
|
||||
// pruneFn calls the Container Prune API for use in "docker system prune",
|
||||
// and returns the amount of space reclaimed and a detailed output string.
|
||||
func pruneFn(ctx context.Context, dockerCLI command.Cli, options pruner.PruneOptions) (uint64, string, error) {
|
||||
return runPrune(ctx, dockerCLI, pruneOptions{
|
||||
force: true,
|
||||
filter: options.Filter,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user