diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index 4ec1b30085..1b4831d43a 100644 --- a/cli/command/stack/list.go +++ b/cli/command/stack/list.go @@ -16,8 +16,10 @@ import ( "github.com/spf13/cobra" ) +type listOptions = options.List + func newListCommand(dockerCli command.Cli) *cobra.Command { - opts := options.List{} + opts := listOptions{} cmd := &cobra.Command{ Use: "ls [OPTIONS]", @@ -25,7 +27,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { Short: "List stacks", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return RunList(cmd.Context(), dockerCli, opts) + return runList(cmd.Context(), dockerCli, opts) }, ValidArgsFunction: completion.NoComplete, } @@ -36,17 +38,24 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { } // RunList performs a stack list against the specified swarm cluster -func RunList(ctx context.Context, dockerCli command.Cli, opts options.List) error { - ss, err := swarm.GetStacks(ctx, dockerCli.Client()) +// +// Deprecated: this function was for internal use and will be removed in the next release. +func RunList(ctx context.Context, dockerCLI command.Cli, opts options.List) error { + return runList(ctx, dockerCLI, opts) +} + +// runList performs a stack list against the specified swarm cluster +func runList(ctx context.Context, dockerCLI command.Cli, opts listOptions) error { + ss, err := swarm.GetStacks(ctx, dockerCLI.Client()) if err != nil { return err } stacks := make([]*formatter.Stack, 0, len(ss)) stacks = append(stacks, ss...) - return format(dockerCli.Out(), opts, stacks) + return format(dockerCLI.Out(), opts, stacks) } -func format(out io.Writer, opts options.List, stacks []*formatter.Stack) error { +func format(out io.Writer, opts listOptions, stacks []*formatter.Stack) error { fmt := formatter.Format(opts.Format) if fmt == "" || fmt == formatter.TableFormatKey { fmt = formatter.SwarmStackTableFormat diff --git a/cli/command/stack/services.go b/cli/command/stack/services.go index f91ba71edf..cdeac2a2b9 100644 --- a/cli/command/stack/services.go +++ b/cli/command/stack/services.go @@ -18,8 +18,11 @@ import ( "github.com/spf13/cobra" ) -func newServicesCommand(dockerCli command.Cli) *cobra.Command { - opts := options.Services{Filter: cliopts.NewFilterOpt()} +// servicesOptions holds docker stack services options +type servicesOptions = options.Services + +func newServicesCommand(dockerCLI command.Cli) *cobra.Command { + opts := servicesOptions{Filter: cliopts.NewFilterOpt()} cmd := &cobra.Command{ Use: "services [OPTIONS] STACK", @@ -30,10 +33,10 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command { if err := validateStackName(opts.Namespace); err != nil { return err } - return RunServices(cmd.Context(), dockerCli, opts) + return runServices(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() @@ -44,15 +47,22 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command { } // RunServices performs a stack services against the specified swarm cluster -func RunServices(ctx context.Context, dockerCli command.Cli, opts options.Services) error { - services, err := swarm.GetServices(ctx, dockerCli, opts) +// +// Deprecated: this function was for internal use and will be removed in the next release. +func RunServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) error { + return runServices(ctx, dockerCLI, opts) +} + +// runServices performs a stack services against the specified swarm cluster +func runServices(ctx context.Context, dockerCLI command.Cli, opts servicesOptions) error { + services, err := swarm.GetServices(ctx, dockerCLI, opts) if err != nil { return err } - return formatWrite(dockerCli, services, opts) + return formatWrite(dockerCLI, services, opts) } -func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts options.Services) error { +func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts servicesOptions) error { // if no services in the stack, print message and exit 0 if len(services) == 0 { _, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.Namespace)