vpm: support `v install -once module_name`(#13977)
							parent
							
								
									e3da3101f6
								
							
						
					
					
						commit
						804f2f56d4
					
				| 
						 | 
				
			
			@ -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,17 +353,18 @@ fn vpm_install(module_names []string, source Source) {
 | 
			
		|||
		println('´v install´ requires *at least one* module name.')
 | 
			
		||||
		exit(2)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if source == .vpm {
 | 
			
		||||
	match source {
 | 
			
		||||
		.vpm {
 | 
			
		||||
			vpm_install_from_vpm(module_names)
 | 
			
		||||
		}
 | 
			
		||||
	if source == .git {
 | 
			
		||||
		.git {
 | 
			
		||||
			vpm_install_from_vcs(module_names, 'git')
 | 
			
		||||
		}
 | 
			
		||||
	if source == .hg {
 | 
			
		||||
		.hg {
 | 
			
		||||
			vpm_install_from_vcs(module_names, 'hg')
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn vpm_update(m []string) {
 | 
			
		||||
	mut module_names := m.clone()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue