aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd
diff options
context:
space:
mode:
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++
}
}