Files
docker-cli/cli/command/stack/swarm/ps.go
Vincent Demeester 0f9d24f78d Refactor stack command/package
- Handle `bundlefile` directly in the `top-level`
  command. `bundlefile` is still experimental and will be deprecated
  in future version — this should make be easier to remove it.
- Validate the `stack` name in all cases (i.e. whatever the
  orchestrator is used)
- Load the composefile ahead of choosing the orchestrator. This
  removes some slight duplication.
- Makes `RunDeploy` easier to use from outside packages (like
  `docker/app`) with a preloaded configuration.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-26 14:07:26 +02:00

36 lines
936 B
Go

package swarm
import (
"context"
"fmt"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/cli/command/stack/options"
"github.com/docker/cli/cli/command/task"
"github.com/docker/docker/api/types"
)
// RunPS is the swarm implementation of docker stack ps
func RunPS(dockerCli command.Cli, opts options.PS) error {
filter := getStackFilterFromOpt(opts.Namespace, opts.Filter)
ctx := context.Background()
client := dockerCli.Client()
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
if err != nil {
return err
}
if len(tasks) == 0 {
return fmt.Errorf("nothing found in stack: %s", opts.Namespace)
}
format := opts.Format
if len(format) == 0 {
format = task.DefaultFormat(dockerCli.ConfigFile(), opts.Quiet)
}
return task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.NoResolve), !opts.NoTrunc, opts.Quiet, format)
}