Skip to content

Commit

Permalink
cli/command/image: add shell completion for --platform flags
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thaJeztah committed Oct 8, 2024
1 parent 8c7f713 commit d42cf96
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/docker/cli-docs-tool/annotation"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/image/build"
"github.com/docker/cli/opts"
"github.com/docker/docker/api"
Expand Down Expand Up @@ -159,6 +160,8 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation("squash", "experimental", nil)
flags.SetAnnotation("squash", "version", []string{"1.25"})

_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)

return cmd
}

Expand Down
2 changes: 2 additions & 0 deletions cli/command/image/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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

return cmd
}
Expand Down
2 changes: 2 additions & 0 deletions cli/command/image/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command {
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())

_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)

return cmd
}

Expand Down
2 changes: 2 additions & 0 deletions cli/command/image/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Image index won't be pushed, meaning that other manifests, including attestation
'os[/arch[/variant]]': Explicit platform (eg. linux/amd64)`)
flags.SetAnnotation("platform", "version", []string{"1.46"})

_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)

return cmd
}

Expand Down

0 comments on commit d42cf96

Please sign in to comment.