diff --git a/.golangci.yml b/.golangci.yml index bf093a63c7ac..1365f9fa3f2b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -222,6 +222,14 @@ linters: linters: - staticcheck + # Ignore deprecation linting for cli/command/stack/*. + # + # FIXME(thaJeztah): remove exception once these functions are un-exported or internal; see https://github.com/docker/cli/pull/6389 + - text: '^(SA1019): ' + path: "cli/command/stack" + linters: + - staticcheck + # Log a warning if an exclusion rule is unused. # Default: false warn-unused: true diff --git a/cli/command/stack/formatter/formatter.go b/cli/command/stack/formatter/formatter.go index 07b322f0616a..7cfe8a89af0f 100644 --- a/cli/command/stack/formatter/formatter.go +++ b/cli/command/stack/formatter/formatter.go @@ -8,21 +8,31 @@ import ( const ( // SwarmStackTableFormat is the default Swarm stack format + // + // Deprecated: this type was for internal use and will be removed in the next release. SwarmStackTableFormat formatter.Format = "table {{.Name}}\t{{.Services}}" stackServicesHeader = "SERVICES" // TableFormatKey is an alias for formatter.TableFormatKey + // + // Deprecated: this type was for internal use and will be removed in the next release. TableFormatKey = formatter.TableFormatKey ) // Context is an alias for formatter.Context +// +// Deprecated: this type was for internal use and will be removed in the next release. type Context = formatter.Context // Format is an alias for formatter.Format +// +// Deprecated: this type was for internal use and will be removed in the next release. type Format = formatter.Format // Stack contains deployed stack information. +// +// Deprecated: this type was for internal use and will be removed in the next release. type Stack struct { // Name is the name of the stack Name string @@ -31,6 +41,8 @@ type Stack struct { } // StackWrite writes formatted stacks using the Context +// +// Deprecated: this function was for internal use and will be removed in the next release. func StackWrite(ctx formatter.Context, stacks []*Stack) error { render := func(format func(subContext formatter.SubContext) error) error { for _, stack := range stacks { diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index 4ec1b30085d4..1b4831d43a9e 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/loader/loader.go b/cli/command/stack/loader/loader.go index 75d485b01464..8187efb5a669 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader/loader.go @@ -22,6 +22,8 @@ import ( ) // LoadComposefile parse the composefile specified in the cli and returns its Config and version. +// +// Deprecated: this function was for internal use and will be removed in the next release. func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.Config, error) { configDetails, err := GetConfigDetails(opts.Composefiles, dockerCli.In()) if err != nil { @@ -84,6 +86,8 @@ func propertyWarnings(properties map[string]string) string { } // GetConfigDetails parse the composefiles specified in the cli and returns their ConfigDetails +// +// Deprecated: this function was for internal use and will be removed in the next release. func GetConfigDetails(composefiles []string, stdin io.Reader) (composetypes.ConfigDetails, error) { var details composetypes.ConfigDetails diff --git a/cli/command/stack/options/opts.go b/cli/command/stack/options/opts.go index 28d4c3262207..bd239e892ffd 100644 --- a/cli/command/stack/options/opts.go +++ b/cli/command/stack/options/opts.go @@ -3,6 +3,8 @@ 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. type Deploy struct { Composefiles []string Namespace string @@ -14,18 +16,24 @@ type Deploy struct { } // Config holds docker stack config options +// +// Deprecated: this type was for internal use and will be removed in the next release. type Config struct { Composefiles []string SkipInterpolation bool } // List holds docker stack ls options +// +// Deprecated: this type was for internal use and will be removed in the next release. type List struct { Format string AllNamespaces 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 @@ -36,12 +44,16 @@ type PS struct { } // Remove holds docker stack remove options +// +// Deprecated: this type was for internal use and will be removed in the next release. type Remove struct { Namespaces []string Detach bool } // Services holds docker stack services options +// +// Deprecated: this type was for internal use and will be removed in the next release. type Services struct { Quiet bool Format string diff --git a/cli/command/stack/services.go b/cli/command/stack/services.go index e1db99532b85..f10cfa310571 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) diff --git a/cli/command/stack/swarm/deploy.go b/cli/command/stack/swarm/deploy.go index ac5ac416c41c..252f42c94d30 100644 --- a/cli/command/stack/swarm/deploy.go +++ b/cli/command/stack/swarm/deploy.go @@ -23,6 +23,8 @@ const ( ) // RunDeploy is the swarm implementation of docker stack deploy +// +// Deprecated: this function was for internal use and will be removed in the next release. func RunDeploy(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *options.Deploy, cfg *composetypes.Config) error { if err := validateResolveImageFlag(opts); err != nil { return err diff --git a/cli/command/stack/swarm/list.go b/cli/command/stack/swarm/list.go index 947302142545..c135b06c17b1 100644 --- a/cli/command/stack/swarm/list.go +++ b/cli/command/stack/swarm/list.go @@ -10,6 +10,8 @@ import ( ) // GetStacks lists the swarm stacks. +// +// Deprecated: this function was for internal use and will be removed in the next release. func GetStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]*formatter.Stack, error) { services, err := apiClient.ServiceList( ctx, diff --git a/cli/command/stack/swarm/ps.go b/cli/command/stack/swarm/ps.go index 4e2596c77126..6d7d2d48a95d 100644 --- a/cli/command/stack/swarm/ps.go +++ b/cli/command/stack/swarm/ps.go @@ -12,6 +12,8 @@ import ( ) // 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) diff --git a/cli/command/stack/swarm/remove.go b/cli/command/stack/swarm/remove.go index c3cb65ae026a..a945f9a57c09 100644 --- a/cli/command/stack/swarm/remove.go +++ b/cli/command/stack/swarm/remove.go @@ -15,6 +15,8 @@ import ( ) // RunRemove is the swarm implementation of docker stack remove +// +// Deprecated: this function was for internal use and will be removed in the next release. func RunRemove(ctx context.Context, dockerCli command.Cli, opts options.Remove) error { apiClient := dockerCli.Client() diff --git a/cli/command/stack/swarm/services.go b/cli/command/stack/swarm/services.go index 652b2629bba4..0cfa062a493a 100644 --- a/cli/command/stack/swarm/services.go +++ b/cli/command/stack/swarm/services.go @@ -11,6 +11,8 @@ import ( ) // GetServices is the swarm implementation of listing stack services +// +// Deprecated: this function was for internal use and will be removed in the next release. func GetServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) ([]swarm.Service, error) { var ( err error