github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/node/promote.go (about) 1 package node 2 3 import ( 4 "fmt" 5 6 "github.com/docker/cli/cli" 7 "github.com/docker/cli/cli/command" 8 "github.com/docker/docker/api/types/swarm" 9 "github.com/spf13/cobra" 10 ) 11 12 func newPromoteCommand(dockerCli command.Cli) *cobra.Command { 13 return &cobra.Command{ 14 Use: "promote NODE [NODE...]", 15 Short: "Promote one or more nodes to manager in the swarm", 16 Args: cli.RequiresMinArgs(1), 17 RunE: func(cmd *cobra.Command, args []string) error { 18 return runPromote(dockerCli, args) 19 }, 20 } 21 } 22 23 func runPromote(dockerCli command.Cli, nodes []string) error { 24 promote := func(node *swarm.Node) error { 25 if node.Spec.Role == swarm.NodeRoleManager { 26 fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID) 27 return errNoRoleChange 28 } 29 node.Spec.Role = swarm.NodeRoleManager 30 return nil 31 } 32 success := func(nodeID string) { 33 fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID) 34 } 35 return updateNodes(dockerCli, nodes, promote, success) 36 }