Add local only and global only flags to plugin expunge command

This commit is contained in:
Chris Roberts 2018-07-18 13:43:52 -07:00
parent 564dff651e
commit 14edb8f423
3 changed files with 71 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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