aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/attach.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/attach.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/attach.go')
-rw-r--r--cmd/podman/attach.go67
1 files changed, 33 insertions, 34 deletions
diff --git a/cmd/podman/attach.go b/cmd/podman/attach.go
index bcfee6891..8b0fd7ffd 100644
--- a/cmd/podman/attach.go
+++ b/cmd/podman/attach.go
@@ -3,57 +3,56 @@ package main
import (
"os"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- attachFlags = []cli.Flag{
- cli.StringFlag{
- Name: "detach-keys",
- Usage: "Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.",
- },
- cli.BoolFlag{
- Name: "no-stdin",
- Usage: "Do not attach STDIN. The default is false.",
- },
- cli.BoolTFlag{
- Name: "sig-proxy",
- Usage: "Proxy received signals to the process (default true)",
- },
- LatestFlag,
- }
+ attachCommand cliconfig.AttachValues
attachDescription = "The podman attach command allows you to attach to a running container using the container's ID or name, either to view its ongoing output or to control it interactively."
- attachCommand = cli.Command{
- Name: "attach",
- Usage: "Attach to a running container",
- Description: attachDescription,
- Flags: sortFlags(attachFlags),
- Action: attachCmd,
- ArgsUsage: "",
- OnUsageError: usageErrorHandler,
+ _attachCommand = &cobra.Command{
+ Use: "attach",
+ Short: "Attach to a running container",
+ Long: attachDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ attachCommand.InputArgs = args
+ attachCommand.GlobalFlags = MainGlobalOpts
+ return attachCmd(&attachCommand)
+ },
+ Example: "",
}
)
-func attachCmd(c *cli.Context) error {
- args := c.Args()
+func init() {
+ attachCommand.Command = _attachCommand
+ flags := attachCommand.Flags()
+ flags.StringVar(&attachCommand.DetachKeys, "detach-keys", "", "Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _")
+ flags.BoolVar(&attachCommand.NoStdin, "no-stdin", false, "Do not attach STDIN. The default is false")
+ flags.BoolVar(&attachCommand.SigProxy, "sig-proxy", true, "Proxy received signals to the process (default true)")
+
+ flags.BoolVarP(&attachCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+
+ rootCmd.AddCommand(attachCommand.Command)
+}
+
+func attachCmd(c *cliconfig.AttachValues) error {
+ args := c.InputArgs
var ctr *libpod.Container
- if err := validateFlags(c, attachFlags); err != nil {
- return err
- }
- if len(c.Args()) > 1 || (len(c.Args()) == 0 && !c.Bool("latest")) {
+
+ if len(c.InputArgs) > 1 || (len(c.InputArgs) == 0 && !c.Latest) {
return errors.Errorf("attach requires the name or id of one running container or the latest flag")
}
- 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)
- if c.Bool("latest") {
+ if c.Latest {
ctr, err = runtime.GetLatestContainer()
} else {
ctr, err = runtime.LookupContainer(args[0])
@@ -72,11 +71,11 @@ func attachCmd(c *cli.Context) error {
}
inputStream := os.Stdin
- if c.Bool("no-stdin") {
+ if c.NoStdin {
inputStream = nil
}
- if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy"), false); err != nil {
+ if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, c.SigProxy, false); err != nil {
return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
}