forked from sourcegraph/zoekt
/
main.go
60 lines (49 loc) · 1.94 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Command zoekt-archive-index indexes an archive.
//
// Example via github.com:
//
// zoekt-archive-index -incremental -commit b57cb1605fd11ba2ecfa7f68992b4b9cc791934d -name github.com/gorilla/mux -strip_components 1 https://codeload.github.com/gorilla/mux/legacy.tar.gz/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d
//
// zoekt-archive-index -branch master https://github.com/gorilla/mux/commit/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d
package main
import (
"flag"
"log"
"github.com/xvandish/zoekt/cmd"
"github.com/xvandish/zoekt/internal/archive"
"go.uber.org/automaxprocs/maxprocs"
)
func main() {
var (
incremental = flag.Bool("incremental", true, "only index changed repositories")
name = flag.String("name", "", "The repository name for the archive")
urlRaw = flag.String("url", "", "The repository URL for the archive")
branch = flag.String("branch", "", "The branch name for the archive")
commit = flag.String("commit", "", "The commit sha for the archive. If incremental this will avoid updating shards already at commit")
strip = flag.Int("strip_components", 0, "Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped.")
downloadLimitMbps = flag.Int64("download-limit-mbps", 0, "If non-zero, limit archive downloads to specified amount in megabits per second")
)
flag.Parse()
// Tune GOMAXPROCS to match Linux container CPU quota.
_, _ = maxprocs.Set()
log.SetFlags(log.LstdFlags | log.Lshortfile)
if len(flag.Args()) != 1 {
log.Fatal("expected argument for archive location")
}
archiveURL := flag.Args()[0]
bopts := cmd.OptionsFromFlags()
opts := archive.Options{
Incremental: *incremental,
Archive: archiveURL,
Name: *name,
RepoURL: *urlRaw,
Branch: *branch,
Commit: *commit,
Strip: *strip,
}
// Sourcegraph specific: Limit HTTP traffic
limitHTTPDefaultClient(*downloadLimitMbps)
if err := archive.Index(opts, *bopts); err != nil {
log.Fatal(err)
}
}