box list subcommand

This commit is contained in:
Mitchell Hashimoto 2010-04-13 17:16:21 -07:00
parent 8f891630d6
commit f097ee3111
3 changed files with 63 additions and 4 deletions

View File

@ -1,9 +1,6 @@
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})
# Adds a box to the local filesystem, given a URI.
module Box
class Add < BoxCommand
BoxCommand.subcommand "add", self

View File

@ -0,0 +1,30 @@
module Vagrant
class Commands
# Lists all added boxes
module Box
class List < BoxCommand
BoxCommand.subcommand "list", self
description "List all installed boxes"
def execute(args=[])
boxes = Vagrant::Box.all(env).sort
wrap_output do
if !boxes.empty?
puts "Installed Vagrant Boxes:\n\n"
boxes.each do |box|
puts box
end
else
puts "No Vagrant Boxes Added!"
end
end
end
def options_spec(opts)
opts.banner = "Usage: vagrant box list"
end
end
end
end
end

View File

@ -0,0 +1,32 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class CommandsBoxListTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::Box::List
@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
@boxes = ["foo", "bar"]
Vagrant::Box.stubs(:all).returns(@boxes)
@instance.stubs(:wrap_output)
end
should "call all on box and sort the results" do
@all = mock("all")
@all.expects(:sort).returns(@boxes)
Vagrant::Box.expects(:all).with(@env).returns(@all)
@instance.execute
end
end
end