Skip to content

Commit a5f4ba0

Browse files
committed
cli/command/config: deprecate exported types and functions
These were exported in f60369d to be used in docker enterprise, but this never happened, and there's no known consumers of these, so we should deprecate these. External consumers can still call the API-client directly, which should've been the correct thing to do in the first place. This deprecates: - `RunConfigCreate` and `CreateOptions` - `RunConfigInspect` and `InspectOptions` - `RunConfigList` and `ListOptions` - `RunConfigRemove` and `RemoveOptions` Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 09cd4ea commit a5f4ba0

File tree

4 files changed

+112
-45
lines changed

4 files changed

+112
-45
lines changed

‎cli/command/config/create.go‎

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,78 @@ import (
1616
)
1717

1818
// CreateOptions specifies some options that are used when creating a config.
19+
//
20+
// Deprecated: this type was for internal use and will be removed in the next release.
1921
type CreateOptions struct {
2022
Name string
2123
TemplateDriver string
2224
File string
2325
Labels opts.ListOpts
2426
}
2527

26-
func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
27-
createOpts := CreateOptions{
28-
Labels: opts.NewListOpts(opts.ValidateLabel),
28+
// createOptions specifies some options that are used when creating a config.
29+
type createOptions struct {
30+
name string
31+
templateDriver string
32+
file string
33+
labels opts.ListOpts
34+
}
35+
36+
func newConfigCreateCommand(dockerCLI command.Cli) *cobra.Command {
37+
createOpts := createOptions{
38+
labels: opts.NewListOpts(opts.ValidateLabel),
2939
}
3040

3141
cmd := &cobra.Command{
3242
Use: "create [OPTIONS] CONFIG file|-",
3343
Short: "Create a config from a file or STDIN",
3444
Args: cli.ExactArgs(2),
3545
RunE: func(cmd *cobra.Command, args []string) error {
36-
createOpts.Name = args[0]
37-
createOpts.File = args[1]
38-
return RunConfigCreate(cmd.Context(), dockerCli, createOpts)
46+
createOpts.name = args[0]
47+
createOpts.file = args[1]
48+
return runCreate(cmd.Context(), dockerCLI, createOpts)
3949
},
4050
ValidArgsFunction: completion.NoComplete,
4151
}
4252
flags := cmd.Flags()
43-
flags.VarP(&createOpts.Labels, "label", "l", "Config labels")
44-
flags.StringVar(&createOpts.TemplateDriver, "template-driver", "", "Template driver")
45-
flags.SetAnnotation("template-driver", "version", []string{"1.37"})
53+
flags.VarP(&createOpts.labels, "label", "l", "Config labels")
54+
flags.StringVar(&createOpts.templateDriver, "template-driver", "", "Template driver")
55+
_ = flags.SetAnnotation("template-driver", "version", []string{"1.37"})
4656

4757
return cmd
4858
}
4959

5060
// RunConfigCreate creates a config with the given options.
61+
//
62+
// Deprecated: this function was for internal use and will be removed in the next release.
5163
func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateOptions) error {
64+
return runCreate(ctx, dockerCLI, createOptions{
65+
name: options.Name,
66+
templateDriver: options.TemplateDriver,
67+
file: options.File,
68+
labels: options.Labels,
69+
})
70+
}
71+
72+
// runCreate creates a config with the given options.
73+
func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error {
5274
apiClient := dockerCLI.Client()
5375

54-
configData, err := readConfigData(dockerCLI.In(), options.File)
76+
configData, err := readConfigData(dockerCLI.In(), options.file)
5577
if err != nil {
56-
return fmt.Errorf("error reading content from %q: %v", options.File, err)
78+
return fmt.Errorf("error reading content from %q: %v", options.file, err)
5779
}
5880

5981
spec := swarm.ConfigSpec{
6082
Annotations: swarm.Annotations{
61-
Name: options.Name,
62-
Labels: opts.ConvertKVStringsToMap(options.Labels.GetSlice()),
83+
Name: options.name,
84+
Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
6385
},
6486
Data: configData,
6587
}
66-
if options.TemplateDriver != "" {
88+
if options.templateDriver != "" {
6789
spec.Templating = &swarm.Driver{
68-
Name: options.TemplateDriver,
90+
Name: options.templateDriver,
6991
}
7092
}
7193
r, err := apiClient.ConfigCreate(ctx, spec)

‎cli/command/config/inspect.go‎

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,76 @@ import (
1616
)
1717

1818
// InspectOptions contains options for the docker config inspect command.
19+
//
20+
// Deprecated: this type was for internal use and will be removed in the next release.
1921
type InspectOptions struct {
2022
Names []string
2123
Format string
2224
Pretty bool
2325
}
2426

25-
func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command {
26-
opts := InspectOptions{}
27+
// inspectOptions contains options for the docker config inspect command.
28+
type inspectOptions struct {
29+
names []string
30+
format string
31+
pretty bool
32+
}
33+
34+
func newConfigInspectCommand(dockerCLI command.Cli) *cobra.Command {
35+
opts := inspectOptions{}
2736
cmd := &cobra.Command{
2837
Use: "inspect [OPTIONS] CONFIG [CONFIG...]",
2938
Short: "Display detailed information on one or more configs",
3039
Args: cli.RequiresMinArgs(1),
3140
RunE: func(cmd *cobra.Command, args []string) error {
32-
opts.Names = args
33-
return RunConfigInspect(cmd.Context(), dockerCli, opts)
41+
opts.names = args
42+
return runInspect(cmd.Context(), dockerCLI, opts)
3443
},
3544
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
36-
return completeNames(dockerCli)(cmd, args, toComplete)
45+
return completeNames(dockerCLI)(cmd, args, toComplete)
3746
},
3847
}
3948

40-
cmd.Flags().StringVarP(&opts.Format, "format", "f", "", flagsHelper.InspectFormatHelp)
41-
cmd.Flags().BoolVar(&opts.Pretty, "pretty", false, "Print the information in a human friendly format")
49+
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
50+
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
4251
return cmd
4352
}
4453

4554
// RunConfigInspect inspects the given Swarm config.
55+
//
56+
// Deprecated: this function was for internal use and will be removed in the next release.
4657
func RunConfigInspect(ctx context.Context, dockerCLI command.Cli, opts InspectOptions) error {
58+
return runInspect(ctx, dockerCLI, inspectOptions{
59+
names: opts.Names,
60+
format: opts.Format,
61+
pretty: opts.Pretty,
62+
})
63+
}
64+
65+
// runInspect inspects the given Swarm config.
66+
func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
4767
apiClient := dockerCLI.Client()
4868

49-
if opts.Pretty {
50-
opts.Format = "pretty"
69+
if opts.pretty {
70+
opts.format = "pretty"
5171
}
5272

5373
getRef := func(id string) (any, []byte, error) {
5474
return apiClient.ConfigInspectWithRaw(ctx, id)
5575
}
56-
f := opts.Format
5776

5877
// check if the user is trying to apply a template to the pretty format, which
5978
// is not supported
60-
if strings.HasPrefix(f, "pretty") && f != "pretty" {
79+
if strings.HasPrefix(opts.format, "pretty") && opts.format != "pretty" {
6180
return errors.New("cannot supply extra formatting options to the pretty template")
6281
}
6382

6483
configCtx := formatter.Context{
6584
Output: dockerCLI.Out(),
66-
Format: newFormat(f, false),
85+
Format: newFormat(opts.format, false),
6786
}
6887

69-
if err := inspectFormatWrite(configCtx, opts.Names, getRef); err != nil {
88+
if err := inspectFormatWrite(configCtx, opts.names, getRef); err != nil {
7089
return cli.StatusError{StatusCode: 1, Status: err.Error()}
7190
}
7291
return nil

‎cli/command/config/ls.go‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,66 @@ import (
1616
)
1717

1818
// ListOptions contains options for the docker config ls command.
19+
//
20+
// Deprecated: this type was for internal use and will be removed in the next release.
1921
type ListOptions struct {
2022
Quiet bool
2123
Format string
2224
Filter opts.FilterOpt
2325
}
2426

25-
func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
26-
listOpts := ListOptions{Filter: opts.NewFilterOpt()}
27+
// listOptions contains options for the docker config ls command.
28+
type listOptions struct {
29+
quiet bool
30+
format string
31+
filter opts.FilterOpt
32+
}
33+
34+
func newConfigListCommand(dockerCLI command.Cli) *cobra.Command {
35+
listOpts := listOptions{filter: opts.NewFilterOpt()}
2736

2837
cmd := &cobra.Command{
2938
Use: "ls [OPTIONS]",
3039
Aliases: []string{"list"},
3140
Short: "List configs",
3241
Args: cli.NoArgs,
3342
RunE: func(cmd *cobra.Command, args []string) error {
34-
return RunConfigList(cmd.Context(), dockerCli, listOpts)
43+
return runList(cmd.Context(), dockerCLI, listOpts)
3544
},
3645
ValidArgsFunction: completion.NoComplete,
3746
}
3847

3948
flags := cmd.Flags()
40-
flags.BoolVarP(&listOpts.Quiet, "quiet", "q", false, "Only display IDs")
41-
flags.StringVar(&listOpts.Format, "format", "", flagsHelper.FormatHelp)
42-
flags.VarP(&listOpts.Filter, "filter", "f", "Filter output based on conditions provided")
49+
flags.BoolVarP(&listOpts.quiet, "quiet", "q", false, "Only display IDs")
50+
flags.StringVar(&listOpts.format, "format", "", flagsHelper.FormatHelp)
51+
flags.VarP(&listOpts.filter, "filter", "f", "Filter output based on conditions provided")
4352

4453
return cmd
4554
}
4655

4756
// RunConfigList lists Swarm configs.
57+
//
58+
// Deprecated: this function was for internal use and will be removed in the next release.
4859
func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptions) error {
60+
return runList(ctx, dockerCLI, listOptions{
61+
quiet: options.Quiet,
62+
format: options.Format,
63+
filter: options.Filter,
64+
})
65+
}
66+
67+
// runList lists Swarm configs.
68+
func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error {
4969
apiClient := dockerCLI.Client()
5070

51-
configs, err := apiClient.ConfigList(ctx, swarm.ConfigListOptions{Filters: options.Filter.Value()})
71+
configs, err := apiClient.ConfigList(ctx, swarm.ConfigListOptions{Filters: options.filter.Value()})
5272
if err != nil {
5373
return err
5474
}
5575

56-
format := options.Format
76+
format := options.format
5777
if len(format) == 0 {
58-
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
78+
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.quiet {
5979
format = dockerCLI.ConfigFile().ConfigFormat
6080
} else {
6181
format = formatter.TableFormatKey
@@ -68,7 +88,7 @@ func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptio
6888

6989
configCtx := formatter.Context{
7090
Output: dockerCLI.Out(),
71-
Format: newFormat(format, options.Quiet),
91+
Format: newFormat(format, options.quiet),
7292
}
7393
return formatWrite(configCtx, configs)
7494
}

‎cli/command/config/remove.go‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,40 @@ import (
1111
)
1212

1313
// RemoveOptions contains options for the docker config rm command.
14+
//
15+
// Deprecated: this type was for internal use and will be removed in the next release.
1416
type RemoveOptions struct {
1517
Names []string
1618
}
1719

18-
func newConfigRemoveCommand(dockerCli command.Cli) *cobra.Command {
20+
func newConfigRemoveCommand(dockerCLI command.Cli) *cobra.Command {
1921
return &cobra.Command{
2022
Use: "rm CONFIG [CONFIG...]",
2123
Aliases: []string{"remove"},
2224
Short: "Remove one or more configs",
2325
Args: cli.RequiresMinArgs(1),
2426
RunE: func(cmd *cobra.Command, args []string) error {
25-
opts := RemoveOptions{
26-
Names: args,
27-
}
28-
return RunConfigRemove(cmd.Context(), dockerCli, opts)
27+
return runRemove(cmd.Context(), dockerCLI, args)
2928
},
3029
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
31-
return completeNames(dockerCli)(cmd, args, toComplete)
30+
return completeNames(dockerCLI)(cmd, args, toComplete)
3231
},
3332
}
3433
}
3534

3635
// RunConfigRemove removes the given Swarm configs.
36+
//
37+
// Deprecated: this function was for internal use and will be removed in the next release.
3738
func RunConfigRemove(ctx context.Context, dockerCLI command.Cli, opts RemoveOptions) error {
39+
return runRemove(ctx, dockerCLI, opts.Names)
40+
}
41+
42+
// runRemove removes the given Swarm configs.
43+
func runRemove(ctx context.Context, dockerCLI command.Cli, names []string) error {
3844
apiClient := dockerCLI.Client()
3945

4046
var errs []error
41-
for _, name := range opts.Names {
47+
for _, name := range names {
4248
if err := apiClient.ConfigRemove(ctx, name); err != nil {
4349
errs = append(errs, err)
4450
continue

0 commit comments

Comments
 (0)