cli/command/stack: minor cleanups: use Println, rename vars

- use Println to print newline instead of custom format
- use dockerCLI with Go's standard camelCase casing.
- suppress some errors to make my IDE and linters happier

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-02-01 22:56:30 +01:00
parent aa74f931d3
commit 925b8fe34c
5 changed files with 51 additions and 51 deletions

View File

@ -52,28 +52,28 @@ func RunServices(ctx context.Context, dockerCli command.Cli, opts options.Servic
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 options.Services) error {
// if no services in the stack, print message and exit 0
if len(services) == 0 {
_, _ = fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", opts.Namespace)
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.Namespace)
return nil
}
sort.Slice(services, func(i, j int) bool {
return sortorder.NaturalLess(services[i].Spec.Name, services[j].Spec.Name)
})
format := opts.Format
if len(format) == 0 {
if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !opts.Quiet {
format = dockerCli.ConfigFile().ServicesFormat
f := opts.Format
if len(f) == 0 {
if len(dockerCLI.ConfigFile().ServicesFormat) > 0 && !opts.Quiet {
f = dockerCLI.ConfigFile().ServicesFormat
} else {
format = formatter.TableFormatKey
f = formatter.TableFormatKey
}
}
servicesCtx := formatter.Context{
Output: dockerCli.Out(),
Format: service.NewListFormat(format, opts.Quiet),
Output: dockerCLI.Out(),
Format: service.NewListFormat(f, opts.Quiet),
}
return service.ListFormatWrite(servicesCtx, services)
}