From 797112cf842136233c02b2dfd1ec6789900cac6e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Apr 2010 17:18:59 -0700 Subject: [PATCH] box remove subcommand --- lib/vagrant/commands/box/remove.rb | 31 ++++++++++++++++++ test/vagrant/commands/box/remove_test.rb | 41 ++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 lib/vagrant/commands/box/remove.rb create mode 100644 test/vagrant/commands/box/remove_test.rb diff --git a/lib/vagrant/commands/box/remove.rb b/lib/vagrant/commands/box/remove.rb new file mode 100644 index 000000000..88670b798 --- /dev/null +++ b/lib/vagrant/commands/box/remove.rb @@ -0,0 +1,31 @@ +module Vagrant + class Commands + # Removes a box permanently from the hard drive. + module Box + class Remove < BoxCommand + BoxCommand.subcommand "remove", self + description "Remove an installed box permanently." + + def execute(args=[]) + if args.length != 1 + show_help + return + end + + + box = Vagrant::Box.find(env, args[0]) + if box.nil? + error_and_exit(:box_remove_doesnt_exist) + return # for tests + end + + box.destroy + end + + def options_spec(opts) + opts.banner = "Usage: vagrant box remove NAME" + end + end + end + end +end \ No newline at end of file diff --git a/test/vagrant/commands/box/remove_test.rb b/test/vagrant/commands/box/remove_test.rb new file mode 100644 index 000000000..97e7dfb80 --- /dev/null +++ b/test/vagrant/commands/box/remove_test.rb @@ -0,0 +1,41 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') + +class CommandsBoxRemoveTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Commands::Box::Remove + + @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" + end + + should "show help if not enough arguments" do + Vagrant::Box.expects(:find).never + @instance.expects(:show_help).once + @instance.execute([]) + end + + should "error and exit if the box doesn't exist" do + Vagrant::Box.expects(:find).returns(nil) + @instance.expects(:error_and_exit).with(:box_remove_doesnt_exist).once + @instance.execute([@name]) + end + + should "call destroy on the box if it exists" do + @box = mock("box") + Vagrant::Box.expects(:find).with(@env, @name).returns(@box) + @box.expects(:destroy).once + @instance.execute([@name]) + end + end +end