vpm: support `v install -once module_name`(#13977)

pull/13987/head
pancake 2022-04-09 13:29:41 +02:00 committed by GitHub
parent e3da3101f6
commit 804f2f56d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 10 deletions

View File

@ -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')
}
}
}

View File

@ -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.

View File

@ -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