summaryrefslogtreecommitdiff
path: root/cmd/podman/images/pull.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/pull.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/pull.go')
-rw-r--r--cmd/podman/images/pull.go69
1 files changed, 45 insertions, 24 deletions
diff --git a/cmd/podman/images/pull.go b/cmd/podman/images/pull.go
index ab3b0a197..a6f41688c 100644
--- a/cmd/podman/images/pull.go
+++ b/cmd/podman/images/pull.go
@@ -5,12 +5,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"
)
// pullOptionsWrapper wraps entities.ImagePullOptions and prevents leaking
@@ -29,11 +30,12 @@ var (
// Command: podman pull
pullCmd = &cobra.Command{
- Use: "pull [options] IMAGE",
- Args: cobra.ExactArgs(1),
- Short: "Pull an image from a registry",
- Long: pullDescription,
- RunE: imagePull,
+ Use: "pull [options] IMAGE",
+ Args: cobra.ExactArgs(1),
+ Short: "Pull an image from a registry",
+ Long: pullDescription,
+ RunE: imagePull,
+ ValidArgsFunction: common.AutocompleteImages,
Example: `podman pull imageName
podman pull fedora:latest`,
}
@@ -42,11 +44,12 @@ var (
// It's basically a clone of `pullCmd` with the exception of being a
// child of the images command.
imagesPullCmd = &cobra.Command{
- Use: pullCmd.Use,
- Args: pullCmd.Args,
- Short: pullCmd.Short,
- Long: pullCmd.Long,
- RunE: pullCmd.RunE,
+ Use: pullCmd.Use,
+ Args: pullCmd.Args,
+ Short: pullCmd.Short,
+ Long: pullCmd.Long,
+ RunE: pullCmd.RunE,
+ ValidArgsFunction: pullCmd.ValidArgsFunction,
Example: `podman image pull imageName
podman image pull fedora:latest`,
}
@@ -58,9 +61,7 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: pullCmd,
})
-
- flags := pullCmd.Flags()
- pullFlags(flags)
+ pullFlags(pullCmd)
// images pull
registry.Commands = append(registry.Commands, registry.CliCommand{
@@ -68,26 +69,46 @@ func init() {
Command: imagesPullCmd,
Parent: imageCmd,
})
-
- imagesPullFlags := imagesPullCmd.Flags()
- pullFlags(imagesPullFlags)
+ pullFlags(imagesPullCmd)
}
// pullFlags set the flags for the pull command.
-func pullFlags(flags *pflag.FlagSet) {
+func pullFlags(cmd *cobra.Command) {
+ flags := cmd.Flags()
+
flags.BoolVar(&pullOptions.AllTags, "all-tags", false, "All tagged images in the repository will be pulled")
- flags.StringVar(&pullOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
- flags.StringVar(&pullOptions.OverrideArch, "override-arch", "", "Use `ARCH` instead of the architecture of the machine for choosing images")
- flags.StringVar(&pullOptions.OverrideOS, "override-os", "", "Use `OS` instead of the running OS for choosing images")
- flags.StringVar(&pullOptions.OverrideVariant, "override-variant", "", " use VARIANT instead of the running architecture variant for choosing images")
+
+ credsFlagName := "creds"
+ flags.StringVar(&pullOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
+ _ = cmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone)
+
+ overrideArchFlagName := "override-arch"
+ flags.StringVar(&pullOptions.OverrideArch, overrideArchFlagName, "", "Use `ARCH` instead of the architecture of the machine for choosing images")
+ _ = cmd.RegisterFlagCompletionFunc(overrideArchFlagName, completion.AutocompleteNone)
+
+ overrideOsFlagName := "override-os"
+ flags.StringVar(&pullOptions.OverrideOS, overrideOsFlagName, "", "Use `OS` instead of the running OS for choosing images")
+ _ = cmd.RegisterFlagCompletionFunc(overrideOsFlagName, completion.AutocompleteNone)
+
+ overrideVariantFlagName := "override-variant"
+ flags.StringVar(&pullOptions.OverrideVariant, overrideVariantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images")
+ _ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone)
+
flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
flags.BoolVar(&pullOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
- flags.StringVar(&pullOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
+
+ authfileFlagName := "authfile"
+ flags.StringVar(&pullOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
+ _ = cmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
if !registry.IsRemote() {
- flags.StringVar(&pullOptions.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
+
+ certDirFlagName := "cert-dir"
+ flags.StringVar(&pullOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
+ _ = cmd.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault)
+
}
_ = flags.MarkHidden("signature-policy")
}