From 804f2f56d48bd3637944c1edfbe5d24911ce7a35 Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 9 Apr 2022 13:29:41 +0200 Subject: [PATCH] vpm: support `v install -once module_name`(#13977) --- cmd/tools/vpm.v | 36 +++++++++++++++++++++++++++--------- cmd/v/help/install.txt | 1 + doc/docs.md | 8 +++++++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/cmd/tools/vpm.v b/cmd/tools/vpm.v index f99187d32b..260a24e283 100644 --- a/cmd/tools/vpm.v +++ b/cmd/tools/vpm.v @@ -87,6 +87,12 @@ fn main() { module_names = manifest.dependencies } mut source := Source.vpm + if '--once' in options { + module_names = vpm_once_filter(module_names) + if module_names.len == 0 { + return + } + } if '--git' in options { source = Source.git } @@ -327,6 +333,17 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) { } } +fn vpm_once_filter(module_names []string) []string { + installed_modules := get_installed_modules() + mut toinstall := []string{} + for mn in module_names { + if mn !in installed_modules { + toinstall << mn + } + } + return toinstall +} + fn vpm_install(module_names []string, source Source) { if settings.is_help { vhelp.show_topic('install') @@ -336,15 +353,16 @@ fn vpm_install(module_names []string, source Source) { println('´v install´ requires *at least one* module name.') exit(2) } - - if source == .vpm { - vpm_install_from_vpm(module_names) - } - if source == .git { - vpm_install_from_vcs(module_names, 'git') - } - if source == .hg { - vpm_install_from_vcs(module_names, 'hg') + match source { + .vpm { + vpm_install_from_vpm(module_names) + } + .git { + vpm_install_from_vcs(module_names, 'git') + } + .hg { + vpm_install_from_vcs(module_names, 'hg') + } } } diff --git a/cmd/v/help/install.txt b/cmd/v/help/install.txt index ba0b3cb175..975a690d7f 100644 --- a/cmd/v/help/install.txt +++ b/cmd/v/help/install.txt @@ -8,6 +8,7 @@ Options: --vpm - [Default] Install from vpm --git - Install from git repository url --hg - Install from mercurial repository url + --once - Only install the module if it was not previously installed -help - Show usage info. -v - Print more details about the performed operation. -server-url - When doing network operations, use this vpm server. Can be given multiple times. diff --git a/doc/docs.md b/doc/docs.md index c0c3459f1d..4bd8afe535 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -4601,13 +4601,19 @@ v install ui Modules can be installed directly from git or mercurial repositories. ```powershell -v install [--git|--hg] [url] +v install [--once] [--git|--hg] [url] ``` **Example:** ```powershell v install --git https://github.com/vlang/markdown ``` +Sometimes you may want to install the dependencies **ONLY** if those are not installed: + +``` +v install --once [module] +``` + Removing a module with v: ```powershell