Merge pull request #752 from stevvooe/ctr-list-quiet

cmd/ctr: add quiet mode to `ctr list`
This commit is contained in:
Stephen Day 2017-04-24 13:46:58 -05:00 committed by GitHub
commit ce72a829c7

View File

@ -13,7 +13,14 @@ import (
var listCommand = cli.Command{ var listCommand = cli.Command{
Name: "list", Name: "list",
Usage: "list containers", Usage: "list containers",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "print only the container id",
},
},
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
quiet := context.Bool("quiet")
containers, err := getExecutionService(context) containers, err := getExecutionService(context)
if err != nil { if err != nil {
return err return err
@ -22,6 +29,12 @@ var listCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
if quiet {
for _, c := range response.Containers {
fmt.Println(c.ID)
}
} else {
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0) w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tPID\tSTATUS") fmt.Fprintln(w, "ID\tPID\tSTATUS")
for _, c := range response.Containers { for _, c := range response.Containers {
@ -36,6 +49,8 @@ var listCommand = cli.Command{
return err return err
} }
} }
}
return nil return nil
}, },
} }