diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bf66230d..dea7b712c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ FEATURES: IMPROVEMENTS: + - `vagrant box remove` works with only the name of the box if that + box exists only backed by one provider. [GH-1032] - `vagrant destroy` returns exit status 1 if any of the confirmations are declined. [GH-923] diff --git a/plugins/commands/box/command/remove.rb b/plugins/commands/box/command/remove.rb index 43a7bc77e..cc45a32c9 100644 --- a/plugins/commands/box/command/remove.rb +++ b/plugins/commands/box/command/remove.rb @@ -12,7 +12,27 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2 + raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1 + + if !argv[1] + # Try to automatically determine the provider. + providers = [] + @env.boxes.all.each do |name, provider| + if name == argv[0] + providers << provider + end + end + + if providers.length > 1 + @env.ui.error( + I18n.t("vagrant.commands.box.remove_must_specify_provider", + name: args[0], + providers: providers.join(", "))) + return 1 + end + + argv[1] = providers[0] || "" + end b = nil begin diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b0c252e7b..122230202 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -656,6 +656,17 @@ en: vm_not_created: "VM not created. Moving on..." vm_not_running: "VM is not currently running. Please bring it up to run this command." box: + remove_must_specify_provider: |- + Multiple providers were found for the box '%{name}'. Please specify + the specific provider for the box you want to remove. The list of + providers backing this box is: + + '%{providers}' + + To remove the box for a specific provider, run the following command, + filling in PROVIDER with one of the providers above: + + vagrant box remove '%{name}' PROVIDER no_installed_boxes: "There are no installed boxes! Use `vagrant box add` to add some." removing: |- Removing box '%{name}' with provider '%{provider}'...