forked from monochromegane/the_platinum_searcher
/
main.go
46 lines (36 loc) · 792 Bytes
/
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
package main
import (
flags "github.com/jessevdk/go-flags"
"github.com/monochromegane/the_platinum_searcher/search"
"github.com/monochromegane/the_platinum_searcher/search/option"
terminal "github.com/pebbe/util"
"os"
"runtime"
)
var opts option.Option
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
parser := flags.NewParser(&opts, flags.Default)
args, err := parser.Parse()
if err != nil {
os.Exit(1)
}
parser.Name = "pt"
parser.Usage = "[OPTIONS] PATTERN [PATH]"
if !terminal.IsTerminal(os.Stdout) {
opts.NoColor = true
opts.NoGroup = true
}
if len(args) == 0 {
parser.WriteHelp(os.Stdout)
os.Exit(1)
}
var root = "."
if len(args) == 2 {
root = args[1]
}
searcher := search.Searcher{root, args[0], &opts}
searcher.Search()
}