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/mount.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/mount.go')
-rw-r--r-- | cmd/podman/mount.go | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/cmd/podman/mount.go b/cmd/podman/mount.go index f71d47434..36ca8bcfb 100644 --- a/cmd/podman/mount.go +++ b/cmd/podman/mount.go @@ -5,15 +5,18 @@ import ( "fmt" "os" + "github.com/containers/libpod/cmd/podman/cliconfig" of "github.com/containers/libpod/cmd/podman/formats" "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/pkg/rootless" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( + mountCommand cliconfig.MountValues + mountDescription = ` podman mount Lists all mounted containers mount points @@ -22,32 +25,29 @@ var ( Mounts the specified container and outputs the mountpoint ` - mountFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "all, a", - Usage: "Mount all containers", - }, - cli.StringFlag{ - Name: "format", - Usage: "Change the output format to Go template", + _mountCommand = &cobra.Command{ + Use: "mount", + Short: "Mount a working container's root filesystem", + Long: mountDescription, + RunE: func(cmd *cobra.Command, args []string) error { + mountCommand.InputArgs = args + mountCommand.GlobalFlags = MainGlobalOpts + return mountCmd(&mountCommand) }, - cli.BoolFlag{ - Name: "notruncate", - Usage: "Do not truncate output", - }, - LatestFlag, - } - mountCommand = cli.Command{ - Name: "mount", - Usage: "Mount a working container's root filesystem", - Description: mountDescription, - Action: mountCmd, - ArgsUsage: "[CONTAINER-NAME-OR-ID [...]]", - Flags: sortFlags(mountFlags), - OnUsageError: usageErrorHandler, } ) +func init() { + mountCommand.Command = _mountCommand + flags := mountCommand.Flags() + flags.BoolVarP(&mountCommand.All, "all", "a", false, "Mount all containers") + flags.StringVar(&mountCommand.Format, "format", "", "Change the output format to Go template") + flags.BoolVarP(&mountCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") + flags.BoolVar(&mountCommand.NoTrunc, "notruncate", false, "Do not truncate output") + + rootCmd.AddCommand(mountCommand.Command) +} + // jsonMountPoint stores info about each container type jsonMountPoint struct { ID string `json:"id"` @@ -55,15 +55,12 @@ type jsonMountPoint struct { MountPoint string `json:"mountpoint"` } -func mountCmd(c *cli.Context) error { - if err := validateFlags(c, mountFlags); err != nil { - return err - } +func mountCmd(c *cliconfig.MountValues) error { if os.Geteuid() != 0 { rootless.SetSkipStorageSetup(true) } - runtime, err := libpodruntime.GetRuntime(c) + runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } @@ -85,11 +82,11 @@ func mountCmd(c *cli.Context) error { } } - if c.Bool("all") && c.Bool("latest") { + if c.All && c.Latest { return errors.Errorf("--all and --latest cannot be used together") } - mountContainers, err := getAllOrLatestContainers(c, runtime, -1, "all") + mountContainers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, -1, "all") if err != nil { if len(mountContainers) == 0 { return err @@ -102,9 +99,9 @@ func mountCmd(c *cli.Context) error { of.JSONString: true, } - json := c.String("format") == of.JSONString - if !formats[c.String("format")] { - return errors.Errorf("%q is not a supported format", c.String("format")) + json := c.Format == of.JSONString + if !formats[c.Format] { + return errors.Errorf("%q is not a supported format", c.Format) } var lastError error @@ -149,7 +146,7 @@ func mountCmd(c *cli.Context) error { continue } - if c.Bool("notruncate") { + if c.NoTrunc { fmt.Printf("%-64s %s\n", container.ID(), mountPoint) } else { fmt.Printf("%-12.12s %s\n", container.ID(), mountPoint) |