`vagrant box` command with primitive functionality is in. Doesn't do anything productive yet.
This commit is contained in:
parent
47149fe9a9
commit
f60b383b75
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
begin
|
||||||
|
require File.expand_path('../../.bundle/environment', __FILE__)
|
||||||
|
rescue LoadError
|
||||||
|
# Fallback on rubygems
|
||||||
|
require "rubygems"
|
||||||
|
end
|
||||||
|
|
||||||
|
require 'git-style-binary/command'
|
||||||
|
|
||||||
|
# Get library
|
||||||
|
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||||
|
$:.unshift(libdir) unless $:.include?(libdir)
|
||||||
|
require 'vagrant'
|
||||||
|
|
||||||
|
GitStyleBinary.command do
|
||||||
|
short_desc "manage boxes"
|
||||||
|
banner <<-EOS
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
#{command.full_name} add name uri
|
||||||
|
#{command.full_name} remove name
|
||||||
|
|
||||||
|
Add and remove vagrant boxes.
|
||||||
|
|
||||||
|
EOS
|
||||||
|
|
||||||
|
run do |command|
|
||||||
|
begin
|
||||||
|
Vagrant::Commands.box(command.argv)
|
||||||
|
rescue ArgumentError
|
||||||
|
educate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module Box
|
||||||
|
class Add < Base
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
module Vagrant
|
||||||
|
class Box < Actions::Runner
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -132,9 +132,35 @@ Please specify a target package to unpack and import
|
||||||
error
|
error
|
||||||
|
|
||||||
VM.execute!(Actions::Up, VM.execute!(Actions::Unpackage, name))
|
VM.execute!(Actions::Up, VM.execute!(Actions::Unpackage, name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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})
|
||||||
|
def box(argv)
|
||||||
|
sub_commands = ["add", "remove"]
|
||||||
|
|
||||||
|
if !sub_commands.include?(argv[0])
|
||||||
|
error_and_exit(<<-error)
|
||||||
|
Please specify a valid action to take on the boxes, either
|
||||||
|
`add` or `remove`. Examples:
|
||||||
|
|
||||||
|
vagrant box add name uri
|
||||||
|
vagrant box remove name
|
||||||
|
error
|
||||||
|
end
|
||||||
|
|
||||||
|
send("box_#{argv[0]}", *argv[1..-1])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Adds a box to the local filesystem, given a URI.
|
||||||
|
def box_add(name, path)
|
||||||
|
Box.execute!(Actions::Box::Add, name, path)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def act_on_vm(&block)
|
def act_on_vm(&block)
|
||||||
yield Env.persisted_vm
|
yield Env.persisted_vm
|
||||||
Env.persisted_vm.execute!
|
Env.persisted_vm.execute!
|
||||||
|
|
|
@ -165,4 +165,44 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
Vagrant::Commands.package
|
Vagrant::Commands.package
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "box" do
|
||||||
|
setup do
|
||||||
|
Vagrant::Commands.stubs(:box_foo)
|
||||||
|
Vagrant::Commands.stubs(:box_add)
|
||||||
|
Vagrant::Commands.stubs(:box_remove)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "error and exit if the first argument is not 'add' or 'remove'" do
|
||||||
|
Vagrant::Commands.expects(:error_and_exit).once
|
||||||
|
Vagrant::Commands.box(["foo"])
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not error and exit if the first argument is 'add' or 'remove'" do
|
||||||
|
commands = ["add", "remove"]
|
||||||
|
|
||||||
|
commands.each do |command|
|
||||||
|
Vagrant::Commands.expects(:error_and_exit).never
|
||||||
|
Vagrant::Commands.expects("box_#{command}".to_sym).once
|
||||||
|
Vagrant::Commands.box([command])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "forward any additional arguments" do
|
||||||
|
Vagrant::Commands.expects(:box_add).with(1,2,3).once
|
||||||
|
Vagrant::Commands.box(["add",1,2,3])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "box add" do
|
||||||
|
setup do
|
||||||
|
@name = "foo"
|
||||||
|
@path = "bar"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "execute the add action with the name and path" do
|
||||||
|
Vagrant::Box.expects(:execute!).with(Vagrant::Actions::Box::Add, @name, @path).once
|
||||||
|
Vagrant::Commands.box_add(@name, @path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue