diff --git a/plugins/commands/plugin/action/expunge_plugins.rb b/plugins/commands/plugin/action/expunge_plugins.rb index 3327d57df..98b7f6014 100644 --- a/plugins/commands/plugin/action/expunge_plugins.rb +++ b/plugins/commands/plugin/action/expunge_plugins.rb @@ -46,13 +46,13 @@ module VagrantPlugins dirs = [] # Do not include global paths if local only - if !env[:env_local] + if !env[:env_local_only] || env[:global_only] files << Vagrant::Plugin::Manager.instance.user_file.path dirs << Vagrant::Bundler.instance.plugin_gem_path end # Add local paths if they exist - if Vagrant::Plugin::Manager.instance.local_file + if Vagrant::Plugin::Manager.instance.local_file && (env[:env_local_only] || !env[:global_only]) files << Vagrant::Plugin::Manager.instance.local_file.path dirs << Vagrant::Bundler.instance.env_plugin_gem_path end diff --git a/plugins/commands/plugin/command/expunge.rb b/plugins/commands/plugin/command/expunge.rb index afe4e12ea..1b23ab02e 100644 --- a/plugins/commands/plugin/command/expunge.rb +++ b/plugins/commands/plugin/command/expunge.rb @@ -16,10 +16,18 @@ module VagrantPlugins options[:force] = force end - o.on("--local", "Remove local project plugins only") do |l| + o.on("--local", "Include local project plugins for expunge") do |l| options[:env_local] = l end + o.on("--local-only", "Only expunge local project plugins") do |l| + options[:env_local_only] = l + end + + o.on("--global-only", "Only expunge global plugins") do |l| + options[:global_only] = l + end + o.on("--reinstall", "Reinstall current plugins after expunge") do |reinstall| options[:reinstall] = reinstall end diff --git a/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb b/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb index 4b1d50257..a58f38d33 100644 --- a/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb +++ b/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb @@ -6,12 +6,16 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do let(:gems_path){ "#{home_path}/gems" } let(:force){ true } let(:env_local){ false } + let(:env_local_only){ nil } + let(:global_only){ nil } let(:env) {{ ui: Vagrant::UI::Silent.new, home_path: home_path, gems_path: gems_path, force: force, - env_local: env_local + env_local: env_local, + env_local_only: env_local_only, + global_only: global_only }} let(:user_file) { double("user_file", path: user_file_pathname) } @@ -75,9 +79,9 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do context "when local option is set" do let(:env_local) { true } - it "should not delete plugins" do - expect(user_file_pathname).not_to receive(:delete) - expect(plugin_gem_path).not_to receive(:rmtree) + it "should delete plugins" do + expect(user_file_pathname).to receive(:delete) + expect(plugin_gem_path).to receive(:rmtree) subject.call(env) end end @@ -104,11 +108,60 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do subject.call(env) end - it "should not delete user plugins" do - expect(user_file_pathname).not_to receive(:delete) - expect(plugin_gem_path).not_to receive(:rmtree) + it "should delete user plugins" do + expect(user_file_pathname).to receive(:delete) + expect(plugin_gem_path).to receive(:rmtree) subject.call(env) end + + context "when local only option is set" do + let(:env_local_only) { true } + + it "should delete local plugins" do + expect(local_file_pathname).to receive(:delete) + expect(env_plugin_gem_path).to receive(:rmtree) + subject.call(env) + end + + it "should not delete user plugins" do + expect(user_file_pathname).not_to receive(:delete) + expect(plugin_gem_path).not_to receive(:rmtree) + subject.call(env) + end + end + + context "when global only option is set" do + let(:global_only) { true } + + it "should not delete local plugins" do + expect(local_file_pathname).not_to receive(:delete) + expect(env_plugin_gem_path).not_to receive(:rmtree) + subject.call(env) + end + + it "should delete user plugins" do + expect(user_file_pathname).to receive(:delete) + expect(plugin_gem_path).to receive(:rmtree) + subject.call(env) + end + end + + context "when global and local only options are set" do + let(:env_local_only) { true } + let(:global_only) { true } + + it "should delete local plugins" do + expect(local_file_pathname).to receive(:delete) + expect(env_plugin_gem_path).to receive(:rmtree) + subject.call(env) + end + + it "should delete user plugins" do + expect(user_file_pathname).to receive(:delete) + expect(plugin_gem_path).to receive(:rmtree) + subject.call(env) + end + end end end end