forked from gexclaude/aaregurucli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AareGuru.go
63 lines (54 loc) · 1.64 KB
/
AareGuru.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
package main
import (
"./api"
"./console"
"./outstd"
"./outtypewrt"
"./texts"
"fmt"
"gopkg.in/alecthomas/kingpin.v2"
"os"
"sync"
)
var (
app = kingpin.New("aareguru", texts.CliDescription)
standard = app.Command("standard", texts.CliCommandStandardDescription).Default()
typewriter = app.Command("schribmaschine", texts.CliCommandTypewriterDescription)
proxy = app.Flag("proxy", texts.CliProxyDescription).Short('p').String()
colorless = app.Flag("ohni-farb", texts.CliColorlessDescription).Short('f').Bool()
noprogressbar = app.Flag("ohni-ladebauke", texts.CliNoprogressbarDescription).Short('l').Bool()
debug = app.Flag("debug", texts.CliProxyDescription).Short('d').Hidden().Bool()
)
func main() {
kingpin.MustParse(app.Parse(os.Args[1:]))
console.InitConsole(!*colorless)
console.ClearConsole()
fmt.Println()
aareGuruResponseChannel := make(chan api.AareGuruResponse)
errChannel := make(chan string)
var wg sync.WaitGroup
defer func() {
if r := recover(); r != nil {
fmt.Println()
fmt.Println(console.CRed(texts.ErrorDetailMsg))
fmt.Println(r)
fmt.Println()
fmt.Print(texts.ErrorHintsMsg)
fmt.Print()
}
console.BeforeExitConsole()
}()
go func() {
defer wg.Done()
wg.Add(1)
api.AskAareGuru(proxy, aareGuruResponseChannel, errChannel, *debug)
}()
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case standard.FullCommand():
outstd.Init(!*noprogressbar)
outstd.RenderAareGuruResponse(aareGuruResponseChannel, errChannel, &wg)
case typewriter.FullCommand():
outtypewrt.Init()
outtypewrt.RenderAareGuruResponse(aareGuruResponseChannel, errChannel, &wg)
}
}