aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-06-25 16:34:00 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-06-25 16:34:00 +0200
commit76fe5414ccc51a2ab7f02f7b55c3251760f5f934 (patch)
tree3a86e3dc36c9d0d3295972a759bb3e06fe234cf5 /skate/cmd
parent426af6950afe0b25c5428cefee953ec345321319 (diff)
downloadrefcat-76fe5414ccc51a2ab7f02f7b55c3251760f5f934.tar.gz
refcat-76fe5414ccc51a2ab7f02f7b55c3251760f5f934.zip
cdx tweaks
Diffstat (limited to 'skate/cmd')
-rw-r--r--skate/cmd/skate-cdx-lookup/main.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/skate/cmd/skate-cdx-lookup/main.go b/skate/cmd/skate-cdx-lookup/main.go
index a6fc5f9..1bfbdb8 100644
--- a/skate/cmd/skate-cdx-lookup/main.go
+++ b/skate/cmd/skate-cdx-lookup/main.go
@@ -2,6 +2,7 @@ package main
import (
"bufio"
+ "encoding/json"
"flag"
"fmt"
"io"
@@ -20,6 +21,7 @@ var (
sleep = flag.Duration("s", 200*time.Millisecond, "sleep between requests")
cacheDir = flag.String("c", path.Join(xdg.CacheHome, "skate-cdx"), "cache dir")
bestEffort = flag.Bool("B", false, "best effort")
+ writeJson = flag.Bool("j", false, "json output")
quiet = flag.Bool("q", false, "no logging")
)
@@ -79,7 +81,25 @@ func main() {
log.Fatal(err)
}
}
- fmt.Printf("[%05d] % 10d %s %s\n", i, len(rows), rows.Summary(), line)
+ if *writeJson {
+ cdxSummary := rows.Summary()
+ var dummy = struct {
+ Summary *skate.CDXSummary `json:"summary"`
+ NumRows int `json:"numRows"`
+ Line string `json:"line"`
+ }{
+ Summary: cdxSummary,
+ NumRows: len(rows),
+ Line: line,
+ }
+ b, err := json.Marshal(dummy)
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Println(string(b))
+ } else {
+ fmt.Printf("[%05d] % 10d %s %s\n", i, len(rows), rows.Summary(), line)
+ }
i++
}
}