From 8f0f0506d669560f4d7b00957f9bac2d3f26f972 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 23 Jan 2014 16:46:46 -0800 Subject: [PATCH] core: BoxAdd requires name if old-style box --- lib/vagrant/action/builtin/box_add.rb | 5 ++++- lib/vagrant/errors.rb | 4 ++++ templates/locales/en.yml | 18 +++++++++++------- .../vagrant/action/builtin/box_add_test.rb | 12 ++++++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 97ed3d26d..11a42273b 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -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 diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 7453d3c72..61c2c4ec2 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -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 diff --git a/templates/locales/en.yml b/templates/locales/en.yml index d8398954d..7ee1a2c7c 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -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: diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index e900dff87..a2391132c 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -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)