unpause.go 1.2 KB

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