2016-09-08 13:11:39 -04:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2017-03-27 21:21:59 -04:00
|
|
|
"github.com/pkg/errors"
|
2016-09-08 13:11:39 -04:00
|
|
|
"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`
|
2017-10-11 12:18:27 -04:00
|
|
|
func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
|
2016-09-08 13:11:39 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:18:27 -04:00
|
|
|
func runUnpause(dockerCli command.Cli, opts *unpauseOptions) error {
|
2016-09-08 13:11:39 -04:00
|
|
|
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
|
|
|
|
}
|