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:
parent
886f2295cf
commit
35e74d58e3
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user