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