-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (53 loc) · 1.11 KB
/
main.go
File metadata and controls
63 lines (53 loc) · 1.11 KB
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
package main
import (
"flag"
"fmt"
"os"
"simpledict/dict"
"sync"
"github.com/fatih/color"
)
func printUsage() {
fmt.Println("Usage: simpledict [flags] <word>")
}
func main() {
args := os.Args
if len(args) < 2 {
printUsage()
os.Exit(1)
}
word := args[len(args)-1]
// flags
syn := flag.Bool("syn", false, "show synonyms")
flag.Parse()
// run all dicts
{
dicts := getAllDicts()
// results := make(map[*string]*dict.Result) // store results used for final printing
wg := new(sync.WaitGroup)
for i := range *dicts {
wg.Add(1)
go func(d *dict.Dict) {
defer wg.Done()
r, err := runDict(&word, d)
if err != nil {
return
}
// results[(*d).GetName()] = r // final printing
c := color.New(color.BgHiGreen, color.FgBlack, color.Underline)
c.Printf("Source: %s\n", *(*d).GetName())
printResult(r, syn)
fmt.Println("")
}(&(*dicts)[i])
}
wg.Wait()
/* final printing
for name, r := range results {
c := color.New(color.BgHiGreen, color.FgBlack, color.Underline)
c.Printf("Source: %s\n", *name)
printResult(r, syn)
fmt.Println("")
}
*/
}
}