mirror of https://github.com/docker/cli.git
Merge pull request #6311 from thaJeztah/28.x_backport_deprecate_platform_flags
[28.x backport] cli/command: remove `AddTrustSigningFlags`, `AddTrustVerificationFlags`, `AddPlatformFlag` utilities
This commit is contained in:
commit
acb019a344
|
|
@ -86,8 +86,11 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
// with hostname
|
// with hostname
|
||||||
flags.Bool("help", false, "Print usage")
|
flags.Bool("help", false, "Print usage")
|
||||||
|
|
||||||
command.AddPlatformFlag(flags, &options.platform)
|
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
|
||||||
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
|
addPlatformFlag(flags, &options.platform)
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
|
||||||
|
|
||||||
|
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
|
||||||
copts = addFlags(flags)
|
copts = addFlags(flags)
|
||||||
|
|
||||||
addCompletions(cmd, dockerCli)
|
addCompletions(cmd, dockerCli)
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,16 @@ type containerOptions struct {
|
||||||
Args []string
|
Args []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addPlatformFlag adds "--platform" to a set of flags for API version 1.32 and
|
||||||
|
// later, using the value of "DOCKER_DEFAULT_PLATFORM" (if set) as a default.
|
||||||
|
//
|
||||||
|
// It should not be used for new uses, which may have a different API version
|
||||||
|
// requirement.
|
||||||
|
func addPlatformFlag(flags *pflag.FlagSet, target *string) {
|
||||||
|
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
||||||
|
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
|
||||||
|
}
|
||||||
|
|
||||||
// addFlags adds all command line flags that will be used by parse to the FlagSet
|
// addFlags adds all command line flags that will be used by parse to the FlagSet
|
||||||
func addFlags(flags *pflag.FlagSet) *containerOptions {
|
func addFlags(flags *pflag.FlagSet) *containerOptions {
|
||||||
copts := &containerOptions{
|
copts := &containerOptions{
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,9 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
// with hostname
|
// with hostname
|
||||||
flags.Bool("help", false, "Print usage")
|
flags.Bool("help", false, "Print usage")
|
||||||
|
|
||||||
command.AddPlatformFlag(flags, &options.platform)
|
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
|
||||||
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
|
addPlatformFlag(flags, &options.platform)
|
||||||
|
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
|
||||||
copts = addFlags(flags)
|
copts = addFlags(flags)
|
||||||
|
|
||||||
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)
|
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
|
flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
|
||||||
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
|
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
|
||||||
|
|
||||||
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
|
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
|
||||||
|
|
||||||
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
||||||
flags.SetAnnotation("platform", "version", []string{"1.38"})
|
flags.SetAnnotation("platform", "version", []string{"1.38"})
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func NewImportCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
options.changes = dockeropts.NewListOpts(nil)
|
options.changes = dockeropts.NewListOpts(nil)
|
||||||
flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
|
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")
|
flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image")
|
||||||
command.AddPlatformFlag(flags, &options.platform)
|
addPlatformFlag(flags, &options.platform)
|
||||||
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
|
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
// addPlatformFlag adds "--platform" to a set of flags for API version 1.32 and
|
||||||
|
// later, using the value of "DOCKER_DEFAULT_PLATFORM" (if set) as a default.
|
||||||
|
//
|
||||||
|
// It should not be used for new uses, which may have a different API version
|
||||||
|
// requirement.
|
||||||
|
func addPlatformFlag(flags *pflag.FlagSet, target *string) {
|
||||||
|
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
||||||
|
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
|
||||||
|
}
|
||||||
|
|
@ -50,8 +50,8 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
|
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
|
||||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
|
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
|
||||||
|
|
||||||
command.AddPlatformFlag(flags, &opts.platform)
|
addPlatformFlag(flags, &opts.platform)
|
||||||
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
|
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
|
||||||
|
|
||||||
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
|
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository")
|
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository")
|
||||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
|
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
|
||||||
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
|
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image signing")
|
||||||
|
|
||||||
// Don't default to DOCKER_DEFAULT_PLATFORM env variable, always default to
|
// Don't default to DOCKER_DEFAULT_PLATFORM env variable, always default to
|
||||||
// pushing the image as-is. This also avoids forcing the platform selection
|
// pushing the image as-is. This also avoids forcing the platform selection
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type pluginOptions struct {
|
||||||
|
|
||||||
func loadPullFlags(dockerCli command.Cli, opts *pluginOptions, flags *pflag.FlagSet) {
|
func loadPullFlags(dockerCli command.Cli, opts *pluginOptions, flags *pflag.FlagSet) {
|
||||||
flags.BoolVar(&opts.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin")
|
flags.BoolVar(&opts.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin")
|
||||||
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
|
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInstallCommand(dockerCli command.Cli) *cobra.Command {
|
func newInstallCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func newPushCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
||||||
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
|
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image signing")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
package command
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AddTrustVerificationFlags adds content trust flags to the provided flagset
|
|
||||||
func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool) {
|
|
||||||
fs.BoolVar(v, "disable-content-trust", !trusted, "Skip image verification")
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddTrustSigningFlags adds "signing" flags to the provided flagset
|
|
||||||
func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool) {
|
|
||||||
fs.BoolVar(v, "disable-content-trust", !trusted, "Skip image signing")
|
|
||||||
}
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/docker/cli/internal/prompt"
|
"github.com/docker/cli/internal/prompt"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ErrPromptTerminated = prompt.ErrTerminated
|
const ErrPromptTerminated = prompt.ErrTerminated
|
||||||
|
|
@ -94,12 +93,6 @@ func PruneFilters(dockerCLI config.Provider, pruneFilters filters.Args) filters.
|
||||||
return pruneFilters
|
return pruneFilters
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later.
|
|
||||||
func AddPlatformFlag(flags *pflag.FlagSet, target *string) {
|
|
||||||
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
|
||||||
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateOutputPath validates the output paths of the "docker cp" command.
|
// ValidateOutputPath validates the output paths of the "docker cp" command.
|
||||||
func ValidateOutputPath(path string) error {
|
func ValidateOutputPath(path string) error {
|
||||||
dir := filepath.Dir(filepath.Clean(path))
|
dir := filepath.Dir(filepath.Clean(path))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue