Box command to show example of a GroupBase command

This commit is contained in:
Mitchell Hashimoto 2010-08-24 11:15:36 -07:00
parent 5af0537e56
commit cc2dcf4d8f
3 changed files with 25 additions and 3 deletions

View File

@ -2,10 +2,12 @@
require 'vagrant'
require 'vagrant/cli'
env = Vagrant::Environment.load!
begin
Vagrant::CLI.start(ARGV, :env => Vagrant::Environment.load!)
Vagrant::CLI.start(ARGV, :env => env)
rescue Vagrant::VagrantError => e
Vagrant.ui.error e.message
Vagrant.ui.error e.backtrace.join("\n")
env.ui.error e.message
env.ui.error e.backtrace.join("\n")
exit e.status_code
end

View File

@ -28,6 +28,7 @@ module Vagrant
end
class CLIMissingEnvironment < VagrantError; status_code(1); end
class BoxNotFound < VagrantError; status_code(2); end
end
# Load them up. One day we'll convert this to autoloads. Today

View File

@ -7,6 +7,25 @@ module Vagrant
def add(name, uri)
Box.add(env, name, uri)
end
desc "remove NAME", "Remove a box from the system"
def remove(name)
b = Box.find(env, name)
raise BoxNotFound.new("Box '#{name}' could not be found.") if !b
b.destroy
end
desc "repackage NAME", "Repackage an installed box into a `.box` file."
def repackage(name)
b = Box.find(env, name)
raise BoxNotFound.new("Box '#{name}' could not be found.") if !b
b.repackage
end
desc "list", "Lists all installed boxes"
def list
# TODO
end
end
end
end