From c744f7afde5404b77202a94feba4ec7c418d27d3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Apr 2010 17:08:36 -0700 Subject: [PATCH] vagrant box add --- lib/vagrant.rb | 2 +- lib/vagrant/commands/box.rb | 16 +++++++++++++++ lib/vagrant/commands/box/add.rb | 27 ++++++++++++++++++++++++++ lib/vagrant/commands/status.rb | 6 +++--- test/vagrant/commands/box/add_test.rb | 28 +++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 lib/vagrant/commands/box.rb create mode 100644 lib/vagrant/commands/box/add.rb create mode 100644 test/vagrant/commands/box/add_test.rb diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 01e27484c..c09ec50cc 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -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 diff --git a/lib/vagrant/commands/box.rb b/lib/vagrant/commands/box.rb new file mode 100644 index 000000000..cb77b076b --- /dev/null +++ b/lib/vagrant/commands/box.rb @@ -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 \ No newline at end of file diff --git a/lib/vagrant/commands/box/add.rb b/lib/vagrant/commands/box/add.rb new file mode 100644 index 000000000..6545dd578 --- /dev/null +++ b/lib/vagrant/commands/box/add.rb @@ -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 \ No newline at end of file diff --git a/lib/vagrant/commands/status.rb b/lib/vagrant/commands/status.rb index e08470dd3..86d7010b5 100644 --- a/lib/vagrant/commands/status.rb +++ b/lib/vagrant/commands/status.rb @@ -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." diff --git a/test/vagrant/commands/box/add_test.rb b/test/vagrant/commands/box/add_test.rb new file mode 100644 index 000000000..a0a8e7932 --- /dev/null +++ b/test/vagrant/commands/box/add_test.rb @@ -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