github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/swarm/leave.go (about) 1 package swarm 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/docker/cli/cli" 8 "github.com/docker/cli/cli/command" 9 "github.com/docker/cli/cli/command/completion" 10 "github.com/spf13/cobra" 11 ) 12 13 type leaveOptions struct { 14 force bool 15 } 16 17 func newLeaveCommand(dockerCli command.Cli) *cobra.Command { 18 opts := leaveOptions{} 19 20 cmd := &cobra.Command{ 21 Use: "leave [OPTIONS]", 22 Short: "Leave the swarm", 23 Args: cli.NoArgs, 24 RunE: func(cmd *cobra.Command, args []string) error { 25 return runLeave(cmd.Context(), dockerCli, opts) 26 }, 27 Annotations: map[string]string{ 28 "version": "1.24", 29 "swarm": "active", 30 }, 31 ValidArgsFunction: completion.NoComplete, 32 } 33 34 flags := cmd.Flags() 35 flags.BoolVarP(&opts.force, "force", "f", false, "Force this node to leave the swarm, ignoring warnings") 36 return cmd 37 } 38 39 func runLeave(ctx context.Context, dockerCli command.Cli, opts leaveOptions) error { 40 client := dockerCli.Client() 41 42 if err := client.SwarmLeave(ctx, opts.force); err != nil { 43 return err 44 } 45 46 fmt.Fprintln(dockerCli.Out(), "Node left the swarm.") 47 return nil 48 }