Skip to content

Commit 7367714

Browse files
committed
cli/command/stack: internalize GetConfigDetails, LoadComposefile
These were deprecated in ad6ab18 and were only used internally. Move them back inside the stack package. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent be97096 commit 7367714

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

cli/command/stack/config.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@ import (
66

77
"github.com/docker/cli/cli"
88
"github.com/docker/cli/cli/command"
9-
"github.com/docker/cli/cli/command/stack/loader"
10-
"github.com/docker/cli/cli/command/stack/options"
119
composeLoader "github.com/docker/cli/cli/compose/loader"
1210
composetypes "github.com/docker/cli/cli/compose/types"
1311
"github.com/spf13/cobra"
1412
"gopkg.in/yaml.v3"
1513
)
1614

15+
// configOptions holds docker stack config options
16+
type configOptions struct {
17+
composeFiles []string
18+
skipInterpolation bool
19+
}
20+
1721
func newConfigCommand(dockerCLI command.Cli) *cobra.Command {
18-
var opts options.Config
22+
var opts configOptions
1923

2024
cmd := &cobra.Command{
2125
Use: "config [OPTIONS]",
2226
Short: "Outputs the final config file, after doing merges and interpolations",
2327
Args: cli.NoArgs,
2428
RunE: func(cmd *cobra.Command, args []string) error {
25-
configDetails, err := loader.GetConfigDetails(opts.Composefiles, dockerCLI.In())
29+
configDetails, err := getConfigDetails(opts.composeFiles, dockerCLI.In())
2630
if err != nil {
2731
return err
2832
}
2933

30-
cfg, err := outputConfig(configDetails, opts.SkipInterpolation)
34+
cfg, err := outputConfig(configDetails, opts.skipInterpolation)
3135
if err != nil {
3236
return err
3337
}
@@ -40,8 +44,8 @@ func newConfigCommand(dockerCLI command.Cli) *cobra.Command {
4044
}
4145

4246
flags := cmd.Flags()
43-
flags.StringSliceVarP(&opts.Composefiles, "compose-file", "c", []string{}, `Path to a Compose file, or "-" to read from stdin`)
44-
flags.BoolVar(&opts.SkipInterpolation, "skip-interpolation", false, "Skip interpolation and output only merged config")
47+
flags.StringSliceVarP(&opts.composeFiles, "compose-file", "c", []string{}, `Path to a Compose file, or "-" to read from stdin`)
48+
flags.BoolVar(&opts.skipInterpolation, "skip-interpolation", false, "Skip interpolation and output only merged config")
4549
return cmd
4650
}
4751

cli/command/stack/deploy.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package stack
33
import (
44
"github.com/docker/cli/cli"
55
"github.com/docker/cli/cli/command"
6-
"github.com/docker/cli/cli/command/stack/loader"
76
"github.com/docker/cli/cli/command/stack/options"
87
"github.com/docker/cli/cli/command/stack/swarm"
98
"github.com/spf13/cobra"
@@ -22,7 +21,7 @@ func newDeployCommand(dockerCLI command.Cli) *cobra.Command {
2221
if err := validateStackName(opts.Namespace); err != nil {
2322
return err
2423
}
25-
config, err := loader.LoadComposefile(dockerCLI, opts)
24+
config, err := loadComposeFile(dockerCLI, opts)
2625
if err != nil {
2726
return err
2827
}
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
22
//go:build go1.23
33

4-
package loader
4+
package stack
55

66
import (
77
"fmt"
@@ -21,11 +21,9 @@ import (
2121
"github.com/pkg/errors"
2222
)
2323

24-
// LoadComposefile parse the composefile specified in the cli and returns its Config and version.
25-
//
26-
// Deprecated: this function was for internal use and will be removed in the next release.
27-
func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.Config, error) {
28-
configDetails, err := GetConfigDetails(opts.Composefiles, dockerCli.In())
24+
// loadComposeFile parse the composefile specified in the cli and returns its configOptions and version.
25+
func loadComposeFile(streams command.Streams, opts options.Deploy) (*composetypes.Config, error) {
26+
configDetails, err := getConfigDetails(opts.Composefiles, streams.In())
2927
if err != nil {
3028
return nil, err
3129
}
@@ -43,13 +41,13 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.
4341

4442
unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
4543
if len(unsupportedProperties) > 0 {
46-
_, _ = fmt.Fprintf(dockerCli.Err(), "Ignoring unsupported options: %s\n\n",
44+
_, _ = fmt.Fprintf(streams.Err(), "Ignoring unsupported options: %s\n\n",
4745
strings.Join(unsupportedProperties, ", "))
4846
}
4947

5048
deprecatedProperties := loader.GetDeprecatedProperties(dicts...)
5149
if len(deprecatedProperties) > 0 {
52-
_, _ = fmt.Fprintf(dockerCli.Err(), "Ignoring deprecated options:\n\n%s\n\n",
50+
_, _ = fmt.Fprintf(streams.Err(), "Ignoring deprecated options:\n\n%s\n\n",
5351
propertyWarnings(deprecatedProperties))
5452
}
5553

@@ -85,10 +83,8 @@ func propertyWarnings(properties map[string]string) string {
8583
return strings.Join(msgs, "\n\n")
8684
}
8785

88-
// GetConfigDetails parse the composefiles specified in the cli and returns their ConfigDetails
89-
//
90-
// Deprecated: this function was for internal use and will be removed in the next release.
91-
func GetConfigDetails(composefiles []string, stdin io.Reader) (composetypes.ConfigDetails, error) {
86+
// getConfigDetails parse the composefiles specified in the cli and returns their ConfigDetails
87+
func getConfigDetails(composefiles []string, stdin io.Reader) (composetypes.ConfigDetails, error) {
9288
var details composetypes.ConfigDetails
9389

9490
if len(composefiles) == 0 {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package loader
1+
package stack
22

33
import (
44
"os"
@@ -22,7 +22,7 @@ services:
2222
file := fs.NewFile(t, "test-get-config-details", fs.WithContent(content))
2323
defer file.Remove()
2424

25-
details, err := GetConfigDetails([]string{file.Path()}, nil)
25+
details, err := getConfigDetails([]string{file.Path()}, nil)
2626
assert.NilError(t, err)
2727
assert.Check(t, is.Equal(filepath.Dir(file.Path()), details.WorkingDir))
2828
assert.Assert(t, is.Len(details.ConfigFiles, 1))
@@ -37,7 +37,7 @@ services:
3737
foo:
3838
image: alpine:3.5
3939
`
40-
details, err := GetConfigDetails([]string{"-"}, strings.NewReader(content))
40+
details, err := getConfigDetails([]string{"-"}, strings.NewReader(content))
4141
assert.NilError(t, err)
4242
cwd, err := os.Getwd()
4343
assert.NilError(t, err)

cli/command/stack/options/opts.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ type Deploy struct {
1313
Quiet bool
1414
}
1515

16-
// Config holds docker stack config options
17-
//
18-
// Deprecated: this type was for internal use and will be removed in the next release.
19-
type Config struct {
20-
Composefiles []string
21-
SkipInterpolation bool
22-
}
23-
2416
// Remove holds docker stack remove options
2517
//
2618
// Deprecated: this type was for internal use and will be removed in the next release.

0 commit comments

Comments
 (0)