From e8370f0098f478b0051b042826683ecd023ac211 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 6 Nov 2012 21:05:14 -0800 Subject: [PATCH] Convert comands to V2 plugins. --- lib/vagrant.rb | 9 +++++++++ lib/vagrant/cli.rb | 15 ++++----------- lib/vagrant/plugin/v2/manager.rb | 13 +++++++++++++ plugins/commands/box/command/add.rb | 2 +- plugins/commands/box/command/list.rb | 2 +- plugins/commands/box/command/remove.rb | 2 +- plugins/commands/box/command/repackage.rb | 2 +- plugins/commands/box/command/root.rb | 2 +- plugins/commands/box/plugin.rb | 2 +- plugins/commands/destroy/command.rb | 2 +- plugins/commands/destroy/plugin.rb | 2 +- plugins/commands/gem/command.rb | 2 +- plugins/commands/gem/plugin.rb | 2 +- plugins/commands/halt/command.rb | 2 +- plugins/commands/halt/plugin.rb | 2 +- plugins/commands/init/command.rb | 2 +- plugins/commands/init/plugin.rb | 2 +- plugins/commands/package/command.rb | 4 ++-- plugins/commands/package/plugin.rb | 2 +- plugins/commands/provision/command.rb | 2 +- plugins/commands/provision/plugin.rb | 2 +- plugins/commands/reload/command.rb | 2 +- plugins/commands/reload/plugin.rb | 2 +- plugins/commands/resume/command.rb | 2 +- plugins/commands/resume/plugin.rb | 2 +- plugins/commands/ssh/command.rb | 2 +- plugins/commands/ssh/plugin.rb | 2 +- plugins/commands/ssh_config/command.rb | 2 +- plugins/commands/ssh_config/plugin.rb | 2 +- plugins/commands/status/command.rb | 2 +- plugins/commands/status/plugin.rb | 2 +- plugins/commands/suspend/command.rb | 2 +- plugins/commands/suspend/plugin.rb | 2 +- plugins/commands/up/command.rb | 2 +- plugins/commands/up/plugin.rb | 2 +- 35 files changed, 59 insertions(+), 44 deletions(-) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index c7fd558a3..040ec3b93 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -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 diff --git a/lib/vagrant/cli.rb b/lib/vagrant/cli.rb index e5616b967..061bbe07a 100644 --- a/lib/vagrant/cli.rb +++ b/lib/vagrant/cli.rb @@ -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| diff --git a/lib/vagrant/plugin/v2/manager.rb b/lib/vagrant/plugin/v2/manager.rb index f8f1ff7f8..1f4207b1e 100644 --- a/lib/vagrant/plugin/v2/manager.rb +++ b/lib/vagrant/plugin/v2/manager.rb @@ -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] diff --git a/plugins/commands/box/command/add.rb b/plugins/commands/box/command/add.rb index f2af90389..1ab61b218 100644 --- a/plugins/commands/box/command/add.rb +++ b/plugins/commands/box/command/add.rb @@ -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 = {} diff --git a/plugins/commands/box/command/list.rb b/plugins/commands/box/command/list.rb index 28e2a8c0d..94a4d3964 100644 --- a/plugins/commands/box/command/list.rb +++ b/plugins/commands/box/command/list.rb @@ -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 = {} diff --git a/plugins/commands/box/command/remove.rb b/plugins/commands/box/command/remove.rb index c4751e14c..ceb619b1a 100644 --- a/plugins/commands/box/command/remove.rb +++ b/plugins/commands/box/command/remove.rb @@ -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 = {} diff --git a/plugins/commands/box/command/repackage.rb b/plugins/commands/box/command/repackage.rb index 39ebd3b20..fc19a5d2d 100644 --- a/plugins/commands/box/command/repackage.rb +++ b/plugins/commands/box/command/repackage.rb @@ -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 = {} diff --git a/plugins/commands/box/command/root.rb b/plugins/commands/box/command/root.rb index 5ba7754c7..c8589b7da 100644 --- a/plugins/commands/box/command/root.rb +++ b/plugins/commands/box/command/root.rb @@ -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 diff --git a/plugins/commands/box/plugin.rb b/plugins/commands/box/plugin.rb index 5834e85a9..bc19f99f6 100644 --- a/plugins/commands/box/plugin.rb +++ b/plugins/commands/box/plugin.rb @@ -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." diff --git a/plugins/commands/destroy/command.rb b/plugins/commands/destroy/command.rb index d0ef4b169..2a1dc5408 100644 --- a/plugins/commands/destroy/command.rb +++ b/plugins/commands/destroy/command.rb @@ -1,6 +1,6 @@ module VagrantPlugins module CommandDestroy - class Command < Vagrant.plugin("1", :command) + class Command < Vagrant.plugin("2", :command) def execute options = {} diff --git a/plugins/commands/destroy/plugin.rb b/plugins/commands/destroy/plugin.rb index 937900684..0e657794b 100644 --- a/plugins/commands/destroy/plugin.rb +++ b/plugins/commands/destroy/plugin.rb @@ -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." diff --git a/plugins/commands/gem/command.rb b/plugins/commands/gem/command.rb index 6e5d00e69..f9b47b842 100644 --- a/plugins/commands/gem/command.rb +++ b/plugins/commands/gem/command.rb @@ -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 diff --git a/plugins/commands/gem/plugin.rb b/plugins/commands/gem/plugin.rb index 4b1aab80c..b2635785d 100644 --- a/plugins/commands/gem/plugin.rb +++ b/plugins/commands/gem/plugin.rb @@ -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 diff --git a/plugins/commands/halt/command.rb b/plugins/commands/halt/command.rb index 1bda63eea..9d0ee5342 100644 --- a/plugins/commands/halt/command.rb +++ b/plugins/commands/halt/command.rb @@ -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 = {} diff --git a/plugins/commands/halt/plugin.rb b/plugins/commands/halt/plugin.rb index fa48aaeb6..d05a60886 100644 --- a/plugins/commands/halt/plugin.rb +++ b/plugins/commands/halt/plugin.rb @@ -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. diff --git a/plugins/commands/init/command.rb b/plugins/commands/init/command.rb index 6fba48900..aaf4f0d8d 100644 --- a/plugins/commands/init/command.rb +++ b/plugins/commands/init/command.rb @@ -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 = {} diff --git a/plugins/commands/init/plugin.rb b/plugins/commands/init/plugin.rb index 7d8c7cd59..08cb2c73d 100644 --- a/plugins/commands/init/plugin.rb +++ b/plugins/commands/init/plugin.rb @@ -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 diff --git a/plugins/commands/package/command.rb b/plugins/commands/package/command.rb index 02338aa9d..f7e09eba9 100644 --- a/plugins/commands/package/command.rb +++ b/plugins/commands/package/command.rb @@ -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 diff --git a/plugins/commands/package/plugin.rb b/plugins/commands/package/plugin.rb index 7bb477ad4..5e22f0f72 100644 --- a/plugins/commands/package/plugin.rb +++ b/plugins/commands/package/plugin.rb @@ -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 diff --git a/plugins/commands/provision/command.rb b/plugins/commands/provision/command.rb index bbaa4044e..ba8d2800c 100644 --- a/plugins/commands/provision/command.rb +++ b/plugins/commands/provision/command.rb @@ -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]" diff --git a/plugins/commands/provision/plugin.rb b/plugins/commands/provision/plugin.rb index 38e0f84b7..ba32dd883 100644 --- a/plugins/commands/provision/plugin.rb +++ b/plugins/commands/provision/plugin.rb @@ -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 diff --git a/plugins/commands/reload/command.rb b/plugins/commands/reload/command.rb index 718a45917..fd7fd9c61 100644 --- a/plugins/commands/reload/command.rb +++ b/plugins/commands/reload/command.rb @@ -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 diff --git a/plugins/commands/reload/plugin.rb b/plugins/commands/reload/plugin.rb index 302546734..8d5e87eaa 100644 --- a/plugins/commands/reload/plugin.rb +++ b/plugins/commands/reload/plugin.rb @@ -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 diff --git a/plugins/commands/resume/command.rb b/plugins/commands/resume/command.rb index db942b48d..92b544918 100644 --- a/plugins/commands/resume/command.rb +++ b/plugins/commands/resume/command.rb @@ -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]" diff --git a/plugins/commands/resume/plugin.rb b/plugins/commands/resume/plugin.rb index 9244bfec3..654f04417 100644 --- a/plugins/commands/resume/plugin.rb +++ b/plugins/commands/resume/plugin.rb @@ -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. diff --git a/plugins/commands/ssh/command.rb b/plugins/commands/ssh/command.rb index a9b73dad8..a062f81fe 100644 --- a/plugins/commands/ssh/command.rb +++ b/plugins/commands/ssh/command.rb @@ -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 = {} diff --git a/plugins/commands/ssh/plugin.rb b/plugins/commands/ssh/plugin.rb index 8b3ebe6e8..f9bfee9a8 100644 --- a/plugins/commands/ssh/plugin.rb +++ b/plugins/commands/ssh/plugin.rb @@ -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. diff --git a/plugins/commands/ssh_config/command.rb b/plugins/commands/ssh_config/command.rb index 05bb65f76..e1943b2c5 100644 --- a/plugins/commands/ssh_config/command.rb +++ b/plugins/commands/ssh_config/command.rb @@ -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 diff --git a/plugins/commands/ssh_config/plugin.rb b/plugins/commands/ssh_config/plugin.rb index e195cdec1..cfbeab0f8 100644 --- a/plugins/commands/ssh_config/plugin.rb +++ b/plugins/commands/ssh_config/plugin.rb @@ -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 diff --git a/plugins/commands/status/command.rb b/plugins/commands/status/command.rb index 0b4e7526e..2d0733806 100644 --- a/plugins/commands/status/command.rb +++ b/plugins/commands/status/command.rb @@ -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 = {} diff --git a/plugins/commands/status/plugin.rb b/plugins/commands/status/plugin.rb index efa68566e..b980a1a08 100644 --- a/plugins/commands/status/plugin.rb +++ b/plugins/commands/status/plugin.rb @@ -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 diff --git a/plugins/commands/suspend/command.rb b/plugins/commands/suspend/command.rb index 6183b71d3..7e33f819d 100644 --- a/plugins/commands/suspend/command.rb +++ b/plugins/commands/suspend/command.rb @@ -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]" diff --git a/plugins/commands/suspend/plugin.rb b/plugins/commands/suspend/plugin.rb index fafe54f41..1aa9ee0f6 100644 --- a/plugins/commands/suspend/plugin.rb +++ b/plugins/commands/suspend/plugin.rb @@ -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. diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index 186f0c98e..e3b6088cd 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -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 diff --git a/plugins/commands/up/plugin.rb b/plugins/commands/up/plugin.rb index 40f6e8f0b..a01c054f9 100644 --- a/plugins/commands/up/plugin.rb +++ b/plugins/commands/up/plugin.rb @@ -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.