Convert comands to V2 plugins.

This commit is contained in:
Mitchell Hashimoto 2012-11-06 21:05:14 -08:00
parent be294e002a
commit e8370f0098
35 changed files with 59 additions and 44 deletions

View File

@ -92,6 +92,15 @@ module Vagrant
c.register([:"1", :host]) { Plugin::V1::Host }
c.register([:"1", :provider]) { Plugin::V1::Provider }
c.register([:"1", :provisioner]) { Plugin::V1::Provisioner }
c.register(:"2") { Plugin::V2::Plugin }
c.register([:"2", :command]) { Plugin::V2::Command }
c.register([:"2", :communicator]) { Plugin::V2::Communicator }
c.register([:"2", :config]) { Plugin::V2::Config }
c.register([:"2", :guest]) { Plugin::V2::Guest }
c.register([:"2", :host]) { Plugin::V2::Host }
c.register([:"2", :provider]) { Plugin::V2::Provider }
c.register([:"2", :provisioner]) { Plugin::V2::Provisioner }
end
# The source root is the path to the root directory of

View File

@ -3,7 +3,7 @@ require 'optparse'
module Vagrant
# Manages the command line interface to Vagrant.
class CLI < Vagrant.plugin("1", :command)
class CLI < Vagrant.plugin("2", :command)
def initialize(argv, env)
super
@ -33,12 +33,7 @@ module Vagrant
# then we also just print the help and exit.
command_class = nil
if @sub_command
Vagrant.plugin("1").registered.each do |plugin|
if plugin.command.has_key?(@sub_command.to_sym)
command_class = plugin.command.get(@sub_command.to_sym)
break
end
end
command_class = Vagrant.plugin("2").manager.commands[@sub_command.to_sym]
end
if !command_class || !@sub_command
@ -69,10 +64,8 @@ module Vagrant
# Add the available subcommands as separators in order to print them
# out as well.
keys = []
Vagrant.plugin("1").registered.each do |plugin|
plugin.command.each do |key, _|
keys << key
end
Vagrant.plugin("2").manager.commands.each do |key, _|
keys << key
end
keys.sort.each do |key|

View File

@ -14,6 +14,19 @@ module Vagrant
@registered = []
end
# This returns all the registered commands.
#
# @return [Hash]
def commands
result = {}
@registered.each do |plugin|
result.merge!(plugin.command.to_hash)
end
result
end
# This returns all the registered communicators.
#
# @return [Hash]

View File

@ -3,7 +3,7 @@ require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class Add < Vagrant.plugin("1", :command)
class Add < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -3,7 +3,7 @@ require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class List < Vagrant.plugin("1", :command)
class List < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -3,7 +3,7 @@ require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class Remove < Vagrant.plugin("1", :command)
class Remove < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -4,7 +4,7 @@ require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class Repackage < Vagrant.plugin("1", :command)
class Repackage < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -3,7 +3,7 @@ require 'optparse'
module VagrantPlugins
module CommandBox
module Command
class Root < Vagrant.plugin("1", :command)
class Root < Vagrant.plugin("2", :command)
def initialize(argv, env)
super

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandBox
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "box command"
description "The `box` command gives you a way to manage boxes."

View File

@ -1,6 +1,6 @@
module VagrantPlugins
module CommandDestroy
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandDestroy
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "destroy command"
description "The `destroy` command destroys your virtual machines."

View File

@ -5,7 +5,7 @@ require "vagrant/util/safe_puts"
module VagrantPlugins
module CommandGem
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
include Vagrant::Util::SafePuts
def execute

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandGem
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "gem command"
description <<-DESC
Provides an interface to RubyGems that can be used to install

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandHalt
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandHalt
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "halt command"
description <<-DESC
The `halt` command halts your virtual machine.

View File

@ -4,7 +4,7 @@ require 'vagrant/util/template_renderer'
module VagrantPlugins
module CommandInit
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandInit
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "init command"
description <<-DESC
The `init` command sets up your working directory to be a

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandPackage
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
options = {}
@ -52,7 +52,7 @@ module VagrantPlugins
# better in the future. We just hardcode this to keep VirtualBox working
# for now.
provider = nil
Vagrant.plugin("1").registered.each do |plugin|
Vagrant.plugin("2").registered.each do |plugin|
provider = plugin.provider.get(:virtualbox)
break if provider
end

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandPackage
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "package command"
description <<-DESC
The `package` command will take a previously existing Vagrant

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandProvision
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant provision [vm-name]"

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandProvision
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "provision command"
description <<-DESC
The `provision` command provisions your virtual machine based on the

View File

@ -6,7 +6,7 @@ require Vagrant.source_root.join("plugins/commands/up/start_mixins")
module VagrantPlugins
module CommandReload
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
# We assume that the `up` plugin exists and that we'll have access
# to this.
include VagrantPlugins::CommandUp::StartMixins

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandReload
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "reload command"
description <<-DESC
The `reload` command will halt, reconfigure your machine based on

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandResume
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant resume [vm-name]"

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandResume
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "resume command"
description <<-DESC
The `resume` command resumes a suspend virtual machine.

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandSSH
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandSSH
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "ssh command"
description <<-DESC
The `ssh` command provides SSH access to the virtual machine.

View File

@ -4,7 +4,7 @@ require "vagrant/util/safe_puts"
module VagrantPlugins
module CommandSSHConfig
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
include Vagrant::Util::SafePuts
def execute

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandSSHConfig
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "ssh-config command"
description <<-DESC
The `ssh-config` command dumps an OpenSSH compatible configuration

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandStatus
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
options = {}

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandStatus
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "status command"
description <<-DESC
The `status` command shows the status of all your virtual machines

View File

@ -2,7 +2,7 @@ require 'optparse'
module VagrantPlugins
module CommandSuspend
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant suspend [vm-name]"

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandSuspend
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "suspend command"
description <<-DESC
The `suspend` command suspends a running virtual machine.

View File

@ -6,7 +6,7 @@ require File.expand_path("../start_mixins", __FILE__)
module VagrantPlugins
module CommandUp
class Command < Vagrant.plugin("1", :command)
class Command < Vagrant.plugin("2", :command)
include StartMixins
def execute

View File

@ -2,7 +2,7 @@ require "vagrant"
module VagrantPlugins
module CommandUp
class Plugin < Vagrant.plugin("1")
class Plugin < Vagrant.plugin("2")
name "up command"
description <<-DESC
The `up` command brings the virtual environment up and running.