vpm: outdated command (#5833)

pull/5842/head
Lukas Neubert 2020-07-15 21:55:07 +02:00 committed by GitHub
parent c563168d69
commit cc7c8009a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import v.vmod
const (
default_vpm_server_urls = ['https://vpm.best', 'https://vpm.vlang.io']
valid_vpm_commands = ['help', 'search', 'install', 'update', 'remove']
valid_vpm_commands = ['help', 'search', 'install', 'update', 'outdated', 'remove']
excluded_dirs = ['cache', 'vlib']
supported_vcs_systems = ['git', 'hg']
supported_vcs_folders = ['.git', '.hg']
@ -21,6 +21,9 @@ const (
'git': 'git clone --depth=1'
'hg': 'hg clone'
}
supported_vcs_outdate_cmds = {
'git': ['git rev-parse @{u}', 'git rev-parse @']
}
)
struct Mod {
@ -73,6 +76,9 @@ fn main() {
'update' {
vpm_update(module_names)
}
'outdated' {
vpm_outdated()
}
'remove' {
vpm_remove(module_names)
}
@ -120,7 +126,6 @@ fn vpm_search(keywords []string) {
break
}
}
if index == 0 {
println('No module(s) found for "$joined"')
} else {
@ -229,6 +234,55 @@ fn vpm_update(m []string) {
}
}
fn vpm_outdated() {
module_names := get_installed_modules()
mut errors := 0
mut outdated := []string{}
for name in module_names {
final_module_path := valid_final_path_of_existing_module(name) or {
continue
}
os.chdir(final_module_path)
vcs := vcs_used_in_dir(final_module_path) or {
continue
}
if vcs[0] != 'git' {
println('Listing outdated modules is not supported with VCS {$vcs}.')
exit(1)
}
local_vcs_cmd := supported_vcs_outdate_cmds[vcs[0]][0]
local_res := os.exec(local_vcs_cmd) or {
errors++
println('Could not get local commit sha of "$name".')
verbose_println('Error command: $local_vcs_cmd')
verbose_println('Error details:\n$err')
continue
}
upstream_vcs_cmd := supported_vcs_outdate_cmds[vcs[0]][1]
upstream_res := os.exec(upstream_vcs_cmd) or {
errors++
println('Could not read upstream commit sha of "$name".')
verbose_println('Error command: $upstream_vcs_cmd')
verbose_println('Error details:\n$err')
continue
}
if local_res.output != upstream_res.output {
outdated << name
}
}
if outdated.len > 0 {
println('Outdated modules:')
for m in outdated {
println(' $m')
}
} else {
println('Modules are up to date.')
}
if errors > 0 {
exit(1)
}
}
fn vpm_remove(module_names []string) {
if settings.is_help {
vhelp.show_topic('remove')

View File

@ -31,6 +31,7 @@ V supports the following commands:
remove Remove a module that was installed from VPM.
search Search for a module from VPM.
update Update an installed module from VPM.
outdated List installed modules that need updates.
* Others:
build Build a V code in the provided path (the default, so you can skip the word `build`).
translate Translate C code to V (coming soon in 0.3).

View File

@ -70,7 +70,7 @@ fn main() {
println('Translating C to V will be available in V 0.3')
return
}
'search', 'install', 'update', 'remove' {
'search', 'install', 'update', 'outdated', 'remove' {
util.launch_tool(prefs.is_verbose, 'vpm', os.args[1..])
return
}