mirror of
https://github.com/docker/cli.git
synced 2026-01-13 18:22:35 +03:00
cli/command/stack/swarm: remove deprecated RunPS and options.PS
These were deprecated inf0e5a0d654and036d3a6baband were only used internally. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package options
|
||||
|
||||
import "github.com/docker/cli/opts"
|
||||
|
||||
// Deploy holds docker stack deploy options
|
||||
//
|
||||
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||
@@ -23,18 +21,6 @@ type Config struct {
|
||||
SkipInterpolation bool
|
||||
}
|
||||
|
||||
// PS holds docker stack ps options
|
||||
//
|
||||
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||
type PS struct {
|
||||
Filter opts.FilterOpt
|
||||
NoTrunc bool
|
||||
Namespace string
|
||||
NoResolve bool
|
||||
Quiet bool
|
||||
Format string
|
||||
}
|
||||
|
||||
// Remove holds docker stack remove options
|
||||
//
|
||||
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||
|
||||
@@ -1,38 +1,73 @@
|
||||
package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/stack/options"
|
||||
"github.com/docker/cli/cli/command/stack/swarm"
|
||||
"github.com/docker/cli/cli/command/idresolver"
|
||||
"github.com/docker/cli/cli/command/task"
|
||||
flagsHelper "github.com/docker/cli/cli/flags"
|
||||
cliopts "github.com/docker/cli/opts"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newPsCommand(dockerCli command.Cli) *cobra.Command {
|
||||
opts := options.PS{Filter: cliopts.NewFilterOpt()}
|
||||
// psOptions holds docker stack ps options
|
||||
type psOptions struct {
|
||||
filter cliopts.FilterOpt
|
||||
noTrunc bool
|
||||
namespace string
|
||||
noResolve bool
|
||||
quiet bool
|
||||
format string
|
||||
}
|
||||
|
||||
func newPsCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts := psOptions{filter: cliopts.NewFilterOpt()}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "ps [OPTIONS] STACK",
|
||||
Short: "List the tasks in the stack",
|
||||
Args: cli.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.Namespace = args[0]
|
||||
if err := validateStackName(opts.Namespace); err != nil {
|
||||
opts.namespace = args[0]
|
||||
if err := validateStackName(opts.namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
return swarm.RunPS(cmd.Context(), dockerCli, opts)
|
||||
return runPS(cmd.Context(), dockerCLI, opts)
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return completeNames(dockerCli)(cmd, args, toComplete)
|
||||
return completeNames(dockerCLI)(cmd, args, toComplete)
|
||||
},
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVar(&opts.NoTrunc, "no-trunc", false, "Do not truncate output")
|
||||
flags.BoolVar(&opts.NoResolve, "no-resolve", false, "Do not map IDs to Names")
|
||||
flags.VarP(&opts.Filter, "filter", "f", "Filter output based on conditions provided")
|
||||
flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display task IDs")
|
||||
flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp)
|
||||
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
|
||||
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
|
||||
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
|
||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs")
|
||||
flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// runPS is the swarm implementation of docker stack ps
|
||||
func runPS(ctx context.Context, dockerCLI command.Cli, opts psOptions) error {
|
||||
apiClient := dockerCLI.Client()
|
||||
tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{
|
||||
Filters: getStackFilterFromOpt(opts.namespace, opts.filter),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(tasks) == 0 {
|
||||
return fmt.Errorf("nothing found in stack: %s", opts.namespace)
|
||||
}
|
||||
|
||||
if opts.format == "" {
|
||||
opts.format = task.DefaultFormat(dockerCLI.ConfigFile(), opts.quiet)
|
||||
}
|
||||
|
||||
return task.Print(ctx, dockerCLI, tasks, idresolver.New(apiClient, opts.noResolve), !opts.noTrunc, opts.quiet, opts.format)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/cli/cli/compose/convert"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
@@ -17,12 +16,6 @@ func getStackFilter(namespace string) filters.Args {
|
||||
return filter
|
||||
}
|
||||
|
||||
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
|
||||
filter := opt.Value()
|
||||
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
||||
return filter
|
||||
}
|
||||
|
||||
func getAllStacksFilter() filters.Args {
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("label", convert.LabelNamespace)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
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/moby/moby/client"
|
||||
)
|
||||
|
||||
// RunPS is the swarm implementation of docker stack ps
|
||||
//
|
||||
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||
func RunPS(ctx context.Context, dockerCLI command.Cli, opts options.PS) error {
|
||||
filter := getStackFilterFromOpt(opts.Namespace, opts.Filter)
|
||||
|
||||
apiClient := dockerCLI.Client()
|
||||
tasks, err := apiClient.TaskList(ctx, client.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(apiClient, opts.NoResolve), !opts.NoTrunc, opts.Quiet, format)
|
||||
}
|
||||
Reference in New Issue
Block a user