-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdf.go
108 lines (91 loc) · 2.76 KB
/
asdf.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"context"
"log"
"os"
"path/filepath"
)
const asdfVersion = "v0.9.0"
func installAsdf(ctx context.Context) {
asdfInstallDir := filepath.Join(homeDir(), ".asdf")
_, err := os.Stat(asdfInstallDir)
if err == nil {
log.Printf("It seems asdf is already installed since " + asdfInstallDir + " directory exists. skip.")
return
}
ec := errContainer{}
ec.execCommand(ctx, currentDir,
"git", "clone", "https://github.com/asdf-vm/asdf.git", asdfInstallDir, "--branch", asdfVersion)
if ec.err != nil {
log.Fatal(ec.err)
}
log.Printf("installing asdf succeeded")
}
type tool struct {
name string
version string
}
func installRuby(ctx context.Context) {
tools := []tool{
{name: "ruby", version: "latest"},
}
ec := errContainer{}
for _, tool := range tools {
ec.execCommand(ctx, currentDir, "asdf", "plugin-add", tool.name)
ec.err = nil // ignore error to ignore "the plugin is already added"
ec.execCommand(ctx, currentDir, "asdf", "install", tool.name, tool.version)
ec.execCommand(ctx, currentDir, "asdf", "global", tool.name, tool.version)
}
if ec.err != nil {
log.Fatal(ec.err)
}
log.Printf("installing ruby via asdf succeeded")
}
func installNodejs(ctx context.Context) {
tools := []tool{
{name: "nodejs", version: "latest"},
}
ec := errContainer{}
for _, tool := range tools {
ec.execCommand(ctx, currentDir, "asdf", "plugin-add", tool.name)
ec.err = nil // ignore error to ignore "the plugin is already added"
ec.execCommand(ctx, currentDir, "asdf", "install", tool.name, tool.version)
ec.execCommand(ctx, currentDir, "asdf", "global", tool.name, tool.version)
}
if ec.err != nil {
log.Fatal(ec.err)
}
log.Printf("installing nodejs via asdf succeeded")
}
func installYarn(ctx context.Context) {
tools := []tool{
{name: "yarn", version: "latest"},
}
ec := errContainer{}
for _, tool := range tools {
ec.execCommand(ctx, currentDir, "asdf", "plugin-add", tool.name)
ec.err = nil // ignore error to ignore "the plugin is already added"
ec.execCommand(ctx, currentDir, "asdf", "install", tool.name, tool.version)
ec.execCommand(ctx, currentDir, "asdf", "global", tool.name, tool.version)
}
if ec.err != nil {
log.Fatal(ec.err)
}
log.Printf("installing yarn via asdf succeeded")
}
func installGHQ(ctx context.Context) {
tools := []tool{
{name: "ghq", version: "latest"},
}
ec := errContainer{}
for _, tool := range tools {
ec.execCommand(ctx, currentDir, "asdf", "plugin-add", tool.name)
ec.err = nil // ignore error to ignore "the plugin is already added"
ec.execCommand(ctx, currentDir, "asdf", "install", tool.name, tool.version)
ec.execCommand(ctx, currentDir, "asdf", "global", tool.name, tool.version)
}
if ec.err != nil {
log.Fatal(ec.err)
}
log.Printf("installing ghq via asdf succeeded")
}