-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.go
58 lines (50 loc) · 1 KB
/
install.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
package main
import (
"fmt"
"os"
"os/exec"
"path"
"strings"
)
var PROJECT_TEMPLATE = "https://github.com/Dino16m/golearn.git"
var DEFAULT_APP_PATH = "./golearn-app"
func install() {
root := getRoot()
fetchTemplate(root)
setupModules(root)
tidyGoModules(root)
fmt.Println("Ready to go")
}
func fetchTemplate(root string) {
fmt.Println(root)
err := exec.Command("git", "clone", PROJECT_TEMPLATE, root).Run()
gitSettingsPath := path.Join(root, ".git")
os.Remove(gitSettingsPath)
if err != nil {
panic(err)
}
}
func tidyGoModules(root string) {
fmt.Println("Tidying go module")
cwd, _ := os.Getwd()
os.Chdir(root)
exec.Command("go", "mod", "tidy").Run()
os.Chdir(cwd)
fmt.Println("Module tidied")
}
func getRoot() string {
root := getPathArg()
fmt.Println("ROOT ", root)
root = strings.TrimSpace(root)
if len(root) < 1 || root == "." {
root = DEFAULT_APP_PATH
}
return root
}
func getPathArg() string {
args := os.Args[2:]
if len(args) < 1 {
return DEFAULT_APP_PATH
}
return args[0]
}