diff --git a/cmd/tools/vpm.v b/cmd/tools/vpm.v index 1eaeb49579..dc9d038017 100644 --- a/cmd/tools/vpm.v +++ b/cmd/tools/vpm.v @@ -9,7 +9,7 @@ import v.vmod const ( default_vpm_server_urls = ['https://vpm.vlang.io'] - valid_vpm_commands = ['help', 'search', 'install', 'update', 'outdated', 'list', 'remove'] + valid_vpm_commands = ['help', 'search', 'install', 'update', 'upgrade', 'outdated', 'list', 'remove'] excluded_dirs = ['cache', 'vlib'] supported_vcs_systems = ['git', 'hg'] supported_vcs_folders = ['.git', '.hg'] @@ -76,6 +76,9 @@ fn main() { 'update' { vpm_update(module_names) } + 'upgrade' { + vpm_upgrade() + } 'outdated' { vpm_outdated() } @@ -239,9 +242,8 @@ fn vpm_update(m []string) { } } -fn vpm_outdated() { +fn get_outdated() ?[]string { 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 { @@ -260,11 +262,9 @@ fn vpm_outdated() { mut outputs := []string{} for step in vcs_cmd_steps { res := os.exec(step) or { - errors++ - println('Error while checking latest commits for "$name".') verbose_println('Error command: git fetch') verbose_println('Error details:\n$err') - continue + return error('Error while checking latest commits for "$name".') } outputs << res.output } @@ -272,6 +272,20 @@ fn vpm_outdated() { outdated << name } } + return outdated +} + +fn vpm_upgrade() { + outdated := get_outdated() or { exit(1) } + if outdated.len > 0 { + vpm_update(outdated) + } else { + println('Modules are up to date.') + } +} + +fn vpm_outdated() { + outdated := get_outdated() or { exit(1) } if outdated.len > 0 { println('Outdated modules:') for m in outdated { @@ -280,9 +294,6 @@ fn vpm_outdated() { } else { println('Modules are up to date.') } - if errors > 0 { - exit(1) - } } fn vpm_list() { diff --git a/cmd/v/help/default.txt b/cmd/v/help/default.txt index ec9ed94674..f40ad8f48e 100644 --- a/cmd/v/help/default.txt +++ b/cmd/v/help/default.txt @@ -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. + upgrade Upgrade all the outdated modules. list List all installed modules. outdated Show installed modules that need updates. * Others: diff --git a/cmd/v/v.v b/cmd/v/v.v index 05bab6ad8a..cf504a4dc1 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -70,7 +70,7 @@ fn main() { println('Translating C to V will be available in V 0.3') return } - 'search', 'install', 'update', 'outdated', 'list', 'remove' { + 'search', 'install', 'update', 'upgrade', 'outdated', 'list', 'remove' { util.launch_tool(prefs.is_verbose, 'vpm', os.args[1..]) return }