Merge pull request #1332 from sak0/dev

ps: --format value check
This commit is contained in:
Qiang Huang 2017-02-21 11:56:15 -08:00 committed by GitHub
commit 3293874044
1 changed files with 6 additions and 2 deletions

8
ps.go
View File

@ -20,7 +20,7 @@ var psCommand = cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "format, f", Name: "format, f",
Value: "", Value: "table",
Usage: `select one of: ` + formatOptions, Usage: `select one of: ` + formatOptions,
}, },
}, },
@ -38,8 +38,12 @@ var psCommand = cli.Command{
return err return err
} }
if context.String("format") == "json" { switch context.String("format") {
case "table":
case "json":
return json.NewEncoder(os.Stdout).Encode(pids) return json.NewEncoder(os.Stdout).Encode(pids)
default:
return fmt.Errorf("invalid format option")
} }
// [1:] is to remove command name, ex: // [1:] is to remove command name, ex: