cli: Workaround for ps's argument

Currently, ps command can not support argument:
(But following usage is in manual)
 | # ./runc ps 123 -ef
 | Incorrect Usage.
 |
 | NAME:
 |    runc ps - ps displays the processes running inside a container
 |
 | USAGE:
 |    runc ps [command options] <container-id> [ps options]
 |
 | OPTIONS:
 |    --format value, -f value  select one of: table or json
 |
 | flag provided but not defined: -ef
 | #

Instead of using odd command like:
 | # ./runc ps -- 123 -ef

We can make it seems little better:
 | # ./runc ps 123 -- -ef
 | UID        PID  PPID  C STIME TTY          TIME CMD
 | root     29046 29038  0 11:18 pts/2    00:00:00 sh
 | #

This patch also fixed manual which can not working in current
code.

Closes #788

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
This commit is contained in:
Zhao Lei 2016-07-06 11:46:22 +08:00
parent 7221e38782
commit f5a95fa244
2 changed files with 5 additions and 2 deletions

View File

@ -2,7 +2,7 @@
runc ps - ps displays the processes running inside a container runc ps - ps displays the processes running inside a container
# SYNOPSIS # SYNOPSIS
runc ps [command options] <container-id> [ps options] runc ps [command options] <container-id> [-- ps options]
# OPTIONS # OPTIONS
--format value, -f value select one of: table(default) or json --format value, -f value select one of: table(default) or json

5
ps.go
View File

@ -16,7 +16,7 @@ import (
var psCommand = cli.Command{ var psCommand = cli.Command{
Name: "ps", Name: "ps",
Usage: "ps displays the processes running inside a container", Usage: "ps displays the processes running inside a container",
ArgsUsage: `<container-id> [ps options]`, ArgsUsage: `<container-id> [-- ps options]`,
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "format, f", Name: "format, f",
@ -43,6 +43,9 @@ var psCommand = cli.Command{
} }
psArgs := context.Args().Get(1) psArgs := context.Args().Get(1)
if psArgs == "--" {
psArgs = context.Args().Get(2)
}
if psArgs == "" { if psArgs == "" {
psArgs = "-ef" psArgs = "-ef"
} }