Skip to content

Commit 35e74d5

Browse files
committed
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>
1 parent 886f229 commit 35e74d5

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

cli/command/node/demote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func newDemoteCommand(dockerCli command.Cli) *cobra.Command {
2424
func runDemote(ctx context.Context, dockerCli command.Cli, nodes []string) error {
2525
demote := func(node *swarm.Node) error {
2626
if node.Spec.Role == swarm.NodeRoleWorker {
27-
fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID)
27+
_, _ = fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID)
2828
return errNoRoleChange
2929
}
3030
node.Spec.Role = swarm.NodeRoleWorker
3131
return nil
3232
}
3333
success := func(nodeID string) {
34-
fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
34+
_, _ = fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID)
3535
}
3636
return updateNodes(ctx, dockerCli, nodes, demote, success)
3737
}

cli/command/node/promote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func newPromoteCommand(dockerCli command.Cli) *cobra.Command {
2424
func runPromote(ctx context.Context, dockerCli command.Cli, nodes []string) error {
2525
promote := func(node *swarm.Node) error {
2626
if node.Spec.Role == swarm.NodeRoleManager {
27-
fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID)
27+
_, _ = fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID)
2828
return errNoRoleChange
2929
}
3030
node.Spec.Role = swarm.NodeRoleManager
3131
return nil
3232
}
3333
success := func(nodeID string) {
34-
fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID)
34+
_, _ = fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID)
3535
}
3636
return updateNodes(ctx, dockerCli, nodes, promote, success)
3737
}

cli/command/node/remove.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
3333
return cmd
3434
}
3535

36-
func runRemove(ctx context.Context, dockerCli command.Cli, args []string, opts removeOptions) error {
37-
client := dockerCli.Client()
36+
func runRemove(ctx context.Context, dockerCLI command.Cli, nodeIDs []string, opts removeOptions) error {
37+
apiClient := dockerCLI.Client()
3838

3939
var errs []string
4040

41-
for _, nodeID := range args {
42-
err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force})
41+
for _, id := range nodeIDs {
42+
err := apiClient.NodeRemove(ctx, id, types.NodeRemoveOptions{Force: opts.force})
4343
if err != nil {
4444
errs = append(errs, err.Error())
4545
continue
4646
}
47-
fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID)
47+
_, _ = fmt.Fprintln(dockerCLI.Out(), id)
4848
}
4949

5050
if len(errs) > 0 {

0 commit comments

Comments
 (0)