Skip to content

Commit 1fd9d0d

Browse files
committed
cli/command/manifest: pass manifest-store and handle context
- pass through the manifest-store, instead of the CLI as a whole - handle context cancellation - rename `runRm` to `runRemove` to align with other commands Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent f431f61 commit 1fd9d0d

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

  • cli/command/manifest

cli/command/manifest/rm.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,43 @@ import (
66

77
"github.com/docker/cli/cli"
88
"github.com/docker/cli/cli/command"
9+
manifeststore "github.com/docker/cli/cli/manifest/store"
910
"github.com/pkg/errors"
1011
"github.com/spf13/cobra"
1112
)
1213

13-
func newRmManifestListCommand(dockerCli command.Cli) *cobra.Command {
14+
func newRmManifestListCommand(dockerCLI command.Cli) *cobra.Command {
1415
cmd := &cobra.Command{
1516
Use: "rm MANIFEST_LIST [MANIFEST_LIST...]",
1617
Short: "Delete one or more manifest lists from local storage",
1718
Args: cli.RequiresMinArgs(1),
1819
RunE: func(cmd *cobra.Command, args []string) error {
19-
return runRm(cmd.Context(), dockerCli, args)
20+
return runRemove(cmd.Context(), dockerCLI.ManifestStore(), args)
2021
},
2122
}
2223

2324
return cmd
2425
}
2526

26-
func runRm(_ context.Context, dockerCli command.Cli, targets []string) error {
27+
func runRemove(ctx context.Context, store manifeststore.Store, targets []string) error {
2728
var errs []string
2829
for _, target := range targets {
29-
targetRef, refErr := normalizeReference(target)
30-
if refErr != nil {
31-
errs = append(errs, refErr.Error())
30+
if ctx.Err() != nil {
31+
return ctx.Err()
32+
}
33+
targetRef, err := normalizeReference(target)
34+
if err != nil {
35+
errs = append(errs, err.Error())
3236
continue
3337
}
34-
_, searchErr := dockerCli.ManifestStore().GetList(targetRef)
35-
if searchErr != nil {
36-
errs = append(errs, searchErr.Error())
38+
_, err = store.GetList(targetRef)
39+
if err != nil {
40+
errs = append(errs, err.Error())
3741
continue
3842
}
39-
rmErr := dockerCli.ManifestStore().Remove(targetRef)
40-
if rmErr != nil {
41-
errs = append(errs, rmErr.Error())
43+
err = store.Remove(targetRef)
44+
if err != nil {
45+
errs = append(errs, err.Error())
4246
}
4347
}
4448
if len(errs) > 0 {

0 commit comments

Comments
 (0)