mirror of https://github.com/docker/cli.git
cli/command/config: deprecate exported types and functions
These were exported inf60369dfe6to 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 <github@gone.nl> (cherry picked from commita5f4ba08d9) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
6f7865f89a
commit
e60b20f08e
|
|
@ -16,6 +16,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateOptions specifies some options that are used when creating a config.
|
// CreateOptions specifies some options that are used when creating a config.
|
||||||
|
//
|
||||||
|
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||||
type CreateOptions struct {
|
type CreateOptions struct {
|
||||||
Name string
|
Name string
|
||||||
TemplateDriver string
|
TemplateDriver string
|
||||||
|
|
@ -23,9 +25,17 @@ type CreateOptions struct {
|
||||||
Labels opts.ListOpts
|
Labels opts.ListOpts
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
|
// createOptions specifies some options that are used when creating a config.
|
||||||
createOpts := CreateOptions{
|
type createOptions struct {
|
||||||
Labels: opts.NewListOpts(opts.ValidateLabel),
|
name string
|
||||||
|
templateDriver string
|
||||||
|
file string
|
||||||
|
labels opts.ListOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConfigCreateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||||
|
createOpts := createOptions{
|
||||||
|
labels: opts.NewListOpts(opts.ValidateLabel),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
|
@ -33,39 +43,51 @@ func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Create a config from a file or STDIN",
|
Short: "Create a config from a file or STDIN",
|
||||||
Args: cli.ExactArgs(2),
|
Args: cli.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
createOpts.Name = args[0]
|
createOpts.name = args[0]
|
||||||
createOpts.File = args[1]
|
createOpts.file = args[1]
|
||||||
return RunConfigCreate(cmd.Context(), dockerCli, createOpts)
|
return runCreate(cmd.Context(), dockerCLI, createOpts)
|
||||||
},
|
},
|
||||||
ValidArgsFunction: completion.NoComplete,
|
ValidArgsFunction: completion.NoComplete,
|
||||||
}
|
}
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.VarP(&createOpts.Labels, "label", "l", "Config labels")
|
flags.VarP(&createOpts.labels, "label", "l", "Config labels")
|
||||||
flags.StringVar(&createOpts.TemplateDriver, "template-driver", "", "Template driver")
|
flags.StringVar(&createOpts.templateDriver, "template-driver", "", "Template driver")
|
||||||
flags.SetAnnotation("template-driver", "version", []string{"1.37"})
|
_ = flags.SetAnnotation("template-driver", "version", []string{"1.37"})
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunConfigCreate creates a config with the given options.
|
// RunConfigCreate creates a config with the given options.
|
||||||
|
//
|
||||||
|
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||||
func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateOptions) error {
|
func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateOptions) error {
|
||||||
|
return runCreate(ctx, dockerCLI, createOptions{
|
||||||
|
name: options.Name,
|
||||||
|
templateDriver: options.TemplateDriver,
|
||||||
|
file: options.File,
|
||||||
|
labels: options.Labels,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// runCreate creates a config with the given options.
|
||||||
|
func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error {
|
||||||
apiClient := dockerCLI.Client()
|
apiClient := dockerCLI.Client()
|
||||||
|
|
||||||
configData, err := readConfigData(dockerCLI.In(), options.File)
|
configData, err := readConfigData(dockerCLI.In(), options.file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("Error reading content from %q: %v", options.File, err)
|
return errors.Errorf("Error reading content from %q: %v", options.file, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
spec := swarm.ConfigSpec{
|
spec := swarm.ConfigSpec{
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: options.Name,
|
Name: options.name,
|
||||||
Labels: opts.ConvertKVStringsToMap(options.Labels.GetSlice()),
|
Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
|
||||||
},
|
},
|
||||||
Data: configData,
|
Data: configData,
|
||||||
}
|
}
|
||||||
if options.TemplateDriver != "" {
|
if options.templateDriver != "" {
|
||||||
spec.Templating = &swarm.Driver{
|
spec.Templating = &swarm.Driver{
|
||||||
Name: options.TemplateDriver,
|
Name: options.templateDriver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r, err := apiClient.ConfigCreate(ctx, spec)
|
r, err := apiClient.ConfigCreate(ctx, spec)
|
||||||
|
|
|
||||||
|
|
@ -16,57 +16,76 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// InspectOptions contains options for the docker config inspect command.
|
// InspectOptions contains options for the docker config inspect command.
|
||||||
|
//
|
||||||
|
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||||
type InspectOptions struct {
|
type InspectOptions struct {
|
||||||
Names []string
|
Names []string
|
||||||
Format string
|
Format string
|
||||||
Pretty bool
|
Pretty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command {
|
// inspectOptions contains options for the docker config inspect command.
|
||||||
opts := InspectOptions{}
|
type inspectOptions struct {
|
||||||
|
names []string
|
||||||
|
format string
|
||||||
|
pretty bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConfigInspectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||||
|
opts := inspectOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "inspect [OPTIONS] CONFIG [CONFIG...]",
|
Use: "inspect [OPTIONS] CONFIG [CONFIG...]",
|
||||||
Short: "Display detailed information on one or more configs",
|
Short: "Display detailed information on one or more configs",
|
||||||
Args: cli.RequiresMinArgs(1),
|
Args: cli.RequiresMinArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts.Names = args
|
opts.names = args
|
||||||
return RunConfigInspect(cmd.Context(), dockerCli, opts)
|
return runInspect(cmd.Context(), 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)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringVarP(&opts.Format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
||||||
cmd.Flags().BoolVar(&opts.Pretty, "pretty", false, "Print the information in a human friendly format")
|
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunConfigInspect inspects the given Swarm config.
|
// RunConfigInspect inspects the given Swarm config.
|
||||||
|
//
|
||||||
|
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||||
func RunConfigInspect(ctx context.Context, dockerCLI command.Cli, opts InspectOptions) error {
|
func RunConfigInspect(ctx context.Context, dockerCLI command.Cli, opts InspectOptions) error {
|
||||||
|
return runInspect(ctx, dockerCLI, inspectOptions{
|
||||||
|
names: opts.Names,
|
||||||
|
format: opts.Format,
|
||||||
|
pretty: opts.Pretty,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// runInspect inspects the given Swarm config.
|
||||||
|
func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
|
||||||
apiClient := dockerCLI.Client()
|
apiClient := dockerCLI.Client()
|
||||||
|
|
||||||
if opts.Pretty {
|
if opts.pretty {
|
||||||
opts.Format = "pretty"
|
opts.format = "pretty"
|
||||||
}
|
}
|
||||||
|
|
||||||
getRef := func(id string) (any, []byte, error) {
|
getRef := func(id string) (any, []byte, error) {
|
||||||
return apiClient.ConfigInspectWithRaw(ctx, id)
|
return apiClient.ConfigInspectWithRaw(ctx, id)
|
||||||
}
|
}
|
||||||
f := opts.Format
|
|
||||||
|
|
||||||
// check if the user is trying to apply a template to the pretty format, which
|
// check if the user is trying to apply a template to the pretty format, which
|
||||||
// is not supported
|
// is not supported
|
||||||
if strings.HasPrefix(f, "pretty") && f != "pretty" {
|
if strings.HasPrefix(opts.format, "pretty") && opts.format != "pretty" {
|
||||||
return errors.New("cannot supply extra formatting options to the pretty template")
|
return errors.New("cannot supply extra formatting options to the pretty template")
|
||||||
}
|
}
|
||||||
|
|
||||||
configCtx := formatter.Context{
|
configCtx := formatter.Context{
|
||||||
Output: dockerCLI.Out(),
|
Output: dockerCLI.Out(),
|
||||||
Format: newFormat(f, false),
|
Format: newFormat(opts.format, false),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := inspectFormatWrite(configCtx, opts.Names, getRef); err != nil {
|
if err := inspectFormatWrite(configCtx, opts.names, getRef); err != nil {
|
||||||
return cli.StatusError{StatusCode: 1, Status: err.Error()}
|
return cli.StatusError{StatusCode: 1, Status: err.Error()}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListOptions contains options for the docker config ls command.
|
// ListOptions contains options for the docker config ls command.
|
||||||
|
//
|
||||||
|
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||||
type ListOptions struct {
|
type ListOptions struct {
|
||||||
Quiet bool
|
Quiet bool
|
||||||
Format string
|
Format string
|
||||||
Filter opts.FilterOpt
|
Filter opts.FilterOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
|
// listOptions contains options for the docker config ls command.
|
||||||
listOpts := ListOptions{Filter: opts.NewFilterOpt()}
|
type listOptions struct {
|
||||||
|
quiet bool
|
||||||
|
format string
|
||||||
|
filter opts.FilterOpt
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConfigListCommand(dockerCLI command.Cli) *cobra.Command {
|
||||||
|
listOpts := listOptions{filter: opts.NewFilterOpt()}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "ls [OPTIONS]",
|
Use: "ls [OPTIONS]",
|
||||||
|
|
@ -31,31 +40,42 @@ func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "List configs",
|
Short: "List configs",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return RunConfigList(cmd.Context(), dockerCli, listOpts)
|
return runList(cmd.Context(), dockerCLI, listOpts)
|
||||||
},
|
},
|
||||||
ValidArgsFunction: completion.NoComplete,
|
ValidArgsFunction: completion.NoComplete,
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.BoolVarP(&listOpts.Quiet, "quiet", "q", false, "Only display IDs")
|
flags.BoolVarP(&listOpts.quiet, "quiet", "q", false, "Only display IDs")
|
||||||
flags.StringVar(&listOpts.Format, "format", "", flagsHelper.FormatHelp)
|
flags.StringVar(&listOpts.format, "format", "", flagsHelper.FormatHelp)
|
||||||
flags.VarP(&listOpts.Filter, "filter", "f", "Filter output based on conditions provided")
|
flags.VarP(&listOpts.filter, "filter", "f", "Filter output based on conditions provided")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunConfigList lists Swarm configs.
|
// RunConfigList lists Swarm configs.
|
||||||
|
//
|
||||||
|
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||||
func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptions) error {
|
func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptions) error {
|
||||||
|
return runList(ctx, dockerCLI, listOptions{
|
||||||
|
quiet: options.Quiet,
|
||||||
|
format: options.Format,
|
||||||
|
filter: options.Filter,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// runList lists Swarm configs.
|
||||||
|
func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error {
|
||||||
apiClient := dockerCLI.Client()
|
apiClient := dockerCLI.Client()
|
||||||
|
|
||||||
configs, err := apiClient.ConfigList(ctx, swarm.ConfigListOptions{Filters: options.Filter.Value()})
|
configs, err := apiClient.ConfigList(ctx, swarm.ConfigListOptions{Filters: options.filter.Value()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
format := options.Format
|
format := options.format
|
||||||
if len(format) == 0 {
|
if len(format) == 0 {
|
||||||
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
|
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.quiet {
|
||||||
format = dockerCLI.ConfigFile().ConfigFormat
|
format = dockerCLI.ConfigFile().ConfigFormat
|
||||||
} else {
|
} else {
|
||||||
format = formatter.TableFormatKey
|
format = formatter.TableFormatKey
|
||||||
|
|
@ -68,7 +88,7 @@ func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptio
|
||||||
|
|
||||||
configCtx := formatter.Context{
|
configCtx := formatter.Context{
|
||||||
Output: dockerCLI.Out(),
|
Output: dockerCLI.Out(),
|
||||||
Format: newFormat(format, options.Quiet),
|
Format: newFormat(format, options.quiet),
|
||||||
}
|
}
|
||||||
return formatWrite(configCtx, configs)
|
return formatWrite(configCtx, configs)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,34 +11,40 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// RemoveOptions contains options for the docker config rm command.
|
// RemoveOptions contains options for the docker config rm command.
|
||||||
|
//
|
||||||
|
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||||
type RemoveOptions struct {
|
type RemoveOptions struct {
|
||||||
Names []string
|
Names []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfigRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
func newConfigRemoveCommand(dockerCLI command.Cli) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "rm CONFIG [CONFIG...]",
|
Use: "rm CONFIG [CONFIG...]",
|
||||||
Aliases: []string{"remove"},
|
Aliases: []string{"remove"},
|
||||||
Short: "Remove one or more configs",
|
Short: "Remove one or more configs",
|
||||||
Args: cli.RequiresMinArgs(1),
|
Args: cli.RequiresMinArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts := RemoveOptions{
|
return runRemove(cmd.Context(), dockerCLI, args)
|
||||||
Names: args,
|
|
||||||
}
|
|
||||||
return RunConfigRemove(cmd.Context(), 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)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunConfigRemove removes the given Swarm configs.
|
// RunConfigRemove removes the given Swarm configs.
|
||||||
|
//
|
||||||
|
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||||
func RunConfigRemove(ctx context.Context, dockerCLI command.Cli, opts RemoveOptions) error {
|
func RunConfigRemove(ctx context.Context, dockerCLI command.Cli, opts RemoveOptions) error {
|
||||||
|
return runRemove(ctx, dockerCLI, opts.Names)
|
||||||
|
}
|
||||||
|
|
||||||
|
// runRemove removes the given Swarm configs.
|
||||||
|
func runRemove(ctx context.Context, dockerCLI command.Cli, names []string) error {
|
||||||
apiClient := dockerCLI.Client()
|
apiClient := dockerCLI.Client()
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, name := range opts.Names {
|
for _, name := range names {
|
||||||
if err := apiClient.ConfigRemove(ctx, name); err != nil {
|
if err := apiClient.ConfigRemove(ctx, name); err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue