core: BoxAdd requires name if old-style box

This commit is contained in:
Mitchell Hashimoto 2014-01-23 16:46:46 -08:00
parent 09e8666296
commit 8f0f0506d6
4 changed files with 31 additions and 8 deletions

View File

@ -35,8 +35,11 @@ module Vagrant
# Adds a box file directly (no metadata component, versioning,
# etc.)
def add_direct(env)
# TODO: what if we have no name
name = env[:box_name]
if !name || name == ""
raise Errors::BoxAddNameRequired
end
url = env[:box_url]
provider = env[:box_provider]
provider = Array(provider) if provider

View File

@ -120,6 +120,10 @@ module Vagrant
error_key(:batch_multi_error)
end
class BoxAddNameRequired < VagrantError
error_key(:box_add_name_required)
end
class BoxAddNoMatchingProvider < VagrantError
error_key(:box_add_no_matching_provider)
end

View File

@ -4,13 +4,6 @@ en:
Machine booted and ready!
boot_waiting: |-
Waiting for machine to boot. This may take a few minutes...
box_add_exists: |-
The box you're attempting to add already exists. Remove it before
adding it again or add it with the `--force` flag.
Name: %{name}
Provider: %{provider}
Version: %{version}
box_add_with_version: |-
Adding box '%{name}' (v%{version}) for '%{provider}' provider...
box_added: |-
@ -263,6 +256,17 @@ en:
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
box_add_exists: |-
The box you're attempting to add already exists. Remove it before
adding it again or add it with the `--force` flag.
Name: %{name}
Provider: %{provider}
Version: %{version}
box_add_name_required: |-
A name is required when adding a box file directly. Please pass
the `--name` parameter to `vagrant box add`. See
`vagrant box add -h` for more help.
box_checksum_invalid_type: |-
The specified checksum type is not supported by Vagrant: %{type}.
Vagrant supports the following checksum types:

View File

@ -96,6 +96,18 @@ describe Vagrant::Action::Builtin::BoxAdd do
end
end
it "raises an error if no name is given" do
box_path = iso_env.box2_file(:virtualbox)
env[:box_url] = box_path.to_s
box_collection.should_receive(:add).never
app.should_receive(:call).never
expect { subject.call(env) }.
to raise_error(Vagrant::Errors::BoxAddNameRequired)
end
it "raises an error if the box already exists" do
box_path = iso_env.box2_file(:virtualbox)