2017-01-13 06:08:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
gocontext "context"
|
|
|
|
"fmt"
|
2017-02-13 18:23:28 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2017-01-13 06:08:09 +00:00
|
|
|
|
2017-02-09 07:31:26 +00:00
|
|
|
"github.com/docker/containerd/api/services/execution"
|
2017-01-13 06:08:09 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var listCommand = cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "list containers",
|
|
|
|
Action: func(context *cli.Context) error {
|
2017-02-13 18:23:28 +00:00
|
|
|
containers, err := getExecutionService(context)
|
2017-01-13 06:08:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
response, err := containers.List(gocontext.Background(), &execution.ListRequest{})
|
2017-01-13 06:08:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
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%s\t%s\n",
|
|
|
|
c.ID,
|
|
|
|
c.Pid,
|
|
|
|
c.Status.String(),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.Flush(); err != nil {
|
2017-01-13 06:08:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|