diff --git a/cmd/tools/vpm/install.v b/cmd/tools/vpm/install.v index dce978a01546ae..bd5bb3889f5fd6 100644 --- a/cmd/tools/vpm/install.v +++ b/cmd/tools/vpm/install.v @@ -233,6 +233,10 @@ fn (m Module) confirm_install() bool { } else { install_version := at_version(if m.version == '' { 'latest' } else { m.version }) println('Module `${m.name}${at_version(m.installed_version)}` is already installed at `${m.install_path_fmted}`.') + if settings.fail_on_prompt { + vpm_error('VPM should not have entered a confirmation prompt.') + exit(1) + } input := os.input('Replace it with `${m.name}${install_version}`? [Y/n]: ') match input.to_lower() { '', 'y' { diff --git a/cmd/tools/vpm/install_test.v b/cmd/tools/vpm/install_test.v index 1171112ca1f783..7ec72c23c306e2 100644 --- a/cmd/tools/vpm/install_test.v +++ b/cmd/tools/vpm/install_test.v @@ -16,6 +16,7 @@ fn testsuite_begin() { os.setenv('VMODULES', test_path, true) os.setenv('VPM_DEBUG', '', true) os.setenv('VPM_NO_INCREMENT', '1', true) + os.setenv('VPM_FAIL_ON_PROMPT', '1', true) } fn testsuite_end() { diff --git a/cmd/tools/vpm/install_version_test.v b/cmd/tools/vpm/install_version_test.v index 91cd16a588d635..33b2bed7c81c39 100644 --- a/cmd/tools/vpm/install_version_test.v +++ b/cmd/tools/vpm/install_version_test.v @@ -14,6 +14,7 @@ fn testsuite_begin() { os.setenv('VMODULES', test_path, true) os.setenv('VPM_DEBUG', '', true) os.setenv('VPM_NO_INCREMENT', '1', true) + os.setenv('VPM_FAIL_ON_PROMPT', '1', true) } fn testsuite_end() { diff --git a/cmd/tools/vpm/settings.v b/cmd/tools/vpm/settings.v index 7cd4e0954121c1..81eb3f38f25868 100644 --- a/cmd/tools/vpm/settings.v +++ b/cmd/tools/vpm/settings.v @@ -13,6 +13,9 @@ mut: server_urls []string vmodules_path string no_dl_count_increment bool + // To ensure that some test scenarios with conflicting module directory names do not get stuck in prompts. + // It is intended that VPM does not display a prompt when `VPM_FAIL_ON_PROMPT` is set. + fail_on_prompt bool // git is used by default. URL installations can specify `--hg`. For already installed modules // and VPM modules that specify a different VCS in their `v.mod`, the VCS is validated separately. vcs VCS @@ -35,5 +38,6 @@ fn init_settings() VpmSettings { vcs: supported_vcs[if '--hg' in opts { 'hg' } else { 'git' }] vmodules_path: os.vmodules_dir() no_dl_count_increment: os.getenv('CI') != '' || (no_inc_env != '' && no_inc_env != '0') + fail_on_prompt: os.getenv('VPM_FAIL_ON_PROMPT') != '' } }