chore: remove prompt error type · docker/cli@fb48fb2 · GitHub
Skip to content

Commit fb48fb2

Browse files
committed
chore: remove prompt error type
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent b35fa5a commit fb48fb2

12 files changed

Lines changed: 30 additions & 25 deletions

File tree

‎cli/command/builder/prune.go‎

Lines changed: 3 additions & 1 deletion

‎cli/command/container/prune.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/cli/command/completion"
1010
"github.com/docker/cli/opts"
11+
"github.com/docker/docker/errdefs"
1112
units "github.com/docker/go-units"
13+
"github.com/pkg/errors"
1214
"github.com/spf13/cobra"
1315
)
1416

@@ -59,7 +61,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
5961
return 0, "", err
6062
}
6163
if !r {
62-
return 0, "", command.ErrUserCancelledOperation
64+
return 0, "", errdefs.Cancelled(errors.New("`container prune` has been cancelled"))
6365
}
6466
}
6567

‎cli/command/image/prune.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"github.com/docker/cli/cli/command"
1111
"github.com/docker/cli/cli/command/completion"
1212
"github.com/docker/cli/opts"
13+
"github.com/docker/docker/errdefs"
1314
units "github.com/docker/go-units"
15+
"github.com/pkg/errors"
1416
"github.com/spf13/cobra"
1517
)
1618

@@ -73,7 +75,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
7375
return 0, "", err
7476
}
7577
if !r {
76-
return 0, "", command.ErrUserCancelledOperation
78+
return 0, "", errdefs.Cancelled(errors.New("`image prune` has been cancelled"))
7779
}
7880
}
7981

‎cli/command/network/prune.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/docker/cli/cli"
88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/opts"
10+
"github.com/docker/docker/errdefs"
11+
"github.com/pkg/errors"
1012
"github.com/spf13/cobra"
1113
)
1214

@@ -55,7 +57,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
5557
return "", err
5658
}
5759
if !r {
58-
return "", command.ErrUserCancelledOperation
60+
return "", errdefs.Cancelled(errors.New("`network prune` cancelled has been cancelled"))
5961
}
6062
}
6163

‎cli/command/plugin/upgrade.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/distribution/reference"
99
"github.com/docker/cli/cli"
1010
"github.com/docker/cli/cli/command"
11+
"github.com/docker/docker/errdefs"
1112
"github.com/docker/docker/pkg/jsonmessage"
1213
"github.com/pkg/errors"
1314
"github.com/spf13/cobra"
@@ -68,7 +69,7 @@ func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions)
6869
return err
6970
}
7071
if !r {
71-
return command.ErrUserCancelledOperation
72+
return errdefs.Cancelled(errors.New("`plugin upgrade` has been cancelled"))
7273
}
7374
}
7475

‎cli/command/system/prune.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"github.com/docker/cli/cli/command/volume"
1818
"github.com/docker/cli/opts"
1919
"github.com/docker/docker/api/types/versions"
20+
"github.com/docker/docker/errdefs"
2021
"github.com/docker/go-units"
2122
"github.com/fvbommel/sortorder"
23+
"github.com/pkg/errors"
2224
"github.com/spf13/cobra"
2325
)
2426

