summaryrefslogtreecommitdiff
path: root/cmd/podman/pull.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/pull.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/pull.go')
-rw-r--r--cmd/podman/pull.go89
1 files changed, 38 insertions, 51 deletions
diff --git a/cmd/podman/pull.go b/cmd/podman/pull.go
index 2349265d0..d70719164 100644
--- a/cmd/podman/pull.go
+++ b/cmd/podman/pull.go
@@ -9,68 +9,58 @@ import (
dockerarchive "github.com/containers/image/docker/archive"
"github.com/containers/image/transports/alltransports"
"github.com/containers/image/types"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod/adapter"
image2 "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- pullFlags = []cli.Flag{
- cli.StringFlag{
- Name: "authfile",
- Usage: "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. Use REGISTRY_AUTH_FILE environment variable to override. ",
- },
- cli.StringFlag{
- Name: "cert-dir",
- Usage: "`pathname` of a directory containing TLS certificates and keys",
- },
- cli.StringFlag{
- Name: "creds",
- Usage: "`credentials` (USERNAME:PASSWORD) to use for authenticating to a registry",
- },
- cli.BoolFlag{
- Name: "quiet, q",
- Usage: "Suppress output information when pulling images",
- },
- cli.StringFlag{
- Name: "signature-policy",
- Usage: "`pathname` of signature policy file (not usually used)",
- },
- cli.BoolTFlag{
- Name: "tls-verify",
- Usage: "Require HTTPS and verify certificates when contacting registries (default: true)",
- },
- }
-
+ pullCommand cliconfig.PullValues
pullDescription = `
Pulls an image from a registry and stores it locally.
An image can be pulled using its tag or digest. If a tag is not
specified, the image with the 'latest' tag (if it exists) is pulled
`
- pullCommand = cli.Command{
- Name: "pull",
- Usage: "Pull an image from a registry",
- Description: pullDescription,
- Flags: sortFlags(pullFlags),
- Action: pullCmd,
- ArgsUsage: "",
- OnUsageError: usageErrorHandler,
+ _pullCommand = &cobra.Command{
+ Use: "pull",
+ Short: "Pull an image from a registry",
+ Long: pullDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ pullCommand.InputArgs = args
+ pullCommand.GlobalFlags = MainGlobalOpts
+ return pullCmd(&pullCommand)
+ },
+ Example: "",
}
)
+func init() {
+ pullCommand.Command = _pullCommand
+ flags := pullCommand.Flags()
+ flags.StringVar(&pullCommand.Authfile, "authfile", "", "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. Use REGISTRY_AUTH_FILE environment variable to override")
+ flags.StringVar(&pullCommand.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
+ flags.StringVar(&pullCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
+ flags.BoolVarP(&pullCommand.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
+ flags.StringVar(&pullCommand.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
+ flags.BoolVar(&pullCommand.TlsVerify, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries (default: true)")
+
+ rootCmd.AddCommand(pullCommand.Command)
+}
+
// pullCmd gets the data from the command line and calls pullImage
// to copy an image from a registry to a local machine
-func pullCmd(c *cli.Context) error {
- runtime, err := adapter.GetRuntime(c)
+func pullCmd(c *cliconfig.PullValues) error {
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- args := c.Args()
+ args := c.InputArgs
if len(args) == 0 {
logrus.Errorf("an image name must be specified")
return nil
@@ -79,15 +69,12 @@ func pullCmd(c *cli.Context) error {
logrus.Errorf("too many arguments. Requires exactly 1")
return nil
}
- if err := validateFlags(c, pullFlags); err != nil {
- return err
- }
image := args[0]
var registryCreds *types.DockerAuthConfig
- if c.IsSet("creds") {
- creds, err := util.ParseRegistryCreds(c.String("creds"))
+ if c.Flag("creds").Changed {
+ creds, err := util.ParseRegistryCreds(c.Creds)
if err != nil {
return err
}
@@ -98,16 +85,16 @@ func pullCmd(c *cli.Context) error {
writer io.Writer
imgID string
)
- if !c.Bool("quiet") {
+ if !c.Quiet {
writer = os.Stderr
}
dockerRegistryOptions := image2.DockerRegistryOptions{
DockerRegistryCreds: registryCreds,
- DockerCertPath: c.String("cert-dir"),
+ DockerCertPath: c.CertDir,
}
- if c.IsSet("tls-verify") {
- dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.BoolT("tls-verify"))
+ if c.Flag("tls-verify").Changed {
+ dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.TlsVerify)
}
// Possible for docker-archive to have multiple tags, so use LoadFromArchiveReference instead
@@ -116,14 +103,14 @@ func pullCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "error parsing %q", image)
}
- newImage, err := runtime.LoadFromArchiveReference(getContext(), srcRef, c.String("signature-policy"), writer)
+ newImage, err := runtime.LoadFromArchiveReference(getContext(), srcRef, c.SignaturePolicy, writer)
if err != nil {
return errors.Wrapf(err, "error pulling image from %q", image)
}
imgID = newImage[0].ID()
} else {
- authfile := getAuthFile(c.String("authfile"))
- newImage, err := runtime.New(getContext(), image, c.String("signature-policy"), authfile, writer, &dockerRegistryOptions, image2.SigningOptions{}, true, nil)
+ authfile := getAuthFile(c.Authfile)
+ newImage, err := runtime.New(getContext(), image, c.SignaturePolicy, authfile, writer, &dockerRegistryOptions, image2.SigningOptions{}, true, nil)
if err != nil {
return errors.Wrapf(err, "error pulling image %q", image)
}