MCPcopy
hub / github.com/google/codesearch / Main

Function Main

cmd/csearch/csearch.go:58–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56)
57
58func Main() {
59 g := regexp.Grep{
60 Stdout: os.Stdout,
61 Stderr: os.Stderr,
62 }
63 g.AddFlags()
64
65 flag.Usage = usage
66 flag.Parse()
67 args := flag.Args()
68
69 if len(args) != 1 {
70 usage()
71 }
72
73 if *cpuProfile != "" {
74 f, err := os.Create(*cpuProfile)
75 if err != nil {
76 log.Fatal(err)
77 }
78 defer f.Close()
79 pprof.StartCPUProfile(f)
80 defer pprof.StopCPUProfile()
81 }
82
83 pat := "(?m)" + args[0]
84 if *iFlag {
85 pat = "(?i)" + pat
86 }
87 re, err := regexp.Compile(pat)
88 if err != nil {
89 log.Fatal(err)
90 }
91 g.Regexp = re
92 var fre *regexp.Regexp
93 if *fFlag != "" {
94 fre, err = regexp.Compile(*fFlag)
95 if err != nil {
96 log.Fatal(err)
97 }
98 }
99 q := index.RegexpQuery(re.Syntax)
100 if *verboseFlag {
101 log.Printf("query: %s\n", q)
102 }
103
104 ix := index.Open(index.File())
105 ix.Verbose = *verboseFlag
106 var post []uint32
107 if *bruteFlag {
108 post = ix.PostingQuery(&index.Query{Op: index.QAll})
109 } else {
110 post = ix.PostingQuery(q)
111 }
112 if *verboseFlag {
113 log.Printf("post query identified %d possible files\n", len(post))
114 }
115

Callers 1

mainFunction · 0.85

Calls 10

AddFlagsMethod · 0.95
MatchStringMethod · 0.95
FileMethod · 0.95
CompileFunction · 0.92
RegexpQueryFunction · 0.92
OpenFunction · 0.92
FileFunction · 0.92
PostingQueryMethod · 0.80
NameMethod · 0.80
usageFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…