Files
containerd/cmd/dist/list.go
Derek McGowan 6d032b99f2 Rename CommittedAt to CreatedAt in content interface
Use "created at" terminology to be consistent with the rest
of the containerd interfaces.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 16:51:16 -07:00

74 lines
1.5 KiB
Go

package main
import (
"fmt"
"os"
"strings"
"text/tabwriter"
"time"
"github.com/containerd/containerd/content"
units "github.com/docker/go-units"
"github.com/urfave/cli"
)
var listCommand = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "list all blobs in the store.",
ArgsUsage: "[flags] [<filter>, ...]",
Description: `List blobs in the content store.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "print only the blob digest",
},
},
Action: func(context *cli.Context) error {
var (
quiet = context.Bool("quiet")
args = []string(context.Args())
)
ctx, cancel := appContext(context)
defer cancel()
cs, err := resolveContentStore(context)
if err != nil {
return err
}
var walkFn content.WalkFunc
if quiet {
walkFn = func(info content.Info) error {
fmt.Println(info.Digest)
return nil
}
} else {
tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
defer tw.Flush()
fmt.Fprintln(tw, "DIGEST\tSIZE\tAGE\tLABELS")
walkFn = func(info content.Info) error {
var labelStrings []string
for k, v := range info.Labels {
labelStrings = append(labelStrings, strings.Join([]string{k, v}, "="))
}
labels := strings.Join(labelStrings, ",")
if labels == "" {
labels = "-"
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n",
info.Digest,
units.HumanSize(float64(info.Size)),
units.HumanDuration(time.Since(info.CreatedAt)),
labels)
return nil
}
}
return cs.Walk(ctx, walkFn, args...)
},
}