2019-08-01 01:34:28 +02:00
|
|
|
module main
|
|
|
|
|
|
|
|
import (
|
|
|
|
http
|
|
|
|
os
|
|
|
|
json
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
//url = 'http://localhost:8089'
|
2019-08-05 04:34:12 +02:00
|
|
|
url = 'https://vpm.best'
|
2019-08-01 01:34:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
struct Mod {
|
|
|
|
id int
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
nr_downloads int
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-08-10 12:21:31 +02:00
|
|
|
if os.args.len <= 1 {
|
|
|
|
println('usage: vget module [module] [module] [...]')
|
2019-08-05 04:34:12 +02:00
|
|
|
return
|
|
|
|
}
|
2019-08-10 12:21:31 +02:00
|
|
|
|
|
|
|
home := os.home_dir()
|
2019-08-10 14:29:37 +02:00
|
|
|
home_vmodules := '${home}.vmodules'
|
|
|
|
if !os.dir_exists( home_vmodules ) {
|
|
|
|
println('Creating $home_vmodules/ ...')
|
|
|
|
os.mkdir(home_vmodules)
|
2019-08-10 12:21:31 +02:00
|
|
|
}
|
2019-08-10 14:29:37 +02:00
|
|
|
os.chdir(home_vmodules)
|
2019-08-10 12:21:31 +02:00
|
|
|
|
2019-08-10 14:29:37 +02:00
|
|
|
mut errors := 0
|
2019-08-10 12:21:31 +02:00
|
|
|
names := os.args.slice(1, os.args.len)
|
|
|
|
for name in names {
|
2019-08-18 16:57:57 +02:00
|
|
|
modurl := url + '/jsmod/$name'
|
|
|
|
r := http.get(modurl) or { panic(err) }
|
|
|
|
|
|
|
|
if r.status_code == 404 {
|
|
|
|
println('Skipping module "$name", since $url reported that "$name" does not exist.')
|
|
|
|
errors++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.status_code != 200 {
|
|
|
|
println('Skipping module "$name", since $url responded with $r.status_code http status code. Please try again later.')
|
|
|
|
errors++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
s := r.text
|
2019-08-10 12:21:31 +02:00
|
|
|
mod := json.decode(Mod, s) or {
|
2019-08-10 14:29:37 +02:00
|
|
|
errors++
|
2019-08-18 16:57:57 +02:00
|
|
|
println('Skipping module "$name", since its information is not in json format.')
|
2019-08-10 14:29:37 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if( '' == mod.url || '' == mod.name ){
|
|
|
|
errors++
|
|
|
|
// a possible 404 error, which means a missing module?
|
2019-08-18 16:57:57 +02:00
|
|
|
println('Skipping module "$name", since it is missing name or url information.')
|
2019-08-10 14:29:37 +02:00
|
|
|
continue
|
2019-08-10 12:21:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-10 14:29:37 +02:00
|
|
|
final_module_path := '$home_vmodules/' + mod.name.replace('.', '/')
|
|
|
|
|
|
|
|
println('Installing module "$name" from $mod.url to $final_module_path ...')
|
2019-09-25 14:10:45 +02:00
|
|
|
_ = os.exec('git clone --depth=1 $mod.url $final_module_path') or {
|
2019-08-10 14:29:37 +02:00
|
|
|
errors++
|
|
|
|
println('Could not install module "$name" to "$final_module_path" .')
|
|
|
|
println('Error details: $err')
|
|
|
|
continue
|
2019-08-10 12:21:31 +02:00
|
|
|
}
|
2019-08-10 14:29:37 +02:00
|
|
|
}
|
|
|
|
if errors > 0 {
|
|
|
|
exit(1)
|
2019-08-10 12:21:31 +02:00
|
|
|
}
|
|
|
|
}
|