make node ps default to self in swarm node

Signed-off-by: allencloud <allen.sun@daocloud.io>
Upstream-commit: b13f5dfd130a69b0eb655d349b7839f12a9384ed
Component: engine
This commit is contained in:
allencloud
2016-07-29 17:20:59 +08:00
parent 4cd762346d
commit 37e3bbaff0
9 changed files with 21 additions and 16 deletions

View File

@ -19,16 +19,21 @@ type psOptions struct {
filter opts.FilterOpt
}
func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
func newPsCommand(dockerCli *client.DockerCli) *cobra.Command {
opts := psOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "ps [OPTIONS] self|NODE",
Short: "List tasks running on a node",
Args: cli.ExactArgs(1),
Use: "ps [OPTIONS] [NODE]",
Short: "List tasks running on a node, defaults to current node",
Args: cli.RequiresRangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.nodeID = args[0]
return runPS(dockerCli, opts)
opts.nodeID = "self"
if len(args) != 0 {
opts.nodeID = args[0]
}
return runPs(dockerCli, opts)
},
}
flags := cmd.Flags()
@ -39,7 +44,7 @@ func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
return cmd
}
func runPS(dockerCli *client.DockerCli, opts psOptions) error {
func runPs(dockerCli *client.DockerCli, opts psOptions) error {
client := dockerCli.Client()
ctx := context.Background()