Skip to content

Commit c3be589

Browse files
committed
cli/command/stack/swarm: remove deprecated RunPS and options.PS
These were deprecated in f0e5a0d and 036d3a6 and were only used internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 2a05951 commit c3be589

File tree

4 files changed

+48
-70
lines changed

4 files changed

+48
-70
lines changed

cli/command/stack/options/opts.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package options
22

3-
import "github.com/docker/cli/opts"
4-
53
// Deploy holds docker stack deploy options
64
//
75
// Deprecated: this type was for internal use and will be removed in the next release.
@@ -23,18 +21,6 @@ type Config struct {
2321
SkipInterpolation bool
2422
}
2523

26-
// PS holds docker stack ps options
27-
//
28-
// Deprecated: this type was for internal use and will be removed in the next release.
29-
type PS struct {
30-
Filter opts.FilterOpt
31-
NoTrunc bool
32-
Namespace string
33-
NoResolve bool
34-
Quiet bool
35-
Format string
36-
}
37-
3824
// Remove holds docker stack remove options
3925
//
4026
// Deprecated: this type was for internal use and will be removed in the next release.

cli/command/stack/ps.go

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,73 @@
11
package stack
22

33
import (
4+
"context"
5+
"fmt"
6+
47
"github.com/docker/cli/cli"
58
"github.com/docker/cli/cli/command"
6-
"github.com/docker/cli/cli/command/stack/options"
7-
"github.com/docker/cli/cli/command/stack/swarm"
9+
"github.com/docker/cli/cli/command/idresolver"
10+
"github.com/docker/cli/cli/command/task"
811
flagsHelper "github.com/docker/cli/cli/flags"
912
cliopts "github.com/docker/cli/opts"
13+
"github.com/moby/moby/client"
1014
"github.com/spf13/cobra"
1115
)
1216

13-
func newPsCommand(dockerCli command.Cli) *cobra.Command {
14-
opts := options.PS{Filter: cliopts.NewFilterOpt()}
17+
// psOptions holds docker stack ps options
18+
type psOptions struct {
19+
filter cliopts.FilterOpt
20+
noTrunc bool
21+
namespace string
22+
noResolve bool
23+
quiet bool
24+
format string
25+
}
26+
27+
func newPsCommand(dockerCLI command.Cli) *cobra.Command {
28+
opts := psOptions{filter: cliopts.NewFilterOpt()}
1529

1630
cmd := &cobra.Command{
1731
Use: "ps [OPTIONS] STACK",
1832
Short: "List the tasks in the stack",
1933
Args: cli.ExactArgs(1),
2034
RunE: func(cmd *cobra.Command, args []string) error {
21-
opts.Namespace = args[0]
22-
if err := validateStackName(opts.Namespace); err != nil {
35+
opts.namespace = args[0]
36+
if err := validateStackName(opts.namespace); err != nil {
2337
return err
2438
}
25-
return swarm.RunPS(cmd.Context(), dockerCli, opts)
39+
return runPS(cmd.Context(), dockerCLI, opts)
2640
},
2741
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
28-
return completeNames(dockerCli)(cmd, args, toComplete)
42+
return completeNames(dockerCLI)(cmd, args, toComplete)
2943
},
3044
}
3145
flags := cmd.Flags()
32-
flags.BoolVar(&opts.NoTrunc, "no-trunc", false, "Do not truncate output")
33-
flags.BoolVar(&opts.NoResolve, "no-resolve", false, "Do not map IDs to Names")
34-
flags.VarP(&opts.Filter, "filter", "f", "Filter output based on conditions provided")
35-
flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display task IDs")
36-
flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp)
46+
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
47+
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
48+
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
49+
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs")
50+
flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp)
3751
return cmd
3852
}
53+
54+
// runPS is the swarm implementation of docker stack ps
55+
func runPS(ctx context.Context, dockerCLI command.Cli, opts psOptions) error {
56+
apiClient := dockerCLI.Client()
57+
tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{
58+
Filters: getStackFilterFromOpt(opts.namespace, opts.filter),
59+
})
60+
if err != nil {
61+
return err
62+
}
63+
64+
if len(tasks) == 0 {
65+
return fmt.Errorf("nothing found in stack: %s", opts.namespace)
66+
}
67+
68+
if opts.format == "" {
69+
opts.format = task.DefaultFormat(dockerCLI.ConfigFile(), opts.quiet)
70+
}
71+
72+
return task.Print(ctx, dockerCLI, tasks, idresolver.New(apiClient, opts.noResolve), !opts.noTrunc, opts.quiet, opts.format)
73+
}

cli/command/stack/swarm/common.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55

66
"github.com/docker/cli/cli/compose/convert"
7-
"github.com/docker/cli/opts"
87
"github.com/moby/moby/api/types/filters"
98
"github.com/moby/moby/api/types/network"
109
"github.com/moby/moby/api/types/swarm"
@@ -17,12 +16,6 @@ func getStackFilter(namespace string) filters.Args {
1716
return filter
1817
}
1918

20-
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
21-
filter := opt.Value()
22-
filter.Add("label", convert.LabelNamespace+"="+namespace)
23-
return filter
24-
}
25-
2619
func getAllStacksFilter() filters.Args {
2720
filter := filters.NewArgs()
2821
filter.Add("label", convert.LabelNamespace)

cli/command/stack/swarm/ps.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)