/
left76
/
ccli5
Обзор
Документация
Войти
/
left76
/
ccli5
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
cli/command/container/pause.go
49 строк
1 KB
Kir Kolyshkin
Switch from x/net/context to context
12 май 2018, 02:49
12 май 2018, 02:49
6f8070d
Код
Авторство
О чём код?
package container import ( "context" "fmt" "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/pkg/errors" "github.com/spf13/cobra" ) type pauseOptions struct { containers []string } // NewPauseCommand creates a new cobra.Command for `docker pause` func NewPauseCommand(dockerCli command.Cli) *cobra.Command { var opts pauseOptions return &cobra.Command{ Use: "pause CONTAINER [CONTAINER...]", Short: "Pause all processes within one or more containers", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.containers = args return runPause(dockerCli, &opts) }, } } func runPause(dockerCli command.Cli, opts *pauseOptions) error { ctx := context.Background() var errs []string errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause) for _, container := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) continue } fmt.Fprintln(dockerCli.Out(), container) } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) } return nil }