-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
handler.go
98 lines (90 loc) · 2.44 KB
/
handler.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
package main
import (
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"
"github.com/mitchellh/go-homedir"
"os"
"strconv"
"strings"
"path/filepath"
)
func InstallHandler(c *cli.Context) {
config := readConfig()
localFolder := config.Local.LocalFolder
remoteURL := c.Args().Get(0)
if remoteURL == "cvpm:test" {
color.Cyan("Installing... Please wait patiently")
pip([]string{"install", "--index-url", "https://test.pypi.org/simple/", "cvpm", "--user"})
return
} else {
color.Cyan("Installing to " + localFolder)
}
var repoFolder string
var repo Repository
// Download Codebase
if strings.HasPrefix(remoteURL, "https://github.com") {
repo = CloneFromGit(remoteURL, localFolder)
}
repoFolder = repo.LocalFolder
// Install Dependencies
color.Cyan("Installing Dependencies... please wait patiently")
InstallDependencies(repoFolder)
color.Blue("Generating Runners")
GeneratingRunners(repoFolder)
color.Cyan("Adding to Local Configuration")
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}
func listRepos(c *cli.Context) {
config := readConfig()
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"No.", "Name", "Vendor", "Path"})
for i, repo := range config.Repositories {
table.Append([]string{strconv.Itoa(i), repo.Name, repo.Vendor, repo.LocalFolder})
}
table.Render()
}
func DaemonHandler(c *cli.Context) {
params := c.Args().Get(0)
switch params {
case "install":
InstallService()
case "uninstall":
UninstallService()
case "run":
runServer(DaemonPort)
default:
color.Red("Unsupported command")
}
}
func RepoHandler(c *cli.Context) {
taskParams := c.Args().Get(0)
switch taskParams {
case "run":
solverstring := c.Args().Get(1)
runParams := strings.Split(solverstring, "/")
color.Cyan("Running " + runParams[0] + "/" + runParams[1] + "/" + runParams[2])
requestParams := map[string]string{
"vendor": runParams[0],
"name": runParams[1],
"solver": runParams[2],
}
ClientPost("repo", requestParams)
case "ps":
requestParams := map[string]string{}
ClientGet("repos", requestParams)
default:
color.Red("Command Not Supported!")
}
}
func ConfigHandler(c* cli.Context) {
configFilePath := filepath.Join(homedir.Dir(), "cvpm", "config.toml")
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
file, err := os.Create(configFilePath)
if err != nil {
color.Red("An error occured!")
}
defer file.Close()
}
}