Proposed implementation for installation warnings

This commit is contained in:
Thomas Heinen 2021-08-23 14:12:33 +02:00
parent d85bdbc4e1
commit 72204bd0fc
No known key found for this signature in database
GPG key ID: 2F2383C6234A72BF
2 changed files with 10 additions and 9 deletions

View file

@ -232,10 +232,10 @@ module InspecPlugins
# Already installed?
if registry.known_plugin?(plugin_name.to_sym)
ui.red("Plugin already installed - #{plugin_name} - Use '#{EXEC_NAME} " \
"plugin list' to see previously installed plugin - " \
"installation failed.\n")
ui.exit Inspec::UI::EXIT_PLUGIN_ERROR
ui.bold("Plugin already installed - #{plugin_name} - Use '#{EXEC_NAME} " \
"plugin list' to see previously installed plugin - " \
"installation failed.\n")
ui.exit Inspec::UI::EXIT_NORMAL
end
# Can we figure out how to load it?
@ -391,8 +391,9 @@ module InspecPlugins
they_explicitly_asked_for_a_version = !options[:version].nil?
what_we_would_install_is_already_installed = pre_installed_versions.include?(requested_version)
if what_we_would_install_is_already_installed && they_explicitly_asked_for_a_version
ui.red("Plugin already installed at requested version - plugin " \
ui.bold("Plugin already installed at requested version - plugin " \
"#{plugin_name} #{requested_version} - refusing to install.\n")
ui.exit Inspec::UI::EXIT_NORMAL
elsif what_we_would_install_is_already_installed && !they_explicitly_asked_for_a_version
ui.red("Plugin already installed at latest version - plugin " \
"#{plugin_name} #{requested_version} - refusing to install.\n")
@ -462,10 +463,10 @@ module InspecPlugins
latest_version = latest_version[plugin_name]&.last
if pre_update_versions.include?(latest_version)
ui.plain_line("#{ui.red("Already installed at latest version:", print: false)} " \
ui.plain_line("#{ui.bold("Already installed at latest version:", print: false)} " \
"#{plugin_name} is at #{latest_version}, which the " \
"latest - refusing to update")
ui.exit Inspec::UI::EXIT_PLUGIN_ERROR
ui.exit Inspec::UI::EXIT_NORMAL
end
end

View file

@ -131,7 +131,7 @@ class PluginManagerCliInstall < Minitest::Test
assert_empty install_result.stderr
assert_exit_code 2, install_result
assert_exit_code 0, install_result
end
def test_fail_install_from_path_when_the_dir_structure_is_wrong
@ -268,7 +268,7 @@ class PluginManagerCliInstall < Minitest::Test
assert_empty install_result.stderr
assert_exit_code 2, install_result
assert_exit_code 0, install_result
end
def test_refuse_install_when_already_installed_can_update