summaryrefslogtreecommitdiff
path: root/cmd/podman/load.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/load.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/load.go')
-rw-r--r--cmd/podman/load.go66
1 files changed, 31 insertions, 35 deletions
diff --git a/cmd/podman/load.go b/cmd/podman/load.go
index f39ee4487..90268ca8f 100644
--- a/cmd/podman/load.go
+++ b/cmd/podman/load.go
@@ -9,45 +9,44 @@ import (
"github.com/containers/image/directory"
dockerarchive "github.com/containers/image/docker/archive"
ociarchive "github.com/containers/image/oci/archive"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod/image"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- loadFlags = []cli.Flag{
- cli.StringFlag{
- Name: "input, i",
- Usage: "Read from archive file, default is STDIN",
- Value: "/dev/stdin",
- },
- cli.BoolFlag{
- Name: "quiet, q",
- Usage: "Suppress the output",
- },
- cli.StringFlag{
- Name: "signature-policy",
- Usage: "`pathname` of signature policy file (not usually used)",
- },
- }
+ loadCommand cliconfig.LoadValues
+
loadDescription = "Loads the image from docker-archive stored on the local machine."
- loadCommand = cli.Command{
- Name: "load",
- Usage: "Load an image from docker archive",
- Description: loadDescription,
- Flags: sortFlags(loadFlags),
- Action: loadCmd,
- ArgsUsage: "",
- OnUsageError: usageErrorHandler,
+ _loadCommand = &cobra.Command{
+ Use: "load",
+ Short: "Load an image from docker archive",
+ Long: loadDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ loadCommand.InputArgs = args
+ loadCommand.GlobalFlags = MainGlobalOpts
+ return loadCmd(&loadCommand)
+ },
}
)
+func init() {
+ loadCommand.Command = _loadCommand
+ flags := loadCommand.Flags()
+ flags.StringVarP(&loadCommand.Input, "input", "i", "/dev/stdin", "Read from archive file, default is STDIN")
+ flags.BoolVarP(&loadCommand.Quiet, "quiet", "q", false, "Suppress the output")
+ flags.StringVar(&loadCommand.SignaturePolicy, "signature-policy", "", "Pathname of signature policy file (not usually used)")
+
+ rootCmd.AddCommand(loadCommand.Command)
+}
+
// loadCmd gets the image/file to be loaded from the command line
// and calls loadImage to load the image to containers-storage
-func loadCmd(c *cli.Context) error {
+func loadCmd(c *cliconfig.LoadValues) error {
- args := c.Args()
+ args := c.InputArgs
var imageName string
if len(args) == 1 {
@@ -56,17 +55,14 @@ func loadCmd(c *cli.Context) error {
if len(args) > 1 {
return errors.New("too many arguments. Requires exactly 1")
}
- if err := validateFlags(c, loadFlags); err != nil {
- return err
- }
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- input := c.String("input")
+ input := c.Input
if input == "/dev/stdin" {
fi, err := os.Stdin.Stat()
@@ -101,7 +97,7 @@ func loadCmd(c *cli.Context) error {
}
var writer io.Writer
- if !c.Bool("quiet") {
+ if !c.Quiet {
writer = os.Stderr
}
@@ -110,18 +106,18 @@ func loadCmd(c *cli.Context) error {
var newImages []*image.Image
src, err := dockerarchive.ParseReference(input) // FIXME? We should add dockerarchive.NewReference()
if err == nil {
- newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer)
+ newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.SignaturePolicy, writer)
}
if err != nil {
// generate full src name with specified image:tag
src, err := ociarchive.NewReference(input, imageName) // imageName may be ""
if err == nil {
- newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer)
+ newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.SignaturePolicy, writer)
}
if err != nil {
src, err := directory.NewReference(input)
if err == nil {
- newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer)
+ newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.SignaturePolicy, writer)
}
if err != nil {
return errors.Wrapf(err, "error pulling %q", input)