-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
115 lines (92 loc) · 2.15 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
// "bufio"
"flag"
"fmt"
"log"
"os"
// "strings"
"time"
"github.com/mitchellh/colorstring"
)
func main() {
t := time.Now()
flag.Usage = usage
flag.Parse()
once(t)
//wait for the rewrite of the configfile.
g_wg.Wait()
}
func once(t time.Time) int {
query.set(os.Args[1:])
count := lookup()
//test
//log.Println("in once", count)
if check_return(count) {
log.Println("======== find sum(", count, ") finished in", time.Since(t), "========")
}
return 0
}
func lookup() int {
c_main_query <- query.pkg
cnt := <-c_scan_main
return int(cnt)
}
func check_return(count int) bool {
//if find nothing, new_storage will scan the goroot && gopaths again with newest data
if count == 0 && findpkgs == 0 {
g_st = new_storage()
count = lookup()
if count != 0 {
g_wg.Add(1)
g_st.rewrite = true
c_storage_rewrite <- true
return true
}
fmt.Fprintln(query.out,
colorstring.Color(fmt.Sprintf("[yellow]can't find [red]%q [yellow]in the GOROOT && GOPATHS", query.pkg)))
rcmd := g_st.recomand(query.pkg)
if rcmd != nil {
fmt.Fprintln(query.out, colorstring.Color("[cyan]it maybe to be:"))
for k, v := range rcmd {
fmt.Fprintf(query.out, colorstring.Color(fmt.Sprintf("[green]%q\t[yellow]----%s\n", diff(query.pkg, v.name), v.path)))
if k > 10 {
break
}
}
}
return false
}
return true
}
// func more() int {
// var r = bufio.NewReader(os.Stdin)
// var line string
// var err error
// for {
// if query.out == nil {
// fmt.Print(">>>")
// } else {
// fmt.Fprint(query.out, ">>>")
// }
// line, err = r.ReadString('\n')
// if err != nil {
// log.Println(err)
// continue
// }
// if len(line) == 0 {
// continue
// }
// if strings.TrimSpace(line) == "q" || strings.TrimSpace(line) == "quit" {
// return 0
// }
// args := strings.Fields(line)
// query.set(args)
// log.Println(query.pkg, query.name)
// cout := lookup()
// if check_return(cout) {
// fmt.Fprintln(query.out, "find sum(", cout, ")")
// }
// }
// return 0
// }