Files
docker-cli/cli/command/service/remove.go
Sebastiaan van Stijn f1193effc0 cli/command/service: use errors.Join
Use stdlib multi-errors instead of creating our own

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-03 19:36:59 +01:00

44 lines
1.0 KiB
Go

package service
import (
"context"
"errors"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
)
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "rm SERVICE [SERVICE...]",
Aliases: []string{"remove"},
Short: "Remove one or more services",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runRemove(cmd.Context(), dockerCli, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return CompletionFn(dockerCli)(cmd, args, toComplete)
},
}
cmd.Flags()
return cmd
}
func runRemove(ctx context.Context, dockerCLI command.Cli, serviceIDs []string) error {
apiClient := dockerCLI.Client()
var errs []error
for _, id := range serviceIDs {
if err := apiClient.ServiceRemove(ctx, id); err != nil {
errs = append(errs, err)
continue
}
_, _ = fmt.Fprintln(dockerCLI.Out(), id)
}
return errors.Join(errs...)
}