-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
167 lines (129 loc) · 5.14 KB
/
main.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package main
import (
"fmt"
"log"
"os"
"github.com/JojiiOfficial/gaw"
librb "github.com/RemoteBuild/LibRemotebuild"
dmConfig "github.com/RemoteBuild/LibRemotebuild/config"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
const (
appName = "rbuild"
version = "1.0.0"
)
// ...
const (
// EnVarPrefix prefix for env vars
EnVarPrefix = "RBUILD"
// EnVarPrefix prefix of all used env vars
EnVarLogLevel = "LOG_LEVEL"
EnVarNoColor = "NO_COLOR"
EnVarNoEmojis = "NO_EMOJIS"
EnVarConfigFile = "CONFIG"
)
// Return the variable using the server prefix
func getEnVar(name string) string {
return fmt.Sprintf("%s_%s", EnVarPrefix, name)
}
// App commands
var (
app = kingpin.New(appName, "A Remote build client")
// Global flags
appYes = app.Flag("yes", "Skip confirmations").Short('y').Bool()
appCfgFile = app.Flag("config", "the configuration file for the app").Envar(getEnVar(EnVarConfigFile)).Short('c').String()
appNoTitle = app.Flag("no-title", "Don't show table titles").Short('t').Bool()
// File related flags
appForce = app.Flag("force", "Forces an action").Short('f').Bool()
setupCmd = app.Command("setup", "Setup the connection to the server")
setupCmdHost = setupCmd.Arg("host", "The host").Required().String()
setupCmdIgnoreCert = setupCmd.Flag("ignore-cert", "Ignore invalid SSL/TLS certs").Bool()
setupCmdServerOnly = setupCmd.Flag("server-only", "Setup the server only").Bool()
setupCmdRegister = setupCmd.Flag("register", "Create an account").Bool()
setupCmdLogin = setupCmd.Flag("login", "Login into an existing account").Bool()
setupCmdToken = setupCmd.Flag("token", "Use an existing sessiontoken to setup a connection").String()
setupCmdUser = setupCmd.Flag("username", "Required if --token is used").String()
// User commands
loginCmd = app.Command("login", "Login into an existing account")
registerCmd = app.Command("register", "Create a new account")
jobs = app.Command("jobs", "List active jobs").Alias("js")
jobsn = jobs.Flag("limit", "Limit the jobs to display").Short('n').Int()
// Job commands
job = app.Command("job", "Job actions").Alias("j")
jobInfo = job.Command("info", "Infos about a job").Alias("i")
jobInfoID = jobInfo.Arg("id", "JobID").Required().Uint()
// New jobs
newJobCmd = job.Command("create", "Create a new job").Alias("c")
jobUploadTo = app.Flag("uploadTo", "Upload compiled file").Short('u').HintOptions([]string{librb.DataManagerUploadType.String(), librb.LocalStorage.String()}...).String()
jobDisableCcache = app.Flag("disable-ccache", "Don't use ccache to build the specified package").Bool()
// -- New AUR job
aurBuild = newJobCmd.Command("aurbuild", "Build an AUR package")
aurbuildPackage = aurBuild.Arg("Package", "The AUR package to build").Required().String()
// Cancel job
jobCancelCmd = job.Command("cancel", "Cancel a job").Alias("stop").Alias("rm")
jobCancelID = jobCancelCmd.Arg("JobID", "ID of job to cancel").Required().Uint()
// Job logs
jobLogsCmd = job.Command("logs", "View logs of job").Alias("l").Alias("log")
jobLogsID = jobLogsCmd.Arg("JobID", "ID of job to retrieve the logs from").Required().Uint()
// logs
logsCmd = app.Command("logs", "View logs of job").Alias("l").Alias("log")
logsID = logsCmd.Arg("JobID", "ID of job to retrieve the logs from").Required().Uint()
// Pause
jobPauseCmd = job.Command("pause", "Pause a job")
jobPauseID = jobPauseCmd.Arg("JobID", "ID of job to pause").Required().Uint()
// Resume
jobResumeCmd = job.Command("resume", "Resume a job")
jobResumeID = jobResumeCmd.Arg("JobID", "ID of job to resume").Required().Uint()
// Ccache
ccacheCmd = app.Command("ccache", "Ccache commands").Alias("cc").Alias("cache").Alias("c")
// clear
ccacheClearCmd = ccacheCmd.Command("clear", "Clear ccache on server").Alias("c")
// getinfo
ccacheInfoCmd = ccacheCmd.Command("stats", "Clear ccache on server").Alias("i").Alias("query").Alias("q").Alias("s")
// List fies on the remote storage
filesCmd = app.Command("files", "List files assigned to a Job").Alias("fs")
filesID = filesCmd.Arg("ID", "The JobID to view the available files from").Required().Uint()
// Download files from a job
DownloadCmd = app.Command("download", "Download files from a job").Alias("dl")
DownloadID = DownloadCmd.Arg("ID", "The JobID to download the output files from").Required().Uint()
)
var (
config *dmConfig.Config
appTrimName int
unmodifiedNS string
)
func main() {
app.HelpFlag.Short('h')
app.Version(version)
// Init random seed from gaw
gaw.Init()
// Prase cli flags
parsed := kingpin.MustParse(app.Parse(os.Args[1:]))
// Init config
if !initConfig(parsed) {
return
}
// Bulid commandData
commandData := buildCData(parsed, appTrimName)
if commandData == nil {
return
}
// Run desired command
runCommand(parsed, commandData)
}
// Load and init config. Return false on error
func initConfig(parsed string) bool {
// Init config
var err error
config, err = dmConfig.InitConfig(dmConfig.GetDefaultConfigFile(), *appCfgFile)
if err != nil {
log.Fatalln(err)
}
if config == nil {
fmt.Println("New config created")
if parsed != setupCmd.FullCommand() {
return false
}
}
return true
}