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

- use Println to print newline instead of custom format
- use apiClient instead of client for the API client to
  prevent shadowing imports.
- 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:41:10 +01:00
parent 886f2295cf
commit 35e74d58e3
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 9 additions and 9 deletions

View File

@ -24,14 +24,14 @@ func newDemoteCommand(dockerCli command.Cli) *cobra.Command {
func runDemote(ctx context.Context, dockerCli command.Cli, nodes []string) error {
demote := func(node *swarm.Node) error {
if node.Spec.Role == swarm.NodeRoleWorker {
fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID)
_, _ = fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID)
return errNoRoleChange
}
node.Spec.Role = swarm.NodeRoleWorker
return nil
}
success := func(nodeID string) {
fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
_, _ = fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
}
return updateNodes(ctx, dockerCli, nodes, demote, success)
}

View File

@ -24,14 +24,14 @@ func newPromoteCommand(dockerCli command.Cli) *cobra.Command {
func runPromote(ctx context.Context, dockerCli command.Cli, nodes []string) error {
promote := func(node *swarm.Node) error {
if node.Spec.Role == swarm.NodeRoleManager {
fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID)
_, _ = fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID)
return errNoRoleChange
}
node.Spec.Role = swarm.NodeRoleManager
return nil
}
success := func(nodeID string) {
fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID)
_, _ = fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID)
}
return updateNodes(ctx, dockerCli, nodes, promote, success)
}

View File

@ -33,18 +33,18 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runRemove(ctx context.Context, dockerCli command.Cli, args []string, opts removeOptions) error {
client := dockerCli.Client()
func runRemove(ctx context.Context, dockerCLI command.Cli, nodeIDs []string, opts removeOptions) error {
apiClient := dockerCLI.Client()
var errs []string
for _, nodeID := range args {
err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force})
for _, id := range nodeIDs {
err := apiClient.NodeRemove(ctx, id, types.NodeRemoveOptions{Force: opts.force})
if err != nil {
errs = append(errs, err.Error())
continue
}
fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID)
_, _ = fmt.Fprintln(dockerCLI.Out(), id)
}
if len(errs) > 0 {