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,20 +29,28 @@ var listCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tPID\tSTATUS") if quiet {
for _, c := range response.Containers { for _, c := range response.Containers {
if _, err := fmt.Fprintf(w, "%s\t%d\t%s\n", fmt.Println(c.ID)
c.ID,
c.Pid,
c.Status.String(),
); err != nil {
return err
} }
if err := w.Flush(); err != nil { } else {
return err w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tPID\tSTATUS")
for _, c := range response.Containers {
if _, err := fmt.Fprintf(w, "%s\t%d\t%s\n",
c.ID,
c.Pid,
c.Status.String(),
); err != nil {
return err
}
if err := w.Flush(); err != nil {
return err
}
} }
} }
return nil return nil
}, },
} }