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