cli/command/stack: deprecate now obsolete wrappers

These wrappers were added to abstract stack deploy to k8s and swarm. Now
that support for deploying to k8s was removed, we can remove these wrappers.

This deprecates:

- RunDeploy()
- RunPs()
- RunRemove()
- GetServices()

This also addresses some linting failers, due to these functions having
unused arguments:

    cli/command/stack/deploy.go:51:39: unused-parameter: parameter 'flags' seems to be unused, consider removing or renaming it as _ (revive)
    func RunDeploy(dockerCli command.Cli, flags *pflag.FlagSet, config *composetypes.Config, opts options.Deploy) error {
                                              ^
    cli/command/stack/ps.go:42:35: unused-parameter: parameter 'flags' seems to be unused, consider removing or renaming it as _ (revive)
    func RunPs(dockerCli command.Cli, flags *pflag.FlagSet, opts options.PS) error {
                                      ^
    cli/command/stack/remove.go:35:39: unused-parameter: parameter 'flags' seems to be unused, consider removing or renaming it as _ (revive)
    func RunRemove(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Remove) error {
                                          ^
    cli/command/stack/list.go:37:14: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
    func RunList(cmd *cobra.Command, dockerCli command.Cli, opts options.List) error {
                 ^
    cli/command/stack/services.go:56:41: unused-parameter: parameter 'flags' seems to be unused, consider removing or renaming it as _ (revive)
    func GetServices(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Services) ([]swarmtypes.Service, error) {
                                            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-03-29 15:42:17 +02:00
parent 78c474539b
commit f08252c10a
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
5 changed files with 29 additions and 21 deletions

View File

@ -28,7 +28,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
if err != nil { if err != nil {
return err return err
} }
return RunDeploy(dockerCli, cmd.Flags(), config, opts) return swarm.RunDeploy(dockerCli, opts, config)
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete) return completeNames(dockerCli)(cmd, args, toComplete)
@ -47,7 +47,9 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
return cmd return cmd
} }
// RunDeploy performs a stack deploy against the specified swarm cluster // RunDeploy performs a stack deploy against the specified swarm cluster.
func RunDeploy(dockerCli command.Cli, flags *pflag.FlagSet, config *composetypes.Config, opts options.Deploy) error { //
// Deprecated: use [swarm.RunDeploy] instead.
func RunDeploy(dockerCli command.Cli, _ *pflag.FlagSet, config *composetypes.Config, opts options.Deploy) error {
return swarm.RunDeploy(dockerCli, opts, config) return swarm.RunDeploy(dockerCli, opts, config)
} }

View File

@ -23,7 +23,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
Short: "List stacks", Short: "List stacks",
Args: cli.NoArgs, Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return RunList(cmd, dockerCli, opts) return RunList(dockerCli, opts)
}, },
ValidArgsFunction: completion.NoComplete, ValidArgsFunction: completion.NoComplete,
} }
@ -34,24 +34,24 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
} }
// RunList performs a stack list against the specified swarm cluster // RunList performs a stack list against the specified swarm cluster
func RunList(cmd *cobra.Command, dockerCli command.Cli, opts options.List) error { func RunList(dockerCli command.Cli, opts options.List) error {
stacks := []*formatter.Stack{}
ss, err := swarm.GetStacks(dockerCli) ss, err := swarm.GetStacks(dockerCli)
if err != nil { if err != nil {
return err return err
} }
stacks := make([]*formatter.Stack, 0, len(ss))
stacks = append(stacks, ss...) stacks = append(stacks, ss...)
return format(dockerCli, opts, stacks) return format(dockerCli, opts, stacks)
} }
func format(dockerCli command.Cli, opts options.List, stacks []*formatter.Stack) error { func format(dockerCli command.Cli, opts options.List, stacks []*formatter.Stack) error {
format := formatter.Format(opts.Format) fmt := formatter.Format(opts.Format)
if format == "" || format == formatter.TableFormatKey { if fmt == "" || fmt == formatter.TableFormatKey {
format = formatter.SwarmStackTableFormat fmt = formatter.SwarmStackTableFormat
} }
stackCtx := formatter.Context{ stackCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: format, Format: fmt,
} }
sort.Slice(stacks, func(i, j int) bool { sort.Slice(stacks, func(i, j int) bool {
return sortorder.NaturalLess(stacks[i].Name, stacks[j].Name) || return sortorder.NaturalLess(stacks[i].Name, stacks[j].Name) ||

View File

@ -23,7 +23,7 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackName(opts.Namespace); err != nil { if err := validateStackName(opts.Namespace); err != nil {
return err return err
} }
return RunPs(dockerCli, cmd.Flags(), opts) return swarm.RunPS(dockerCli, opts)
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete) return completeNames(dockerCli)(cmd, args, toComplete)
@ -38,7 +38,9 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command {
return cmd return cmd
} }
// RunPs performs a stack ps against the specified swarm cluster // RunPs performs a stack ps against the specified swarm cluster.
func RunPs(dockerCli command.Cli, flags *pflag.FlagSet, opts options.PS) error { //
// Deprecated: use [swarm.RunPS] instead.
func RunPs(dockerCli command.Cli, _ *pflag.FlagSet, opts options.PS) error {
return swarm.RunPS(dockerCli, opts) return swarm.RunPS(dockerCli, opts)
} }

View File

@ -22,7 +22,7 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackNames(opts.Namespaces); err != nil { if err := validateStackNames(opts.Namespaces); err != nil {
return err return err
} }
return RunRemove(dockerCli, cmd.Flags(), opts) return swarm.RunRemove(dockerCli, opts)
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete) return completeNames(dockerCli)(cmd, args, toComplete)
@ -31,7 +31,9 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
return cmd return cmd
} }
// RunRemove performs a stack remove against the specified swarm cluster // RunRemove performs a stack remove against the specified swarm cluster.
func RunRemove(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Remove) error { //
// Deprecated: use [swarm.RunRemove] instead.
func RunRemove(dockerCli command.Cli, _ *pflag.FlagSet, opts options.Remove) error {
return swarm.RunRemove(dockerCli, opts) return swarm.RunRemove(dockerCli, opts)
} }

View File

@ -30,7 +30,7 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackName(opts.Namespace); err != nil { if err := validateStackName(opts.Namespace); err != nil {
return err return err
} }
return RunServices(dockerCli, cmd.Flags(), opts) return RunServices(dockerCli, opts)
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete) return completeNames(dockerCli)(cmd, args, toComplete)
@ -44,16 +44,18 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
} }
// RunServices performs a stack services against the specified swarm cluster // RunServices performs a stack services against the specified swarm cluster
func RunServices(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Services) error { func RunServices(dockerCli command.Cli, opts options.Services) error {
services, err := GetServices(dockerCli, flags, opts) services, err := swarm.GetServices(dockerCli, opts)
if err != nil { if err != nil {
return err return err
} }
return formatWrite(dockerCli, services, opts) return formatWrite(dockerCli, services, opts)
} }
// GetServices returns the services for the specified swarm cluster // GetServices returns the services for the specified swarm cluster.
func GetServices(dockerCli command.Cli, flags *pflag.FlagSet, opts options.Services) ([]swarmtypes.Service, error) { //
// Deprecated: use [swarm.GetServices] instead.
func GetServices(dockerCli command.Cli, _ *pflag.FlagSet, opts options.Services) ([]swarmtypes.Service, error) {
return swarm.GetServices(dockerCli, opts) return swarm.GetServices(dockerCli, opts)
} }