summaryrefslogtreecommitdiff
path: root/cmd/podman/run.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/run.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/run.go')
-rw-r--r--cmd/podman/run.go56
1 files changed, 32 insertions, 24 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 3ef546940..76b29cb84 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -8,49 +8,57 @@ import (
"strconv"
"strings"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
-var runDescription = "Runs a command in a new container from the given image"
-
-var runFlags []cli.Flag = append(createFlags, cli.BoolTFlag{
- Name: "sig-proxy",
- Usage: "Proxy received signals to the process (default true)",
-})
-
-var runCommand = cli.Command{
- Name: "run",
- Usage: "Run a command in a new container",
- Description: runDescription,
- Flags: sortFlags(runFlags),
- Action: runCmd,
- ArgsUsage: "IMAGE [COMMAND [ARG...]]",
- HideHelp: true,
- SkipArgReorder: true,
- UseShortOptionHandling: true,
- OnUsageError: usageErrorHandler,
+var (
+ runCommmand cliconfig.RunValues
+
+ runDescription = "Runs a command in a new container from the given image"
+ _runCommmand = &cobra.Command{
+ Use: "run",
+ Short: "Run a command in a new container",
+ Long: runDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ runCommmand.InputArgs = args
+ runCommmand.GlobalFlags = MainGlobalOpts
+ return runCmd(&runCommmand)
+ },
+ Example: "IMAGE [COMMAND [ARG...]]",
+ }
+)
+
+func init() {
+ runCommmand.Command = _runCommmand
+ flags := runCommmand.Flags()
+ flags.SetInterspersed(false)
+ flags.Bool("sig-proxy", true, "Proxy received signals to the process (default true)")
+ getCreateFlags(&runCommmand.PodmanCommand)
+
+ rootCmd.AddCommand(runCommmand.Command)
}
-func runCmd(c *cli.Context) error {
- if err := createInit(c); err != nil {
+func runCmd(c *cliconfig.RunValues) error {
+ if err := createInit(&c.PodmanCommand); err != nil {
return err
}
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, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- ctr, createConfig, err := createContainer(c, runtime)
+ ctr, createConfig, err := createContainer(&c.PodmanCommand, runtime)
if err != nil {
return err
}
@@ -110,7 +118,7 @@ func runCmd(c *cli.Context) error {
}
}
}
- if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy"), true); err != nil {
+ if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), true); err != nil {
// This means the command did not exist
exitCode = 127
if strings.Index(err.Error(), "permission denied") > -1 {