unpause.go 1.2 KB

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