From c67783bcd158536eb0ef34dc7164173c4f488d24 Mon Sep 17 00:00:00 2001 From: iRedMail <2048991+iredmail@users.noreply.github.com> Date: Sat, 10 Aug 2019 18:21:31 +0800 Subject: [PATCH] =?UTF-8?q?v=20install:=20=20install=20multiple=20modules?= =?UTF-8?q?=20in=20one=20command:=20'v=20install=20m1=20m2=20m3=20?= =?UTF-8?q?=E2=80=A6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/main.v | 18 +++++++++--------- tools/vget.v | 36 ++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 60d7fd6e59..18295822d4 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -126,11 +126,12 @@ fn main() { return } if 'install' in args { - mod := args.last() - if args.len != 3 || mod.len < 2 { - println('usage: v install [module]') + if args.len <= 3 { + println('usage: v install [module] [module] [...]') return - } + } + + names := args.slice(2, args.len) vroot := os.dir(os.executable()) vget := '$vroot/tools/vget' if true { @@ -140,13 +141,12 @@ fn main() { _ := os.exec('$vexec vget.v') or { panic(err) } - //println('Done.') } - println('Installing module ${mod}...') - _ := os.exec('$vget $mod') or { - panic(err) + + _ := os.exec('$vget ' + names.join(' ')) or { + panic(err) } - return + return } // TODO quit if the compiler is too old // u := os.file_last_mod_unix('v') diff --git a/tools/vget.v b/tools/vget.v index e72a82ed63..908ed9667d 100644 --- a/tools/vget.v +++ b/tools/vget.v @@ -19,14 +19,8 @@ struct Mod { } fn main() { - if os.args.len != 2 { - println('usage: vget [module]') - return - } - name := os.args.last() - s := http.get_text(url + '/jsmod/$name') - mod := json.decode(Mod, s) or { - println('Error. Make sure you are online.') + if os.args.len <= 1 { + println('usage: vget module [module] [module] [...]') return } home := os.home_dir() @@ -39,5 +33,27 @@ fn main() { _ := os.exec('git -C "$home/.vmodules" clone --depth=1 $mod.url ' + mod.name.replace('.', '/')) or { panic(err) } - println(s) -} + + 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) + } +}