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 {
|
2018-05-28 06:21:41 -04:00
|
|
|
if err := validateStackName(opts.Namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2017-12-04 06:30:39 -05:00
|
|
|
filter := getStackFilterFromOpt(opts.Namespace, opts.Filter)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2018-05-28 06:21:41 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
client := dockerCli.Client()
|
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 {
|
2018-05-28 06:21:41 -04:00
|
|
|
return fmt.Errorf("nothing found in stack: %s", opts.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
|
|
|
}
|