Files
docker-cli/cli/command/swarm/leave.go
Sebastiaan van Stijn 139968dff2 cli/command/completion: deprecate NoComplete
This function was an exact duplicate of [cobra.NoFileCompletions], so
deprecating it in favor of that.

[cobra.NoFileCompletions]: https://pkg.go.dev/github.com/spf13/cobra@v1.9.1#NoFileCompletions

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 2827d037ba)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-30 12:24:11 +02:00

48 lines
1.0 KiB
Go

package swarm
import (
"context"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
)
type leaveOptions struct {
force bool
}
func newLeaveCommand(dockerCli command.Cli) *cobra.Command {
opts := leaveOptions{}
cmd := &cobra.Command{
Use: "leave [OPTIONS]",
Short: "Leave the swarm",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runLeave(cmd.Context(), dockerCli, opts)
},
Annotations: map[string]string{
"version": "1.24",
"swarm": "active",
},
ValidArgsFunction: cobra.NoFileCompletions,
}
flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Force this node to leave the swarm, ignoring warnings")
return cmd
}
func runLeave(ctx context.Context, dockerCLI command.Cli, opts leaveOptions) error {
apiClient := dockerCLI.Client()
if err := apiClient.SwarmLeave(ctx, opts.force); err != nil {
return err
}
_, _ = fmt.Fprintln(dockerCLI.Out(), "Node left the swarm.")
return nil
}