-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (70 loc) · 1.69 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
package main
import (
"fmt"
"os"
"sync"
"github.com/kavishgr/getghrel/github"
"github.com/kavishgr/getghrel/options"
"github.com/kavishgr/getghrel/utils"
)
func main() {
var (
opts = options.ParseFlags()
skipextraction = opts.SkipExtraction
token = opts.GHToken
tempdir = opts.TempDir
ost, arch = utils.OsInfo()
regex = utils.SetRegex(ost, arch)
stdInUrls = make(chan string)
jobs sync.WaitGroup
version = "0.1.2"
)
if opts.Version {
fmt.Println("getghrel version: ", version)
os.Exit(1)
}
if token == "" {
fmt.Println("GITHUB_TOKEN environment variable is not found.")
fmt.Println("Nor is -ghtoken provided on the command line.")
fmt.Println("")
fmt.Println("Run 'getghrel -h'")
fmt.Println("Or browse to: 'https://github.com/kavishgr/getghrel'")
os.Exit(1)
}
if len(os.Args) == 1 {
fmt.Println("No arguments were provided.")
fmt.Println("Run: 'getghrel -h'")
os.Exit(1)
}
go utils.ScanStdIn(stdInUrls)
if opts.List {
for c := 0; c < opts.Concurrency; c++ {
jobs.Add(1)
go github.FetchGithubReleaseUrl(stdInUrls, &jobs, regex, token)
}
}
if opts.Download {
_, err := os.Stat(tempdir)
if os.IsNotExist(err) {
err = os.Mkdir(tempdir, 0755)
if err != nil {
panic(err)
}
}
for c := 0; c < opts.Concurrency; c++ {
jobs.Add(1)
go github.DownloadRelease(stdInUrls, &jobs, token, tempdir, skipextraction)
}
}
jobs.Wait() // wait for above jobs to finish
switch {
case opts.List:
return
case skipextraction:
fmt.Println("Archives are inside: ", tempdir)
default:
cleanup(tempdir)
fmt.Println("")
fmt.Println("All Binaries are inside: ", tempdir)
}
}