@@ -80,7 +82,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
8082
return err
8183
}
8284
if !r {
83-
return command.ErrUserCancelledOperation
85+
return errdefs.Cancelled(errors.New("`system prune` has been cancelled"))
8486
}
8587
}
8688
pruneFuncs := []func(ctx context.Context, dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error){

‎cli/command/system/prune_test.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/docker/cli/cli/command"
87
"github.com/docker/cli/cli/config/configfile"
98
"github.com/docker/cli/internal/test"
109
"github.com/docker/docker/api/types"
@@ -18,7 +17,7 @@ func TestPrunePromptPre131DoesNotIncludeBuildCache(t *testing.T) {
1817
cli := test.NewFakeCli(&fakeClient{version: "1.30"})
1918
cmd := newPruneCommand(cli)
2019
cmd.SetArgs([]string{})
21-
assert.ErrorIs(t, cmd.Execute(), command.ErrUserCancelledOperation)
20+
assert.ErrorContains(t, cmd.Execute(), "`system prune` has been cancelled")
2221
expected := `WARNING! This will remove:
2322
- all stopped containers
2423
- all networks not used by at least one container
@@ -36,7 +35,7 @@ func TestPrunePromptFilters(t *testing.T) {
3635
cmd := newPruneCommand(cli)
3736
cmd.SetArgs([]string{"--filter", "until=24h", "--filter", "label=hello-world", "--filter", "label!=foo=bar", "--filter", "label=bar=baz"})
3837

39-
assert.ErrorIs(t, cmd.Execute(), command.ErrUserCancelledOperation)
38+
assert.ErrorContains(t, cmd.Execute(), "`system prune` has been cancelled")
4039
expected := `WARNING! This will remove:
4140
- all stopped containers
4241
- all networks not used by at least one container

‎cli/command/trust/revoke.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/cli/command/image"
1010
"github.com/docker/cli/cli/trust"
11+
"github.com/docker/docker/errdefs"
1112
"github.com/pkg/errors"
1213
"github.com/spf13/cobra"
1314
"github.com/theupdateframework/notary/client"
@@ -48,7 +49,7 @@ func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, opti
4849
return err
4950
}
5051
if !deleteRemote {
51-
return command.ErrUserCancelledOperation
52+
return errdefs.Cancelled(errors.New("`trust revoke` has been cancelled"))
5253
}
5354
}
5455

‎cli/command/trust/revoke_test.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66
"testing"
77

8-
"github.com/docker/cli/cli/command"
98
"github.com/docker/cli/cli/trust"
109
"github.com/docker/cli/internal/test"
1110
"github.com/docker/cli/internal/test/notary"
@@ -58,6 +57,8 @@ func TestTrustRevokeCommandErrors(t *testing.T) {
5857
}
5958

6059
func TestTrustRevokeCommand(t *testing.T) {
60+
revokeCancelledError := "`trust revoke` has been cancelled"
61+
6162
testCases := []struct {
6263
doc string
6364
notaryRepository func(trust.ImageRefAndAuth, []string) (client.Repository, error)
@@ -70,7 +71,7 @@ func TestTrustRevokeCommand(t *testing.T) {
7071
notaryRepository: notary.GetOfflineNotaryRepository,
7172
args: []string{"reg-name.io/image"},
7273
expectedMessage: "Please confirm you would like to delete all signature data for reg-name.io/image? [y/N] ",
73-
expectedErr: command.ErrUserCancelledOperation.Error(),
74+
expectedErr: revokeCancelledError,
7475
},
7576
{
7677
doc: "OfflineErrors_Offline",
@@ -89,7 +90,7 @@ func TestTrustRevokeCommand(t *testing.T) {
8990
notaryRepository: notary.GetUninitializedNotaryRepository,
9091
args: []string{"reg-name.io/image"},
9192
expectedMessage: "Please confirm you would like to delete all signature data for reg-name.io/image? [y/N] ",
92-
expectedErr: command.ErrUserCancelledOperation.Error(),
93+
expectedErr: revokeCancelledError,
9394
},
9495
{
9596
doc: "UninitializedErrors_NoTrustData",
@@ -108,7 +109,7 @@ func TestTrustRevokeCommand(t *testing.T) {
108109
notaryRepository: notary.GetEmptyTargetsNotaryRepository,
109110
args: []string{"reg-name.io/image"},
110111
expectedMessage: "Please confirm you would like to delete all signature data for reg-name.io/image? [y/N] ",
111-
expectedErr: command.ErrUserCancelledOperation.Error(),
112+
expectedErr: revokeCancelledError,
112113
},
113114
{
114115
doc: "EmptyNotaryRepo_NoSignedTags",
@@ -127,7 +128,7 @@ func TestTrustRevokeCommand(t *testing.T) {
127128
notaryRepository: notary.GetEmptyTargetsNotaryRepository,
128129
args: []string{"alpine"},
129130
expectedMessage: "Please confirm you would like to delete all signature data for alpine? [y/N] ",
130-
expectedErr: command.ErrUserCancelledOperation.Error(),
131+
expectedErr: revokeCancelledError,
131132
},
132133
}
133134

‎cli/command/utils.go‎

Lines changed: 1 addition & 6 deletions

0 commit comments

Comments
 (0)