Anton Kalyaev 6c5a580006 more concise message for BoxNotFound error
Now we have different providers, but the error message didn't tell
anything about it. Suppose I want to remove one of my boxes:

    vagrant box remove opscode-ubuntu-12.04 vritualbox

There is a typo in provider name. The error message is:

    Box 'opscode-ubuntu-12.04' could not be found.

Therefore I need to double check the box name, and only than I will see
the typo.

This commit make the error message looks like this:

    Box 'opscode-ubuntu-12.04' with 'vritualbox' provider could not be
found.
2013-05-05 18:23:12 +04:00

38 lines
1.0 KiB
Ruby

require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class Remove < Vagrant.plugin("2", :command)
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant box remove <name> <provider>"
end
# Parse the options
argv = parse_options(opts)
return if !argv
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2
b = nil
begin
b = @env.boxes.find(argv[0], argv[1].to_sym)
rescue Vagrant::Errors::BoxUpgradeRequired
@env.boxes.upgrade(argv[0])
retry
end
raise Vagrant::Errors::BoxNotFound, :name => argv[0], :provider => argv[1].to_sym if !b
@env.ui.info(I18n.t("vagrant.commands.box.removing",
:name => argv[0],
:provider => argv[1]))
b.destroy!
# Success, exit status 0
0
end
end
end
end
end