2019-08-01 02:34:28 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import (
|
|
|
|
http
|
|
|
|
os
|
|
|
|
json
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
//url = 'http://localhost:8089'
|
2019-08-05 05:34:12 +03:00
|
|
|
url = 'https://vpm.best'
|
2019-08-01 02:34:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
struct Mod {
|
|
|
|
id int
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
nr_downloads int
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-08-10 13:21:31 +03:00
|
|
|
if os.args.len <= 1 {
|
|
|
|
println('usage: vget module [module] [module] [...]')
|
2019-08-05 05:34:12 +03:00
|
|
|
return
|
|
|
|
}
|
2019-08-01 02:34:28 +03:00
|
|
|
home := os.home_dir()
|
2019-08-06 22:10:52 +03:00
|
|
|
if !os.dir_exists(home + '/.vmodules') {
|
2019-08-06 16:51:15 +03:00
|
|
|
println('Creating vmodules directory...')
|
|
|
|
os.chdir(home)
|
|
|
|
os.mkdir('.vmodules')
|
|
|
|
println('Done.')
|
|
|
|
}
|
2019-08-08 08:30:05 +03:00
|
|
|
_ := os.exec('git -C "$home/.vmodules" clone --depth=1 $mod.url ' + mod.name.replace('.', '/')) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-08-10 13:21:31 +03:00
|
|
|
|
|
|
|
home := os.home_dir()
|
|
|
|
if !os.dir_exists(home + '/.vmodules') {
|
|
|
|
println('Creating $home/.vmodules/ ...')
|
|
|
|
os.chdir(home)
|
|
|
|
os.mkdir('.vmodules')
|
|
|
|
println('Done.')
|
|
|
|
}
|
|
|
|
|
|
|
|
names := os.args.slice(1, os.args.len)
|
|
|
|
for name in names {
|
|
|
|
s := http.get_text(url + '/jsmod/$name')
|
|
|
|
mod := json.decode(Mod, s) or {
|
|
|
|
println('Error. Make sure you are online.')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
println('Installing module $name...')
|
|
|
|
_ := os.exec('git -C $home/.vmodules clone --depth=1 $mod.url ' + mod.name.replace('.', '/')) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
println(s)
|
|
|
|
}
|
|
|
|
}
|