diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 92be3d13a..a584f3163 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -57,6 +57,9 @@ module Vagrant # The directory where temporary files for Vagrant go. attr_reader :tmp_path + # File where command line aliases go. + attr_reader :aliases_path + # The directory where boxes are stored. attr_reader :boxes_path @@ -123,6 +126,7 @@ module Vagrant @data_dir = @home_path.join("data") @gems_path = Vagrant::Bundler.instance.plugin_gem_path @tmp_path = @home_path.join("tmp") + @aliases_path = @home_path.join("aliases") @machine_index_dir = @data_dir.join("machine-index") # Prepare the directories diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index a6928bc12..af09512d3 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -108,6 +108,10 @@ module Vagrant error_key(:active_machine_with_different_provider) end + class AliasInvalidError < VagrantError + error_key(:alias_invalid_error) + end + class BatchMultiError < VagrantError error_key(:batch_multi_error) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b299481b4..6e6beba71 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -378,6 +378,12 @@ en: Machine name: %{name} Active provider: %{active_provider} Requested provider: %{requested_provider} + alias_invalid_error: |- + The defined alias is not valid. Please review the information below + to help resolve the issue: + + Alias: %{alias} + Message: %{message} batch_multi_error: |- An error occurred while executing multiple actions in parallel. Any errors that occurred are shown below. diff --git a/test/unit/vagrant/alias_test.rb b/test/unit/vagrant/alias_test.rb index b15eac33d..5a106684d 100644 --- a/test/unit/vagrant/alias_test.rb +++ b/test/unit/vagrant/alias_test.rb @@ -25,6 +25,18 @@ describe Vagrant::Alias do end end + it "raises an error on invalid keywords" do + keywords = [ + "keyword with a space = command", + "keyword\twith a tab = command", + "keyword\nwith a newline = command", + ] + + keywords.each do |keyword| + expect { interpreter.interpret(keyword) }.to raise_error(Vagrant::Errors::AliasInvalidError) + end + end + it "properly interprets a simple alias" do keyword, command = interpreter.interpret("keyword=command") @@ -45,5 +57,12 @@ describe Vagrant::Alias do expect(keyword).to eq("keyword") expect(command).to eq("command = command") end + + it "allows keywords with non-alpha-numeric characters" do + keyword, command = interpreter.interpret("keyword! = command") + + expect(keyword).to eq("keyword!") + expect(command).to eq("command") + end end end