Skip to content

Commit

Permalink
update system prune flag --all confirm tooltip
Browse files Browse the repository at this point in the history
Signed-off-by: Han Xu <suyanhanx@gmail.com>
  • Loading branch information
suyanhanx committed Feb 23, 2023
1 parent 17b6166 commit c03d691
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
19 changes: 9 additions & 10 deletions cmd/nerdctl/system_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/clientutil"
"github.com/containerd/nerdctl/pkg/cmd/system"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -80,12 +79,6 @@ func grantSystemPrunePermission(cmd *cobra.Command, options types.SystemPruneOpt
return false, err
}

if !options.All {
logrus.Warn("Currently, `nerdctl system prune` requires --all to be specified. Skip pruning.")
// NOP
return false, nil
}

if !force {
var confirm string
msg := `This will remove:
Expand All @@ -95,10 +88,16 @@ func grantSystemPrunePermission(cmd *cobra.Command, options types.SystemPruneOpt
msg += `
- all volumes not used by at least one container`
}
msg += `
if options.All {
msg += `
- all images without at least one container associated to them
- all build cache
`
- all build cache`
} else {
msg += `
- all dangling images
- all dangling build cache`
}

msg += "\nAre you sure you want to continue? [y/N] "
fmt.Fprintf(options.Stdout, "WARNING! %s", msg)
fmt.Fscanf(cmd.InOrStdin(), "%s", &confirm)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/types/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ type BuilderBuildOptions struct {
BuildContext string
}

// BuilderPruneOptions specifies options for `nerdctl builder build`.
// BuilderPruneOptions specifies options for `nerdctl builder prune`.
type BuilderPruneOptions struct {
Stderr io.Writer
// GOptions is the global options
GOptions GlobalCommandOptions
// BuildKitHost is the buildkit host
BuildKitHost string
// All will remove all unused build cache, not just dangling ones
// All will remove all unused images and all build cache, not just dangling ones
All bool
}
2 changes: 1 addition & 1 deletion pkg/cmd/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Prune(ctx context.Context, client *containerd.Client, options types.SystemP
if err := image.Prune(ctx, client, types.ImagePruneOptions{
Stdout: options.Stdout,
GOptions: options.GOptions,
All: true,
All: options.All,
}); err != nil {
return nil
}
Expand Down

0 comments on commit c03d691

Please sign in to comment.