cli/command/volume: use stdlib errors, remove errdefs uses

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-05-16 20:00:04 +02:00
parent 981e75e0f4
commit 1168edb259
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 16 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package volume
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"sort" "sort"
"strings" "strings"
@ -11,7 +12,6 @@ import (
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -52,7 +52,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 { if len(args) == 1 {
if options.name != "" { if options.name != "" {
return errors.Errorf("conflicting options: cannot specify a volume-name through both --name and as a positional arg") return errors.New("conflicting options: cannot specify a volume-name through both --name and as a positional arg")
} }
options.name = args[0] options.name = args[0]
} }

View File

@ -2,6 +2,7 @@ package volume
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
@ -10,9 +11,7 @@ import (
"github.com/docker/cli/internal/prompt" "github.com/docker/cli/internal/prompt"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs" "github.com/docker/go-units"
units "github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -68,7 +67,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
if versions.GreaterThanOrEqualTo(dockerCli.CurrentVersion(), "1.42") { if versions.GreaterThanOrEqualTo(dockerCli.CurrentVersion(), "1.42") {
if options.all { if options.all {
if pruneFilters.Contains("all") { if pruneFilters.Contains("all") {
return 0, "", errdefs.InvalidParameter(errors.New("conflicting options: cannot specify both --all and --filter all=1")) return 0, "", invalidParamErr{errors.New("conflicting options: cannot specify both --all and --filter all=1")}
} }
pruneFilters.Add("all", "true") pruneFilters.Add("all", "true")
warning = allVolumesWarning warning = allVolumesWarning
@ -83,7 +82,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
return 0, "", err return 0, "", err
} }
if !r { if !r {
return 0, "", errdefs.Cancelled(errors.New("volume prune has been cancelled")) return 0, "", cancelledErr{errors.New("volume prune has been cancelled")}
} }
} }
@ -103,6 +102,14 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
return spaceReclaimed, output, nil return spaceReclaimed, output, nil
} }
type invalidParamErr struct{ error }
func (invalidParamErr) InvalidParameter() {}
type cancelledErr struct{ error }
func (cancelledErr) Cancelled() {}
// RunPrune calls the Volume Prune API // RunPrune calls the Volume Prune API
// This returns the amount of space reclaimed and a detailed output string // This returns the amount of space reclaimed and a detailed output string
func RunPrune(ctx context.Context, dockerCli command.Cli, _ bool, filter opts.FilterOpt) (uint64, string, error) { func RunPrune(ctx context.Context, dockerCli command.Cli, _ bool, filter opts.FilterOpt) (uint64, string, error) {

View File

@ -2,12 +2,12 @@ package volume
import ( import (
"context" "context"
"errors"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -50,7 +50,7 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, volumeID, availabilit
} }
if vol.ClusterVolume == nil { if vol.ClusterVolume == nil {
return errors.New("Can only update cluster volumes") return errors.New("can only update cluster volumes")
} }
if flags.Changed("availability") { if flags.Changed("availability") {