diff options
author | baude <bbaude@redhat.com> | 2019-01-31 13:20:04 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-02-08 10:26:43 -0600 |
commit | 25a3923b61a5ca014318e6d957f68abd03947297 (patch) | |
tree | 2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/export.go | |
parent | 962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff) | |
download | podman-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/export.go')
-rw-r--r-- | cmd/podman/export.go | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/cmd/podman/export.go b/cmd/podman/export.go index eaa4e38a2..bd9e38b0c 100644 --- a/cmd/podman/export.go +++ b/cmd/podman/export.go @@ -3,50 +3,52 @@ package main import ( "os" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/libpod/adapter" "github.com/containers/libpod/pkg/rootless" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( - exportFlags = []cli.Flag{ - cli.StringFlag{ - Name: "output, o", - Usage: "Write to a file, default is STDOUT", - Value: "/dev/stdout", - }, - } + exportCommand cliconfig.ExportValues exportDescription = "Exports container's filesystem contents as a tar archive" + " and saves it on the local machine." - exportCommand = cli.Command{ - Name: "export", - Usage: "Export container's filesystem contents as a tar archive", - Description: exportDescription, - Flags: sortFlags(exportFlags), - Action: exportCmd, - ArgsUsage: "CONTAINER", - OnUsageError: usageErrorHandler, + + _exportCommand = &cobra.Command{ + Use: "export", + Short: "Export container's filesystem contents as a tar archive", + Long: exportDescription, + RunE: func(cmd *cobra.Command, args []string) error { + exportCommand.InputArgs = args + exportCommand.GlobalFlags = MainGlobalOpts + return exportCmd(&exportCommand) + }, + Example: "CONTAINER", } ) +func init() { + exportCommand.Command = _exportCommand + flags := exportCommand.Flags() + flags.StringVarP(&exportCommand.Output, "output", "o", "/dev/stdout", "Write to a file, default is STDOUT") + rootCmd.AddCommand(exportCommand.Command) +} + // exportCmd saves a container to a tarball on disk -func exportCmd(c *cli.Context) error { - if err := validateFlags(c, exportFlags); err != nil { - return err - } +func exportCmd(c *cliconfig.ExportValues) error { if os.Geteuid() != 0 { rootless.SetSkipStorageSetup(true) } - runtime, err := adapter.GetRuntime(c) + 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 { return errors.Errorf("container id must be specified") } @@ -54,10 +56,11 @@ func exportCmd(c *cli.Context) error { return errors.Errorf("too many arguments given, need 1 at most.") } - output := c.String("output") + output := c.Output if runtime.Remote && (output == "/dev/stdout" || len(output) == 0) { return errors.New("remote client usage must specify an output file (-o)") } + if output == "/dev/stdout" { file := os.Stdout if logrus.IsTerminal(file) { @@ -68,5 +71,5 @@ func exportCmd(c *cli.Context) error { if err := validateFileName(output); err != nil { return err } - return runtime.Export(args[0], c.String("output")) + return runtime.Export(args[0], output) } |