github.com/portworx/docker@v1.12.1/api/client/container/unpause.go (about)

     1  package container
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"golang.org/x/net/context"
     8  
     9  	"github.com/docker/docker/api/client"
    10  	"github.com/docker/docker/cli"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  type unpauseOptions struct {
    15  	containers []string
    16  }
    17  
    18  // NewUnpauseCommand creats a new cobra.Command for `docker unpause`
    19  func NewUnpauseCommand(dockerCli *client.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  	cmd.SetFlagErrorFunc(flagErrorFunc)
    32  
    33  	return cmd
    34  }
    35  
    36  func runUnpause(dockerCli *client.DockerCli, opts *unpauseOptions) error {
    37  	ctx := context.Background()
    38  
    39  	var errs []string
    40  	for _, container := range opts.containers {
    41  		if err := dockerCli.Client().ContainerUnpause(ctx, container); err != nil {
    42  			errs = append(errs, err.Error())
    43  		} else {
    44  			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
    45  		}
    46  	}
    47  	if len(errs) > 0 {
    48  		return fmt.Errorf("%s", strings.Join(errs, "\n"))
    49  	}
    50  	return nil
    51  }