-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.go
More file actions
65 lines (58 loc) · 1.36 KB
/
install.go
File metadata and controls
65 lines (58 loc) · 1.36 KB
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
package cmd
import (
cfg "codacy/cli-v2/config"
"fmt"
"log"
"github.com/spf13/cobra"
)
var registry string
func init() {
installCmd.Flags().StringVarP(®istry, "registry", "r", "", "Registry to use for installing tools")
rootCmd.AddCommand(installCmd)
}
var installCmd = &cobra.Command{
Use: "install",
Short: "Installs the tools specified in the project's config-file.",
Long: "Installs all runtimes and tools specified in the project's config-file file.",
Run: func(cmd *cobra.Command, args []string) {
// install runtimes
fetchRuntimes(&cfg.Config)
// install tools
fetchTools(&cfg.Config)
},
}
func fetchRuntimes(config *cfg.ConfigType) {
for _, r := range config.Runtimes() {
switch r.Name() {
case "node":
err := cfg.InstallNode(r)
if err != nil {
log.Fatal(err)
}
default:
log.Fatal("Unknown runtime:", r.Name())
}
}
}
func fetchTools(config *cfg.ConfigType) {
for _, tool := range config.Tools() {
switch tool.Name() {
case "eslint":
// eslint needs node runtime
nodeRuntime := config.Runtimes()["node"]
err := cfg.InstallEslint(nodeRuntime, tool, registry)
if err != nil {
fmt.Println(err.Error())
log.Fatal(err)
}
case "trivy":
err := cfg.InstallTrivy(tool)
if err != nil {
fmt.Println(err.Error())
log.Fatal(err)
}
default:
log.Fatal("Unknown tool:", tool.Name())
}
}
}