From 9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351 Mon Sep 17 00:00:00 2001 From: Marco Vedovati Date: Thu, 28 Jun 2018 19:08:49 +0200 Subject: Refactor podman/utils with a single container start and attach function Use a single function startAttachCtr() to handle both container start with attach and attach to running containers, as the code handling the attach is common for the 2 use cases. Signed-off-by: Marco Vedovati Closes: #1025 Approved by: rhatdan --- cmd/podman/start.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cmd/podman/start.go') diff --git a/cmd/podman/start.go b/cmd/podman/start.go index 00528d04e..e917d9198 100644 --- a/cmd/podman/start.go +++ b/cmd/podman/start.go @@ -96,16 +96,21 @@ func startCmd(c *cli.Context) error { return errors.Wrapf(err, "unable to get container state") } + ctrRunning := ctrState == libpod.ContainerStateRunning + if attach { inputStream := os.Stdin if !c.Bool("interactive") { inputStream = nil } - if ctrState == libpod.ContainerStateRunning { - return attachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy")) + + // attach to the container and also start it not already running + err = startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), !ctrRunning) + if ctrRunning { + return err } - if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.Bool("sig-proxy")); err != nil { + if err != nil { return errors.Wrapf(err, "unable to start container %s", ctr.ID()) } @@ -117,7 +122,7 @@ func startCmd(c *cli.Context) error { return ctr.Cleanup() } - if ctrState == libpod.ContainerStateRunning { + if ctrRunning { fmt.Println(ctr.ID()) continue } -- cgit v1.2.3-54-g00ecf