core: ask what provider to use if multiple providers
This commit is contained in:
parent
e38ce34e56
commit
f9c9559320
|
@ -101,6 +101,28 @@ module Vagrant
|
|||
# provider.
|
||||
metadata_provider = metadata_version.provider(
|
||||
metadata_version.providers.first)
|
||||
else
|
||||
providers = metadata_version.providers.sort
|
||||
|
||||
choice = 0
|
||||
options = providers.map do |p|
|
||||
choice += 1
|
||||
"#{choice}) #{p}"
|
||||
end.join("\n")
|
||||
|
||||
# We have more than one provider, ask the user what they want
|
||||
choice = env[:ui].ask(I18n.t(
|
||||
"vagrant.box_add_choose_provider",
|
||||
options: options))
|
||||
choice = choice.to_i if choice
|
||||
while !choice || choice <= 0 || choice > providers.length
|
||||
choice = env[:ui].ask(I18n.t(
|
||||
"vagrant.box_add_choose_provider_again"))
|
||||
choice = choice.to_i if choice
|
||||
end
|
||||
|
||||
metadata_provider = metadata_version.provider(
|
||||
providers[choice-1])
|
||||
end
|
||||
|
||||
box_add(
|
||||
|
@ -331,7 +353,6 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: do the HEAD request
|
||||
output = d.head
|
||||
match = output.scan(/^Content-Type: (.+?)$/).last
|
||||
return false if !match
|
||||
|
|
|
@ -4,6 +4,16 @@ en:
|
|||
Machine booted and ready!
|
||||
boot_waiting: |-
|
||||
Waiting for machine to boot. This may take a few minutes...
|
||||
box_add_choose_provider: |-
|
||||
This box can work with multiple providers! The providers that it
|
||||
can work with are listed below. Please review the list and choose
|
||||
the provider you will be working with.
|
||||
|
||||
%{options}
|
||||
|
||||
Enter your choice:
|
||||
box_add_choose_provider_again: |-
|
||||
Invalid choice. Try again:
|
||||
box_add_with_version: |-
|
||||
Adding box '%{name}' (v%{version}) for '%{provider}' provider...
|
||||
box_added: |-
|
||||
|
|
|
@ -450,6 +450,51 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
|||
expect(env[:box_added]).to equal(box)
|
||||
end
|
||||
|
||||
it "asks the user what provider if multiple options" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
"versions": [
|
||||
{
|
||||
"version": "0.5"
|
||||
},
|
||||
{
|
||||
"version": "0.7",
|
||||
"providers": [
|
||||
{
|
||||
"name": "virtualbox",
|
||||
"url": "#{box_path}"
|
||||
},
|
||||
{
|
||||
"name": "vmware",
|
||||
"url": "#{iso_env.box2_file(:vmware)}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
RAW
|
||||
f.close
|
||||
end
|
||||
|
||||
env[:box_url] = tf.path
|
||||
|
||||
env[:ui].should_receive(:ask).and_return("1")
|
||||
|
||||
box_collection.should_receive(:add).with do |path, name, version|
|
||||
expect(checksum(path)).to eq(checksum(box_path))
|
||||
expect(name).to eq("foo/bar")
|
||||
expect(version).to eq("0.7")
|
||||
true
|
||||
end.and_return(box)
|
||||
|
||||
app.should_receive(:call).with(env)
|
||||
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
it "raises an exception if no matching version" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
|
|
Loading…
Reference in New Issue