github.com/kobeld/docker@v1.12.0-rc1/api/client/node/cmd.go (about) 1 package node 2 3 import ( 4 "fmt" 5 6 "golang.org/x/net/context" 7 8 "github.com/spf13/cobra" 9 10 "github.com/docker/docker/api/client" 11 "github.com/docker/docker/cli" 12 apiclient "github.com/docker/engine-api/client" 13 ) 14 15 // NewNodeCommand returns a cobra command for `node` subcommands 16 func NewNodeCommand(dockerCli *client.DockerCli) *cobra.Command { 17 cmd := &cobra.Command{ 18 Use: "node", 19 Short: "Manage Docker Swarm nodes", 20 Args: cli.NoArgs, 21 Run: func(cmd *cobra.Command, args []string) { 22 fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) 23 }, 24 } 25 cmd.AddCommand( 26 newAcceptCommand(dockerCli), 27 newDemoteCommand(dockerCli), 28 newInspectCommand(dockerCli), 29 newListCommand(dockerCli), 30 newPromoteCommand(dockerCli), 31 newRemoveCommand(dockerCli), 32 newTasksCommand(dockerCli), 33 newUpdateCommand(dockerCli), 34 ) 35 return cmd 36 } 37 38 func nodeReference(client apiclient.APIClient, ctx context.Context, ref string) (string, error) { 39 // The special value "self" for a node reference is mapped to the current 40 // node, hence the node ID is retrieved using the `/info` endpoint. 41 if ref == "self" { 42 info, err := client.Info(ctx) 43 if err != nil { 44 return "", err 45 } 46 return info.Swarm.NodeID, nil 47 } 48 return ref, nil 49 }