Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/zoekt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main
import (
"bytes"
"context"
"encoding/json"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -54,6 +55,13 @@ func displayMatches(files []zoekt.FileMatch, pat string, withRepo bool, list boo
}
}

func displayMatchesJSONL(files []zoekt.FileMatch) {
encoder := json.NewEncoder(os.Stdout)
for _, f := range files {
encoder.Encode(f)
}
}

func addTabIfNonEmpty(s string) string {
if s != "" {
return "\t" + s
Expand Down Expand Up @@ -165,6 +173,7 @@ func main() {
verbose := flag.Bool("v", false, "print some background data")
withRepo := flag.Bool("r", false, "print the repo before the file name")
list := flag.Bool("l", false, "print matching filenames only")
jsonl := flag.Bool("jsonl", false, "print results in jsonl format")
sym := flag.Bool("sym", false, "do experimental symbol search")

flag.Usage = func() {
Expand Down Expand Up @@ -229,7 +238,12 @@ func main() {
sres, _ = searcher.Search(context.Background(), q, &sOpts)
}

displayMatches(sres.Files, pat, *withRepo, *list)
if *jsonl {
displayMatchesJSONL(sres.Files)
} else {
displayMatches(sres.Files, pat, *withRepo, *list)
}

if *verbose {
log.Printf("stats: %#v", sres.Stats)
}
Expand Down
Loading