vagrant box add

This commit is contained in:
Mitchell Hashimoto 2010-04-13 17:08:36 -07:00
parent 3107fa763f
commit c744f7afde
5 changed files with 75 additions and 4 deletions

View File

@ -9,7 +9,7 @@ end
# The vagrant specific files which must be loaded prior to the rest
%w{vagrant/util vagrant/util/stacked_proc_runner vagrant/util/progress_meter vagrant/actions/base vagrant/downloaders/base vagrant/actions/collection
vagrant/actions/runner vagrant/config vagrant/provisioners/base vagrant/provisioners/chef vagrant/commands/base}.each do |f|
vagrant/actions/runner vagrant/config vagrant/provisioners/base vagrant/provisioners/chef vagrant/commands/base vagrant/commands/box}.each do |f|
require File.expand_path(f, libdir)
end

View File

@ -0,0 +1,16 @@
module Vagrant
class Commands
# Manages the `vagrant box` command, allowing the user to add
# and remove boxes. This single command, given an array, determines
# which action to take and calls the respective action method
# (see {box_add} and {box_remove})
class Box < Base
Base.subcommand "box", self
description "Box commands"
def options_spec(opts)
opts.banner = "Usage: vagrant box SUBCOMMAND"
end
end
end
end

View File

@ -0,0 +1,27 @@
module Vagrant
class Commands
# Manages the `vagrant box` command, allowing the user to add
# and remove boxes. This single command, given an array, determines
# which action to take and calls the respective action method
# (see {box_add} and {box_remove})
class Box
class Add < Base
Box.subcommand "add", self
description "Add a box"
def execute(args)
if args.length != 2
show_help
return
end
Vagrant::Box.add(env, args[0], args[1])
end
def options_spec(opts)
opts.banner = "Usage: vagrant box add NAME URI"
end
end
end
end
end

View File

@ -1,8 +1,8 @@
module Vagrant
class Commands
# Export and package the current vm
#
# This command requires that an instance be powered off
# Outputs the status of the current environment. This command outputs
# useful information such as whether or not the environment is created
# and if its running, suspended, etc.
class Status < Base
Base.subcommand "status", self
description "Shows the status of the current environment."

View File

@ -0,0 +1,28 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class CommandsBoxAddTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::Box::Add
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
@env = mock_environment
@env.stubs(:require_persisted_vm)
@env.stubs(:vm).returns(@persisted_vm)
@instance = @klass.new(@env)
end
context "executing" do
setup do
@name = "foo"
@path = "bar"
end
should "execute the add action with the name and path" do
Vagrant::Box.expects(:add).with(@env, @name, @path).once
@instance.execute([@name, @path])
end
end
end