From a1b37980e3480734c97306e8206ccc57b217c847 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 23 May 2012 16:18:29 -0700 Subject: [PATCH] Defer loading for commands to last possible moment --- plugins/commands/box/command/root.rb | 23 +++++++++++++++++++---- plugins/commands/box/plugin.rb | 9 ++------- plugins/commands/destroy/plugin.rb | 5 ++--- plugins/commands/gem/plugin.rb | 5 ++--- plugins/commands/halt/plugin.rb | 5 ++--- plugins/commands/init/plugin.rb | 5 ++--- plugins/commands/package/plugin.rb | 5 ++--- plugins/commands/provision/plugin.rb | 5 ++--- plugins/commands/reload/command.rb | 4 ++++ plugins/commands/reload/plugin.rb | 5 ++--- plugins/commands/resume/plugin.rb | 5 ++--- plugins/commands/ssh/plugin.rb | 5 ++--- plugins/commands/ssh_config/plugin.rb | 5 ++--- plugins/commands/status/plugin.rb | 5 ++--- plugins/commands/suspend/plugin.rb | 5 ++--- plugins/commands/up/command.rb | 4 ++++ plugins/commands/up/plugin.rb | 9 ++------- 17 files changed, 55 insertions(+), 54 deletions(-) diff --git a/plugins/commands/box/command/root.rb b/plugins/commands/box/command/root.rb index 80a439051..1817989e2 100644 --- a/plugins/commands/box/command/root.rb +++ b/plugins/commands/box/command/root.rb @@ -10,10 +10,25 @@ module VagrantPlugins @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv) @subcommands = Vagrant::Registry.new - @subcommands.register(:add) { Add } - @subcommands.register(:list) { List } - @subcommands.register(:remove) { Remove } - @subcommands.register(:repackage) { Repackage } + @subcommands.register(:add) do + require File.expand_path("../add", __FILE__) + Add + end + + @subcommands.register(:list) do + require File.expand_path("../list", __FILE__) + List + end + + @subcommands.register(:remove) do + require File.expand_path("../remove", __FILE__) + Remove + end + + @subcommands.register(:repackage) do + require File.expand_path("../repackage", __FILE__) + Repackage + end end def execute diff --git a/plugins/commands/box/plugin.rb b/plugins/commands/box/plugin.rb index 1ece8a3dc..5834e85a9 100644 --- a/plugins/commands/box/plugin.rb +++ b/plugins/commands/box/plugin.rb @@ -6,15 +6,10 @@ module VagrantPlugins name "box command" description "The `box` command gives you a way to manage boxes." - activated do + command("box") do require File.expand_path("../command/root", __FILE__) - require File.expand_path("../command/add", __FILE__) - require File.expand_path("../command/list", __FILE__) - require File.expand_path("../command/remove", __FILE__) - require File.expand_path("../command/repackage", __FILE__) + Command::Root end - - command("box") { Command::Root } end end end diff --git a/plugins/commands/destroy/plugin.rb b/plugins/commands/destroy/plugin.rb index 0bf2aa9bf..937900684 100644 --- a/plugins/commands/destroy/plugin.rb +++ b/plugins/commands/destroy/plugin.rb @@ -6,11 +6,10 @@ module VagrantPlugins name "destroy command" description "The `destroy` command destroys your virtual machines." - activated do + command("destroy") do require File.expand_path("../command", __FILE__) + Command end - - command("destroy") { Command } end end end diff --git a/plugins/commands/gem/plugin.rb b/plugins/commands/gem/plugin.rb index bb4bce350..4b1aab80c 100644 --- a/plugins/commands/gem/plugin.rb +++ b/plugins/commands/gem/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins RubyGems into the Vagrant environment. DESC - activated do + command("gem") do require File.expand_path("../command", __FILE__) + Command end - - command("gem") { Command } end end end diff --git a/plugins/commands/halt/plugin.rb b/plugins/commands/halt/plugin.rb index 7df6b9fa6..fa48aaeb6 100644 --- a/plugins/commands/halt/plugin.rb +++ b/plugins/commands/halt/plugin.rb @@ -8,11 +8,10 @@ module VagrantPlugins The `halt` command halts your virtual machine. DESC - activated do + command("halt") do require File.expand_path("../command", __FILE__) + Command end - - command("halt") { Command } end end end diff --git a/plugins/commands/init/plugin.rb b/plugins/commands/init/plugin.rb index 19b04d4ca..7d8c7cd59 100644 --- a/plugins/commands/init/plugin.rb +++ b/plugins/commands/init/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins Vagrant-managed environment. DESC - activated do + command("init") do require File.expand_path("../command", __FILE__) + Command end - - command("init") { Command } end end end diff --git a/plugins/commands/package/plugin.rb b/plugins/commands/package/plugin.rb index 8d0c20935..7bb477ad4 100644 --- a/plugins/commands/package/plugin.rb +++ b/plugins/commands/package/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins environment and package it into a box file. DESC - activated do + command("package") do require File.expand_path("../command", __FILE__) + Command end - - command("package") { Command } end end end diff --git a/plugins/commands/provision/plugin.rb b/plugins/commands/provision/plugin.rb index 5a02e4ea0..38e0f84b7 100644 --- a/plugins/commands/provision/plugin.rb +++ b/plugins/commands/provision/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins configuration of the Vagrantfile. DESC - activated do + command("provision") do require File.expand_path("../command", __FILE__) + Command end - - command("provision") { Command } end end end diff --git a/plugins/commands/reload/command.rb b/plugins/commands/reload/command.rb index abd1628dc..81ea71cca 100644 --- a/plugins/commands/reload/command.rb +++ b/plugins/commands/reload/command.rb @@ -1,5 +1,9 @@ require 'optparse' +require "vagrant" + +require Vagrant.source_root.join("plugins/commands/up/start_mixins") + module VagrantPlugins module CommandReload class Command < Vagrant::Command::Base diff --git a/plugins/commands/reload/plugin.rb b/plugins/commands/reload/plugin.rb index e67757291..302546734 100644 --- a/plugins/commands/reload/plugin.rb +++ b/plugins/commands/reload/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins the Vagrantfile, and bring it back up. DESC - activated do + command("reload") do require File.expand_path("../command", __FILE__) + Command end - - command("reload") { Command } end end end diff --git a/plugins/commands/resume/plugin.rb b/plugins/commands/resume/plugin.rb index 3774adf88..9244bfec3 100644 --- a/plugins/commands/resume/plugin.rb +++ b/plugins/commands/resume/plugin.rb @@ -8,11 +8,10 @@ module VagrantPlugins The `resume` command resumes a suspend virtual machine. DESC - activated do + command("resume") do require File.expand_path("../command", __FILE__) + Command end - - command("resume") { Command } end end end diff --git a/plugins/commands/ssh/plugin.rb b/plugins/commands/ssh/plugin.rb index bc655c8f1..8b3ebe6e8 100644 --- a/plugins/commands/ssh/plugin.rb +++ b/plugins/commands/ssh/plugin.rb @@ -8,11 +8,10 @@ module VagrantPlugins The `ssh` command provides SSH access to the virtual machine. DESC - activated do + command("ssh") do require File.expand_path("../command", __FILE__) + Command end - - command("ssh") { Command } end end end diff --git a/plugins/commands/ssh_config/plugin.rb b/plugins/commands/ssh_config/plugin.rb index 67a80da68..e195cdec1 100644 --- a/plugins/commands/ssh_config/plugin.rb +++ b/plugins/commands/ssh_config/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins that can be used to quickly SSH into your virtual machine. DESC - activated do + command("ssh-config") do require File.expand_path("../command", __FILE__) + Command end - - command("ssh-config") { Command } end end end diff --git a/plugins/commands/status/plugin.rb b/plugins/commands/status/plugin.rb index 0b14b5b89..efa68566e 100644 --- a/plugins/commands/status/plugin.rb +++ b/plugins/commands/status/plugin.rb @@ -9,11 +9,10 @@ module VagrantPlugins in this environment. DESC - activated do + command("status") do require File.expand_path("../command", __FILE__) + Command end - - command("status") { Command } end end end diff --git a/plugins/commands/suspend/plugin.rb b/plugins/commands/suspend/plugin.rb index bddfc80ed..fafe54f41 100644 --- a/plugins/commands/suspend/plugin.rb +++ b/plugins/commands/suspend/plugin.rb @@ -8,11 +8,10 @@ module VagrantPlugins The `suspend` command suspends a running virtual machine. DESC - activated do + command("suspend") do require File.expand_path("../command", __FILE__) + Command end - - command("suspend") { Command } end end end diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index bfe89eb17..e013b637d 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -1,5 +1,9 @@ require 'optparse' +require "vagrant" + +require File.expand_path("../start_mixins", __FILE__) + module VagrantPlugins module CommandUp class Command < Vagrant::Command::Base diff --git a/plugins/commands/up/plugin.rb b/plugins/commands/up/plugin.rb index 2f9b126a5..40f6e8f0b 100644 --- a/plugins/commands/up/plugin.rb +++ b/plugins/commands/up/plugin.rb @@ -1,9 +1,5 @@ require "vagrant" -# These are used by various other commands, so we just load them -# up right away. -require File.expand_path("../start_mixins", __FILE__) - module VagrantPlugins module CommandUp class Plugin < Vagrant.plugin("1") @@ -12,11 +8,10 @@ module VagrantPlugins The `up` command brings the virtual environment up and running. DESC - activated do + command("up") do require File.expand_path("../command", __FILE__) + Command end - - command("up") { Command } end end end