From 39bc87d2738ddf3885f1007480a4d258d49f9ce9 Mon Sep 17 00:00:00 2001 From: aviau Date: Mon, 4 Jan 2021 23:03:14 -0500 Subject: [PATCH] cmd/pk/list: filter by type --- cmd/pk/list.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/pk/list.go b/cmd/pk/list.go index f0efc5c0a..200d8f301 100644 --- a/cmd/pk/list.go +++ b/cmd/pk/list.go @@ -34,8 +34,9 @@ import ( type listCmd struct { *syncCmd - describe bool // whether to describe each blob. - cl *client.Client // client used for the describe requests. + describe bool // whether to describe each blob. + camliType string // filter by schema blob type + cl *client.Client // client used for the describe requests. } func init() { @@ -44,10 +45,12 @@ func init() { syncCmd: &syncCmd{ dest: "stdout", }, - describe: false, + describe: false, + camliType: "", } flags.StringVar(&cmd.syncCmd.src, "src", "", "Source blobserver is either a URL prefix (with optional path), a host[:port], a path (starting with /, ./, or ../), or blank to use the Perkeep client config's default host.") - flags.BoolVar(&cmd.describe, "describe", false, "Use describe requests to get each blob's type. Requires a source server with a search endpoint. Mostly used for demos. Requires many extra round-trips to the server currently.") + flags.BoolVar(&cmd.describe, "describe", false, "Use describe requests to get each schema blob's type. Requires a source server with a search endpoint. Mostly used for demos. Requires many extra round-trips to the server currently.") + flags.StringVar(&cmd.camliType, "type", "", "Filter by schema blob type. Empty string means no filter. Implies -describe.") return cmd }) } @@ -67,6 +70,8 @@ func (c *listCmd) Examples() []string { } func (c *listCmd) RunCommand(args []string) error { + c.describe = c.describe || c.camliType != "" + if !c.describe { return c.syncCmd.RunCommand(args) } @@ -113,11 +118,14 @@ func (c *listCmd) RunCommand(args []string) error { fmt.Fprintf(stdout, "%v \n", v) continue } - detailed := detail(blob) - if detailed != "" { - detailed = fmt.Sprintf("\t%v", detailed) + + if c.camliType == "" || blob.CamliType == c.camliType { + detailed := detail(blob) + if detailed != "" { + detailed = fmt.Sprintf("\t%v", detailed) + } + fmt.Fprintf(stdout, "%v %v%v\n", v, blob.Size, detailed) } - fmt.Fprintf(stdout, "%v %v%v\n", v, blob.Size, detailed) } blobRefs = make([]blob.Ref, 0, describeBatchSize) return nil