Merge pull request #8871 from briancain/8719/master/add-force-flag-for-update
Add force flag for box upgrade command
This commit is contained in:
commit
335aa35ff4
|
@ -33,6 +33,10 @@ module VagrantPlugins
|
|||
options[:provider] = p.to_sym
|
||||
end
|
||||
|
||||
o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
|
||||
options[:force] = f
|
||||
end
|
||||
|
||||
build_download_options(o, download_options)
|
||||
end
|
||||
|
||||
|
@ -40,15 +44,15 @@ module VagrantPlugins
|
|||
return if !argv
|
||||
|
||||
if options[:box]
|
||||
update_specific(options[:box], options[:provider], download_options)
|
||||
update_specific(options[:box], options[:provider], download_options, options[:force])
|
||||
else
|
||||
update_vms(argv, options[:provider], download_options)
|
||||
update_vms(argv, options[:provider], download_options, options[:force])
|
||||
end
|
||||
|
||||
0
|
||||
end
|
||||
|
||||
def update_specific(name, provider, download_options)
|
||||
def update_specific(name, provider, download_options, force)
|
||||
boxes = {}
|
||||
@env.boxes.all.each do |n, v, p|
|
||||
boxes[n] ||= {}
|
||||
|
@ -81,11 +85,11 @@ module VagrantPlugins
|
|||
|
||||
to_update.each do |n, p, v|
|
||||
box = @env.boxes.find(n, p, v)
|
||||
box_update(box, "> #{v}", @env.ui, download_options)
|
||||
box_update(box, "> #{v}", @env.ui, download_options, force)
|
||||
end
|
||||
end
|
||||
|
||||
def update_vms(argv, provider, download_options)
|
||||
def update_vms(argv, provider, download_options, force)
|
||||
machines = {}
|
||||
|
||||
with_target_vms(argv, provider: provider) do |machine|
|
||||
|
@ -120,11 +124,11 @@ module VagrantPlugins
|
|||
if download_options[:insecure].nil?
|
||||
download_options[:insecure] = machine.config.vm.box_download_insecure
|
||||
end
|
||||
box_update(box, version, machine.ui, download_options)
|
||||
box_update(box, version, machine.ui, download_options, force)
|
||||
end
|
||||
end
|
||||
|
||||
def box_update(box, version, ui, download_options)
|
||||
def box_update(box, version, ui, download_options, force)
|
||||
ui.output(I18n.t("vagrant.box_update_checking", name: box.name))
|
||||
ui.detail("Latest installed version: #{box.version}")
|
||||
ui.detail("Version constraints: #{version}")
|
||||
|
@ -149,6 +153,7 @@ module VagrantPlugins
|
|||
box_provider: update[2].name,
|
||||
box_version: update[1].version,
|
||||
ui: ui,
|
||||
box_force: force,
|
||||
box_client_cert: download_options[:client_cert],
|
||||
box_download_ca_cert: download_options[:ca_cert],
|
||||
box_download_ca_path: download_options[:ca_path],
|
||||
|
|
|
@ -94,6 +94,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
|||
allow(action_runner).to receive(:run) do |action, opts|
|
||||
if opts[:box_provider]
|
||||
action_called = true
|
||||
expect(opts[:box_force]).to eq(nil)
|
||||
expect(opts[:box_url]).to eq(metadata_url.to_s)
|
||||
expect(opts[:box_provider]).to eq("virtualbox")
|
||||
expect(opts[:box_version]).to eq("1.1")
|
||||
|
@ -356,6 +357,27 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
|||
subject.execute
|
||||
end
|
||||
end
|
||||
|
||||
context "force flag is specified on the command line" do
|
||||
let(:argv) { ["--force"].concat(download_options) }
|
||||
|
||||
it "passes force through to action_box_add as true" do
|
||||
expect(box).to receive(:has_update?).
|
||||
with(machine.config.vm.box_version,
|
||||
{download_options:
|
||||
{ca_cert: "foo", ca_path: "bar", client_cert: "baz",
|
||||
insecure: true}}).
|
||||
and_return([md, md.version("1.1"),
|
||||
md.version("1.1").provider("virtualbox")])
|
||||
|
||||
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
|
||||
expect(opts[:box_force]).to be(true)
|
||||
true
|
||||
}
|
||||
|
||||
subject.execute
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue