2016-09-08 13:11:39 -04:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2016-12-24 19:05:37 -05:00
|
|
|
"errors"
|
2016-09-08 13:11:39 -04:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/spf13/cobra"
|
2016-12-24 19:05:37 -05:00
|
|
|
"golang.org/x/net/context"
|
2016-09-08 13:11:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type unpauseOptions struct {
|
|
|
|
containers []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUnpauseCommand creates a new cobra.Command for `docker unpause`
|
|
|
|
func NewUnpauseCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
|
var opts unpauseOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unpause CONTAINER [CONTAINER...]",
|
|
|
|
Short: "Unpause all processes within one or more containers",
|
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts.containers = args
|
|
|
|
return runUnpause(dockerCli, &opts)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runUnpause(dockerCli *command.DockerCli, opts *unpauseOptions) error {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
var errs []string
|
2016-09-12 05:21:08 -04:00
|
|
|
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause)
|
2016-09-08 13:11:39 -04:00
|
|
|
for _, container := range opts.containers {
|
2016-09-12 05:21:08 -04:00
|
|
|
if err := <-errChan; err != nil {
|
2016-09-08 13:11:39 -04:00
|
|
|
errs = append(errs, err.Error())
|
2016-12-24 19:05:37 -05:00
|
|
|
continue
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
2016-12-24 19:05:37 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), container)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
2016-12-24 19:05:37 -05:00
|
|
|
return errors.New(strings.Join(errs, "\n"))
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|