2017-11-20 09:30:52 -05:00
|
|
|
package swarm
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2016-09-08 13:11:39 -04:00
|
|
|
"fmt"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/command/idresolver"
|
2017-12-04 06:30:39 -05:00
|
|
|
"github.com/docker/cli/cli/command/stack/options"
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command/task"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
2017-12-04 06:30:39 -05:00
|
|
|
// RunPS is the swarm implementation of docker stack ps
|
|
|
|
func RunPS(dockerCli command.Cli, opts options.PS) error {
|
|
|
|
namespace := opts.Namespace
|
2016-09-08 13:11:39 -04:00
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2017-12-04 06:30:39 -05:00
|
|
|
filter := getStackFilterFromOpt(opts.Namespace, opts.Filter)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2016-11-01 10:01:16 -04:00
|
|
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
|
2016-09-08 13:11:39 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tasks) == 0 {
|
2017-08-30 06:47:53 -04:00
|
|
|
return fmt.Errorf("nothing found in stack: %s", namespace)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2017-12-04 06:30:39 -05:00
|
|
|
format := opts.Format
|
2016-11-07 00:54:40 -05:00
|
|
|
if len(format) == 0 {
|
2017-12-04 06:30:39 -05:00
|
|
|
format = task.DefaultFormat(dockerCli.ConfigFile(), opts.Quiet)
|
2016-11-07 00:54:40 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 06:30:39 -05:00
|
|
|
return task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.NoResolve), !opts.NoTrunc, opts.Quiet, format)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|