Browse code

make node ps default to self in swarm node

Signed-off-by: allencloud <allen.sun@daocloud.io>

allencloud authored on 2016/07/29 18:20:59
Showing 9 changed files
... ...
@@ -28,7 +28,7 @@ func NewNodeCommand(dockerCli *client.DockerCli) *cobra.Command {
28 28
 		newListCommand(dockerCli),
29 29
 		newPromoteCommand(dockerCli),
30 30
 		newRemoveCommand(dockerCli),
31
-		newPSCommand(dockerCli),
31
+		newPsCommand(dockerCli),
32 32
 		newUpdateCommand(dockerCli),
33 33
 	)
34 34
 	return cmd
... ...
@@ -19,16 +19,21 @@ type psOptions struct {
19 19
 	filter    opts.FilterOpt
20 20
 }
21 21
 
22
-func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
22
+func newPsCommand(dockerCli *client.DockerCli) *cobra.Command {
23 23
 	opts := psOptions{filter: opts.NewFilterOpt()}
24 24
 
25 25
 	cmd := &cobra.Command{
26
-		Use:   "ps [OPTIONS] self|NODE",
27
-		Short: "List tasks running on a node",
28
-		Args:  cli.ExactArgs(1),
26
+		Use:   "ps [OPTIONS] [NODE]",
27
+		Short: "List tasks running on a node, defaults to current node",
28
+		Args:  cli.RequiresRangeArgs(0, 1),
29 29
 		RunE: func(cmd *cobra.Command, args []string) error {
30
-			opts.nodeID = args[0]
31
-			return runPS(dockerCli, opts)
30
+			opts.nodeID = "self"
31
+
32
+			if len(args) != 0 {
33
+				opts.nodeID = args[0]
34
+			}
35
+
36
+			return runPs(dockerCli, opts)
32 37
 		},
33 38
 	}
34 39
 	flags := cmd.Flags()
... ...
@@ -39,7 +44,7 @@ func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
39 39
 	return cmd
40 40
 }
41 41
 
42
-func runPS(dockerCli *client.DockerCli, opts psOptions) error {
42
+func runPs(dockerCli *client.DockerCli, opts psOptions) error {
43 43
 	client := dockerCli.Client()
44 44
 	ctx := context.Background()
45 45
 
... ...
@@ -22,7 +22,7 @@ func NewServiceCommand(dockerCli *client.DockerCli) *cobra.Command {
22 22
 	cmd.AddCommand(
23 23
 		newCreateCommand(dockerCli),
24 24
 		newInspectCommand(dockerCli),
25
-		newPSCommand(dockerCli),
25
+		newPsCommand(dockerCli),
26 26
 		newListCommand(dockerCli),
27 27
 		newRemoveCommand(dockerCli),
28 28
 		newScaleCommand(dockerCli),
... ...
@@ -20,7 +20,7 @@ type psOptions struct {
20 20
 	filter    opts.FilterOpt
21 21
 }
22 22
 
23
-func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
23
+func newPsCommand(dockerCli *client.DockerCli) *cobra.Command {
24 24
 	opts := psOptions{filter: opts.NewFilterOpt()}
25 25
 
26 26
 	cmd := &cobra.Command{
... ...
@@ -25,7 +25,7 @@ func NewStackCommand(dockerCli *client.DockerCli) *cobra.Command {
25 25
 		newDeployCommand(dockerCli),
26 26
 		newRemoveCommand(dockerCli),
27 27
 		newServicesCommand(dockerCli),
28
-		newPSCommand(dockerCli),
28
+		newPsCommand(dockerCli),
29 29
 	)
30 30
 	return cmd
31 31
 }
... ...
@@ -25,7 +25,7 @@ type psOptions struct {
25 25
 	noResolve bool
26 26
 }
27 27
 
28
-func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
28
+func newPsCommand(dockerCli *client.DockerCli) *cobra.Command {
29 29
 	opts := psOptions{filter: opts.NewFilterOpt()}
30 30
 
31 31
 	cmd := &cobra.Command{
... ...
@@ -792,7 +792,7 @@ __docker_node_commands() {
792 792
         "ls:List nodes in the swarm"
793 793
         "promote:Promote a node as manager in the swarm"
794 794
         "rm:Remove one or more nodes from the swarm"
795
-        "ps:List tasks running on a node"
795
+        "ps:List tasks running on a node, defaults to current node"
796 796
         "update:Update a node"
797 797
     )
798 798
     _describe -t docker-node-commands "docker node command" _docker_node_subcommands
... ...
@@ -115,7 +115,7 @@ read the [`dockerd`](dockerd.md) reference page.
115 115
 | [node demote](node_demote.md) | Demotes an existing manager so that it is no longer a manager |
116 116
 | [node inspect](node_inspect.md) | Inspect a node in the swarm                |
117 117
 | [node update](node_update.md) | Update attributes for a node                 |
118
-| [node ps](node_ps.md) | List tasks running on a node                   |
118
+| [node ps](node_ps.md) | List tasks running on a node                         |
119 119
 | [node ls](node_ls.md) | List nodes in the swarm                              |
120 120
 | [node rm](node_rm.md) | Remove one or more nodes from the swarm                         |
121 121
 
... ...
@@ -12,9 +12,9 @@ parent = "smn_cli"
12 12
 # node ps
13 13
 
14 14
 ```markdown
15
-Usage:  docker node ps [OPTIONS] self|NODE
15
+Usage:  docker node ps [OPTIONS] [NODE]
16 16
 
17
-List tasks running on a node
17
+List tasks running on a node, defaults to current node.
18 18
 
19 19
 Options:
20 20
   -a, --all            Display all instances