Files
docker-cli/cli/command/swarm/leave.go
Sebastiaan van Stijn 0adaf6be3b verify that DisableFlagsInUseLine is set for all commands
This replaces the visitAll recursive function with a test that verifies that
the option is set for all commands and subcommands, so that it doesn't have
to be modified at runtime.

We currently still have to loop over all functions for the setValidateArgs
call, but that can be looked at separately.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 09:39:46 +02:00

49 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,
DisableFlagsInUseLine: true,
}
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
}