Skip to content

Commit 02141af

Browse files
committed
cli/command/image: use opts.PlatformSlice for image remove
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent fecbc3d commit 02141af

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

cli/command/image/remove.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import (
66
"fmt"
77

88
cerrdefs "github.com/containerd/errdefs"
9-
"github.com/containerd/platforms"
109
"github.com/docker/cli/cli"
1110
"github.com/docker/cli/cli/command"
1211
"github.com/docker/cli/cli/command/completion"
12+
"github.com/docker/cli/opts"
1313
"github.com/docker/docker/api/types/image"
14+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1415
"github.com/spf13/cobra"
1516
)
1617

1718
type removeOptions struct {
1819
force bool
1920
noPrune bool
20-
platforms []string
21+
platforms []ocispec.Platform
2122
}
2223

2324
// NewRemoveCommand creates a new `docker remove` command
@@ -42,8 +43,7 @@ func NewRemoveCommand(dockerCLI command.Cli) *cobra.Command {
4243
flags.BoolVarP(&options.force, "force", "f", false, "Force removal of the image")
4344
flags.BoolVar(&options.noPrune, "no-prune", false, "Do not delete untagged parents")
4445

45-
// TODO(thaJeztah): create a "platforms" option for this (including validation / parsing).
46-
flags.StringSliceVar(&options.platforms, "platform", nil, `Remove only the given platform variant. Formatted as "os[/arch[/variant]]" (e.g., "linux/amd64")`)
46+
flags.Var(opts.NewPlatformSlice(&options.platforms), "platform", `Remove only the given platform variant. Formatted as "os[/arch[/variant]]" (e.g., "linux/amd64")`)
4747
_ = flags.SetAnnotation("platform", "version", []string{"1.50"})
4848

4949
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
@@ -63,14 +63,7 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, i
6363
options := image.RemoveOptions{
6464
Force: opts.force,
6565
PruneChildren: !opts.noPrune,
66-
}
67-
68-
for _, v := range opts.platforms {
69-
p, err := platforms.Parse(v)
70-
if err != nil {
71-
return err
72-
}
73-
options.Platforms = append(options.Platforms, p)
66+
Platforms: opts.platforms,
7467
}
7568

7669
// TODO(thaJeztah): this logic can likely be simplified: do we want to print "not found" errors at all when using "force"?

docs/reference/commandline/image_rm.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Remove one or more images
99

1010
### Options
1111

12-
| Name | Type | Default | Description |
13-
|:--------------------------|:--------------|:--------|:-------------------------------------------------------------------------------------------------|
14-
| `-f`, `--force` | `bool` | | Force removal of the image |
15-
| `--no-prune` | `bool` | | Do not delete untagged parents |
16-
| [`--platform`](#platform) | `stringSlice` | | Remove only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`) |
12+
| Name | Type | Default | Description |
13+
|:--------------------------|:------------|:--------|:-------------------------------------------------------------------------------------------------|
14+
| `-f`, `--force` | `bool` | | Force removal of the image |
15+
| `--no-prune` | `bool` | | Do not delete untagged parents |
16+
| [`--platform`](#platform) | `platforms` | | Remove only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`) |
1717

1818

1919
<!---MARKER_GEN_END-->

docs/reference/commandline/rmi.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Remove one or more images
99

1010
### Options
1111

12-
| Name | Type | Default | Description |
13-
|:----------------|:--------------|:--------|:-------------------------------------------------------------------------------------------------|
14-
| `-f`, `--force` | `bool` | | Force removal of the image |
15-
| `--no-prune` | `bool` | | Do not delete untagged parents |
16-
| `--platform` | `stringSlice` | | Remove only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`) |
12+
| Name | Type | Default | Description |
13+
|:----------------|:------------|:--------|:-------------------------------------------------------------------------------------------------|
14+
| `-f`, `--force` | `bool` | | Force removal of the image |
15+
| `--no-prune` | `bool` | | Do not delete untagged parents |
16+
| `--platform` | `platforms` | | Remove only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`) |
1717

1818

1919
<!---MARKER_GEN_END-->

0 commit comments

Comments
 (0)