Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / docker / cli / cli / command / container / unpause.go
1 package container
2
3 import (
4         "fmt"
5         "strings"
6
7         "github.com/docker/cli/cli"
8         "github.com/docker/cli/cli/command"
9         "github.com/pkg/errors"
10         "github.com/spf13/cobra"
11         "golang.org/x/net/context"
12 )
13
14 type unpauseOptions struct {
15         containers []string
16 }
17
18 // NewUnpauseCommand creates a new cobra.Command for `docker unpause`
19 func NewUnpauseCommand(dockerCli *command.DockerCli) *cobra.Command {
20         var opts unpauseOptions
21
22         cmd := &cobra.Command{
23                 Use:   "unpause CONTAINER [CONTAINER...]",
24                 Short: "Unpause all processes within one or more containers",
25                 Args:  cli.RequiresMinArgs(1),
26                 RunE: func(cmd *cobra.Command, args []string) error {
27                         opts.containers = args
28                         return runUnpause(dockerCli, &opts)
29                 },
30         }
31         return cmd
32 }
33
34 func runUnpause(dockerCli *command.DockerCli, opts *unpauseOptions) error {
35         ctx := context.Background()
36
37         var errs []string
38         errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause)
39         for _, container := range opts.containers {
40                 if err := <-errChan; err != nil {
41                         errs = append(errs, err.Error())
42                         continue
43                 }
44                 fmt.Fprintln(dockerCli.Out(), container)
45         }
46         if len(errs) > 0 {
47                 return errors.New(strings.Join(errs, "\n"))
48         }
49         return nil
50 }