This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
/
go-ultralight.go
74 lines (64 loc) · 1.67 KB
/
go-ultralight.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
package main
import (
"flag"
"log"
"runtime"
"strings"
)
type flagVals struct {
dryRun bool
noDownload bool
noCopy bool
goos string
allOS bool
output string
}
type utility struct {
flags *flagVals
// current working directory
userDir string
vendorDir string
isModule bool
// location of the go-ultralight package
packageDir string
}
func osToUL(os string) string {
switch os {
case "linux":
return "linux"
case "darwin":
return "mac"
case "windows":
return "win"
}
return ""
}
func main() {
envOpts := flagVals{}
flag.BoolVar(&envOpts.dryRun, "dry-run", false, "Performs a dry run.")
flag.BoolVar(&envOpts.noDownload, "no-download", false, "Do not download the SDK if it does not exist.")
flag.BoolVar(&envOpts.noCopy, "no-copy", false, "Do not copy binaries to your current directory.")
flag.StringVar(&envOpts.goos, "os", runtime.GOOS, "Target OS to fetch the binaries for.\nSupported options: linux, windows, darwin")
flag.BoolVar(&envOpts.allOS, "all", false, "Fetch binaries for all supported OSes. Overrides 'os' flag.")
flag.StringVar(&envOpts.output, "output", "", "Copy binaries to a specific folder instead of the current directory.")
flag.Parse()
envOpts.goos = strings.TrimSpace(strings.ToLower(envOpts.goos))
switch envOpts.goos {
case "linux", "darwin", "windows":
default:
log.Fatalf("Unsupported OS specified: %v", envOpts.goos)
}
u := utility{
flags: &envOpts,
}
// retrieves and configures the folders used by the utility
u.getDirectories()
// download and extract the SDK
if !u.flags.noDownload {
u.download()
}
// copy the binaries to the target project
if !u.flags.noCopy {
u.install()
}
}