Skip to content

Commit d42cf96

Browse files
committed
cli/command/image: add shell completion for --platform flags
With this patch, completion is provided for `--platform` flags: docker pull --platform<TAB> linux linux/amd64 linux/arm/v5 linux/arm/v7 linux/arm64/v8 linux/riscv64 wasip1 windows linux/386 linux/arm linux/arm/v6 linux/arm64 linux/ppc64le linux/s390x wasip1/wasm windows/amd64 Note that `docker buildx build` (with BuildKit) does not yet provide completion; it's provided through buildx, and uses a different format (accepting multiple comma-separated platforms). Interestingly, tab-completion for `docker build` currently uses completion for non-buildkit, and has some other issues that may have to be looked into. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8c7f713 commit d42cf96

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

cli/command/image/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/docker/cli-docs-tool/annotation"
1919
"github.com/docker/cli/cli"
2020
"github.com/docker/cli/cli/command"
21+
"github.com/docker/cli/cli/command/completion"
2122
"github.com/docker/cli/cli/command/image/build"
2223
"github.com/docker/cli/opts"
2324
"github.com/docker/docker/api"
@@ -159,6 +160,8 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
159160
flags.SetAnnotation("squash", "experimental", nil)
160161
flags.SetAnnotation("squash", "version", []string{"1.25"})
161162

163+
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
164+
162165
return cmd
163166
}
164167

cli/command/image/import.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
10+
"github.com/docker/cli/cli/command/completion"
1011
dockeropts "github.com/docker/cli/opts"
1112
"github.com/docker/docker/api/types/image"
1213
"github.com/docker/docker/pkg/jsonmessage"
@@ -47,6 +48,7 @@ func NewImportCommand(dockerCli command.Cli) *cobra.Command {
4748
flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
4849
flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image")
4950
command.AddPlatformFlag(flags, &options.platform)
51+
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
5052

5153
return cmd
5254
}

cli/command/image/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command {
5050
command.AddPlatformFlag(flags, &opts.platform)
5151
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
5252

53+
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
54+
5355
return cmd
5456
}
5557

cli/command/image/push.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Image index won't be pushed, meaning that other manifests, including attestation
6868
'os[/arch[/variant]]': Explicit platform (eg. linux/amd64)`)
6969
flags.SetAnnotation("platform", "version", []string{"1.46"})
7070

71+
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
72+
7173
return cmd
7274
}
7375

0 commit comments

Comments
 (0)