github.com/portworx/docker@v1.12.1/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 newDemoteCommand(dockerCli), 27 newInspectCommand(dockerCli), 28 newListCommand(dockerCli), 29 newPromoteCommand(dockerCli), 30 newRemoveCommand(dockerCli), 31 newPSCommand(dockerCli), 32 newUpdateCommand(dockerCli), 33 ) 34 return cmd 35 } 36 37 // Reference returns the reference of a node. The special value "self" for a node 38 // reference is mapped to the current node, hence the node ID is retrieved using 39 // the `/info` endpoint. 40 func Reference(client apiclient.APIClient, ctx context.Context, ref string) (string, error) { 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 }