summaryrefslogtreecommitdiff
path: root/cmd/podman/images/push.go
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2020-05-31 17:35:59 +0200
committerPaul Holzinger <paul.holzinger@web.de>2020-11-12 11:38:31 +0100
commitb5d1d89a377e38762a75c2042dcc50a370ba6707 (patch)
treeeebedb62f7aeeb17cd6fdbe9317a59effd02e96d /cmd/podman/images/push.go
parentdf4bf5c584f264bdefef5cb30d85c036260eff8f (diff)
downloadpodman-b5d1d89a377e38762a75c2042dcc50a370ba6707.tar.gz
podman-b5d1d89a377e38762a75c2042dcc50a370ba6707.tar.bz2
podman-b5d1d89a377e38762a75c2042dcc50a370ba6707.zip
Add shell completion with cobra
Allow automatic generation for shell completion scripts with the internal cobra functions (requires v1.0.0+). This should replace the handwritten completion scripts and even adds support for fish. With this approach it is less likley that completions and code are out of sync. We can now create the scripts with - podman completion bash - podman completion zsh - podman completion fish To test the completion run: source <(podman completion bash) The same works for podman-remote and podman --remote and it will complete your remote containers/images with the correct endpoints values from --url/--connection. The completion logic is written in go and provided by the cobra library. The completion functions lives in `cmd/podman/completion/completion.go`. The unit test at cmd/podman/shell_completion_test.go checks if each command and flag has an autocompletion function set. This prevents that commands and flags have no shell completion set. This commit does not replace the current autocompletion scripts. Closes #6440 Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'cmd/podman/images/push.go')
-rw-r--r--cmd/podman/images/push.go69
1 files changed, 46 insertions, 23 deletions
diff --git a/cmd/podman/images/push.go b/cmd/podman/images/push.go
index dd45a790f..447b02fbe 100644
--- a/cmd/podman/images/push.go
+++ b/cmd/podman/images/push.go
@@ -4,12 +4,13 @@ import (
"os"
"github.com/containers/common/pkg/auth"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/image/v5/types"
+ "github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/util"
"github.com/spf13/cobra"
- "github.com/spf13/pflag"
)
// pushOptionsWrapper wraps entities.ImagepushOptions and prevents leaking
@@ -28,11 +29,12 @@ var (
// Command: podman push
pushCmd = &cobra.Command{
- Use: "push [options] SOURCE [DESTINATION]",
- Short: "Push an image to a specified destination",
- Long: pushDescription,
- RunE: imagePush,
- Args: cobra.RangeArgs(1, 2),
+ Use: "push [options] SOURCE [DESTINATION]",
+ Short: "Push an image to a specified destination",
+ Long: pushDescription,
+ RunE: imagePush,
+ Args: cobra.RangeArgs(1, 2),
+ ValidArgsFunction: common.AutocompleteImages,
Example: `podman push imageID docker://registry.example.com/repository:tag
podman push imageID oci-archive:/path/to/layout:image:tag`,
}
@@ -41,11 +43,12 @@ var (
// It's basically a clone of `pushCmd` with the exception of being a
// child of the images command.
imagePushCmd = &cobra.Command{
- Use: pushCmd.Use,
- Short: pushCmd.Short,
- Long: pushCmd.Long,
- RunE: pushCmd.RunE,
- Args: pushCmd.Args,
+ Use: pushCmd.Use,
+ Short: pushCmd.Short,
+ Long: pushCmd.Long,
+ RunE: pushCmd.RunE,
+ Args: pushCmd.Args,
+ ValidArgsFunction: pushCmd.ValidArgsFunction,
Example: `podman image push imageID docker://registry.example.com/repository:tag
podman image push imageID oci-archive:/path/to/layout:image:tag`,
}
@@ -57,9 +60,7 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: pushCmd,
})
-
- flags := pushCmd.Flags()
- pushFlags(flags)
+ pushFlags(pushCmd)
// images push
registry.Commands = append(registry.Commands, registry.CliCommand{
@@ -67,23 +68,45 @@ func init() {
Command: imagePushCmd,
Parent: imageCmd,
})
-
- pushFlags(imagePushCmd.Flags())
+ pushFlags(imagePushCmd)
}
// pushFlags set the flags for the push command.
-func pushFlags(flags *pflag.FlagSet) {
- flags.StringVar(&pushOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
- flags.StringVar(&pushOptions.CertDir, "cert-dir", "", "Path to a directory containing TLS certificates and keys")
+func pushFlags(cmd *cobra.Command) {
+ flags := cmd.Flags()
+
+ authfileFlagName := "authfile"
+ flags.StringVar(&pushOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
+ _ = cmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
+
+ certDirFlagName := "cert-dir"
+ flags.StringVar(&pushOptions.CertDir, certDirFlagName, "", "Path to a directory containing TLS certificates and keys")
+ _ = cmd.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault)
+
flags.BoolVar(&pushOptions.Compress, "compress", false, "Compress tarball image layers when pushing to a directory using the 'dir' transport. (default is same compression type as source)")
- flags.StringVar(&pushOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
- flags.StringVar(&pushOptions.DigestFile, "digestfile", "", "Write the digest of the pushed image to the specified file")
+
+ credsFlagName := "creds"
+ flags.StringVar(&pushOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
+ _ = cmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone)
+
flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
- flags.StringVarP(&pushOptions.Format, "format", "f", "", "Manifest type (oci, v2s1, or v2s2) to use when pushing an image using the 'dir' transport (default is manifest type of source)")
+
+ digestfileFlagName := "digestfile"
+ flags.StringVar(&pushOptions.DigestFile, digestfileFlagName, "", "Write the digest of the pushed image to the specified file")
+ _ = cmd.RegisterFlagCompletionFunc(digestfileFlagName, completion.AutocompleteDefault)
+
+ formatFlagName := "format"
+ flags.StringVarP(&pushOptions.Format, formatFlagName, "f", "", "Manifest type (oci, v2s1, or v2s2) to use when pushing an image using the 'dir' transport (default is manifest type of source)")
+ _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteManifestFormat)
+
flags.BoolVarP(&pushOptions.Quiet, "quiet", "q", false, "Suppress output information when pushing images")
flags.BoolVar(&pushOptions.RemoveSignatures, "remove-signatures", false, "Discard any pre-existing signatures in the image")
flags.StringVar(&pushOptions.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
- flags.StringVar(&pushOptions.SignBy, "sign-by", "", "Add a signature at the destination using the specified key")
+
+ signByFlagName := "sign-by"
+ flags.StringVar(&pushOptions.SignBy, signByFlagName, "", "Add a signature at the destination using the specified key")
+ _ = cmd.RegisterFlagCompletionFunc(signByFlagName, completion.AutocompleteNone)
+
flags.BoolVar(&pushOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
if registry.IsRemote() {