Skip to content

Commit

Permalink
Subcommand docker manifest rm
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit b9ef85e
Author: Jennings Zhang <[email protected]>
Date:   Mon Sep 14 21:39:57 2020 -0400

    Fix bash completion

    #2449 (review)
    Signed-off-by: Jennings Zhang <[email protected]>

commit 8c46bd6
Author: Jennings Zhang <[email protected]>
Date:   Sun Sep 13 01:48:12 2020 -0400

    Add tests for docker manifest rm

    Signed-off-by: Jennings Zhang <[email protected]>

commit 7e3d9a9
Author: Jennings Zhang <[email protected]>
Date:   Sun Sep 13 00:55:37 2020 -0400

    docker manifest rm multiple args

    Signed-off-by: Jennings Zhang <[email protected]>

commit 30466e2
Author: Jennings Zhang <[email protected]>
Date:   Sun Sep 13 00:01:20 2020 -0400

    No need to search before Remove

    #2449 (comment)
    Signed-off-by: Jennings Zhang <[email protected]>

commit ccdc4ed
Author: Jennings Zhang <[email protected]>
Date:   Sat Sep 12 23:42:41 2020 -0400

    Completion should also handle --help

    #2449 (comment)
    Signed-off-by: Jennings Zhang <[email protected]>

commit ed260af
Merge: 46c61d8 2955ece
Author: Jennings Zhang <[email protected]>
Date:   Sat Sep 12 23:31:54 2020 -0400

    Merge branch 'master' into manifest-rm

commit 46c61d8
Author: Jennings Zhang <[email protected]>
Date:   Fri Apr 17 21:53:33 2020 -0400

    Remove extra space

    Signed-off-by: Jennings Zhang <[email protected]>

commit 6d31d26
Author: Jennings Zhang <[email protected]>
Date:   Fri Apr 17 21:15:21 2020 -0400

    Bash completion for `docker manifest rm`

    Signed-off-by: Jennings Zhang <[email protected]>

commit 3c8c843
Author: Jennings Zhang <[email protected]>
Date:   Fri Apr 17 21:05:50 2020 -0400

    Frankenstein a `docker manifest rm` command

    Signed-off-by: Jennings Zhang <[email protected]>

Signed-off-by: Jennings Zhang <[email protected]>
  • Loading branch information
jennydaman committed Sep 15, 2020
1 parent 2955ece commit 29dcc37
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/command/manifest/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewManifestCommand(dockerCli command.Cli) *cobra.Command {
newInspectCommand(dockerCli),
newAnnotateCommand(dockerCli),
newPushListCommand(dockerCli),
newRmManifestListCommand(dockerCli),
)
return cmd
}
Expand Down
47 changes: 47 additions & 0 deletions cli/command/manifest/rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package manifest

import (
"strings"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func newRmManifestListCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "rm MANIFEST_LIST [MANIFEST_LIST...]",
Short: "Delete one or more manifest lists from local storage",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runRm(dockerCli, args)
},
}

return cmd
}

func runRm(dockerCli command.Cli, targets []string) error {
var errs []string
for _, target := range targets {
targetRef, refErr := normalizeReference(target)
if refErr != nil {
errs = append(errs, refErr.Error())
continue
}
_, searchErr := dockerCli.ManifestStore().GetList(targetRef)
if searchErr != nil {
errs = append(errs, searchErr.Error())
continue
}
rmErr := dockerCli.ManifestStore().Remove(targetRef)
if rmErr != nil {
errs = append(errs, rmErr.Error())
}
}
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
}
return nil
}
65 changes: 65 additions & 0 deletions cli/command/manifest/rm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package manifest

import (
"io/ioutil"
"testing"

"github.com/docker/cli/internal/test"
"gotest.tools/v3/assert"
)

// create two manifest lists and remove them both
func TestRmSeveralManifests(t *testing.T) {
store, cleanup := newTempManifestStore(t)
defer cleanup()

cli := test.NewFakeCli(nil)
cli.SetManifestStore(store)

list1 := ref(t, "first:1")
namedRef := ref(t, "alpine:3.0")
err := store.Save(list1, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)
namedRef = ref(t, "alpine:3.1")
err = store.Save(list1, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)

list2 := ref(t, "second:2")
namedRef = ref(t, "alpine:3.2")
err = store.Save(list2, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)

cmd := newRmManifestListCommand(cli)
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
cmd.SetOut(ioutil.Discard)
err = cmd.Execute()
assert.NilError(t, err)

_, search1 := cli.ManifestStore().GetList(list1)
_, search2 := cli.ManifestStore().GetList(list2)
assert.Error(t, search1, "No such manifest: example.com/first:1")
assert.Error(t, search2, "No such manifest: example.com/second:2")
}

// attempt to remove a manifest list which was never created
func TestRmManifestNotCreated(t *testing.T) {
store, cleanup := newTempManifestStore(t)
defer cleanup()

cli := test.NewFakeCli(nil)
cli.SetManifestStore(store)

list2 := ref(t, "second:2")
namedRef := ref(t, "alpine:3.2")
err := store.Save(list2, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)

cmd := newRmManifestListCommand(cli)
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
cmd.SetOut(ioutil.Discard)
err = cmd.Execute()
assert.Error(t, err, "No such manifest: example.com/first:1")

_, err = cli.ManifestStore().GetList(list2)
assert.Error(t, err, "No such manifest: example.com/second:2")
}
12 changes: 12 additions & 0 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -4128,6 +4128,7 @@ _docker_manifest() {
create
inspect
push
rm
"
__docker_subcommands "$subcommands" && return

Expand Down Expand Up @@ -4226,6 +4227,17 @@ _docker_manifest_push() {
esac
}

_docker_network_rm() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_complete_images --force-tag --id
;;
esac
}

_docker_node() {
local subcommands="
demote
Expand Down

0 comments on commit 29dcc37

Please sign in to comment.