From b026be7cb31e239579ac11e5fa7c45094940be19 Mon Sep 17 00:00:00 2001 From: Bernard Pietraga Date: Wed, 1 Nov 2017 23:36:22 +0100 Subject: [PATCH] Fix --output path with specified folder --- lib/vagrant/action/general/package.rb | 12 ++++++++++++ templates/locales/en.yml | 1 + test/unit/plugins/commands/package/command_test.rb | 12 ++++++++++++ 3 files changed, 25 insertions(+) diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index c969486a2..a2a4e5c8c 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -73,6 +73,8 @@ module Vagrant self.class.validate!(env["package.output"], env["package.directory"]) + package_with_folder_path if env["package.output"].include?(File::SEPARATOR) + raise Errors::PackageOutputDirectory if File.directory?(fullpath) @app.call(env) @@ -83,6 +85,16 @@ module Vagrant compress end + def package_with_folder_path + folder_path = File.expand_path("..", @fullpath) + create_box_folder(folder_path) unless File.directory?(folder_path) + end + + def create_box_folder(folder_path) + @env[:ui].info(I18n.t("vagrant.actions.general.package.box_folder", folder_path: folder_path)) + FileUtils.mkdir_p(folder_path) + end + def recover(env) @env = env diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 98193171e..8c6287673 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2114,6 +2114,7 @@ en: package: packaging: "Packaging additional file: %{file}" compressing: "Compressing package to: %{fullpath}" + box_folder: "Creating new folder: %{folder_path}" output_exists: |- The specified file '%{filename}' to save the package as already exists. Please remove this file or specify a different file name for outputting. diff --git a/test/unit/plugins/commands/package/command_test.rb b/test/unit/plugins/commands/package/command_test.rb index 7888c8860..49a5fbe89 100644 --- a/test/unit/plugins/commands/package/command_test.rb +++ b/test/unit/plugins/commands/package/command_test.rb @@ -57,6 +57,18 @@ describe VagrantPlugins::CommandPackage::Command do expect{ package_command.execute }.to raise_error(Vagrant::Errors::MachineNotFound) end end + + context "with --output option" do + + let(:argv){ ['--output', 'package-output-folder/default'] } + + it "packages default machine inside specified folder" do + expect(package_command).to receive(:package_vm).with( + a_machine_named('default'), :output => "package-output-folder/default" + ) + package_command.execute + end + end end context "with multiple arguments" do