summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-06-03 11:06:14 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:35 -0700
commit9c16e305952a8f5787ba8e9e7bd618785903a32a (patch)
treee8c69ab319cdb2c673edbb5ae7455e4a22857d13
parentced6b7747cfce06813ca1e65b80f5d7aec23062d (diff)
downloadchef-9c16e305952a8f5787ba8e9e7bd618785903a32a.tar.gz
Don't load dependencies unless you run the command!
-rw-r--r--lib/chef/chef_fs/knife.rb27
-rw-r--r--lib/chef/knife/delete.rb5
-rw-r--r--lib/chef/knife/deps.rb7
-rw-r--r--lib/chef/knife/diff.rb5
-rw-r--r--lib/chef/knife/download.rb5
-rw-r--r--lib/chef/knife/edit.rb7
-rw-r--r--lib/chef/knife/list.rb7
-rw-r--r--lib/chef/knife/raw.rb10
-rw-r--r--lib/chef/knife/show.rb7
-rw-r--r--lib/chef/knife/upload.rb5
-rw-r--r--lib/chef/knife/xargs.rb7
-rw-r--r--spec/support/shared/integration/knife_support.rb5
12 files changed, 62 insertions, 35 deletions
diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb
index fcdf4e93be..f68cec8971 100644
--- a/lib/chef/chef_fs/knife.rb
+++ b/lib/chef/chef_fs/knife.rb
@@ -16,17 +16,23 @@
# limitations under the License.
#
-require 'chef/chef_fs/file_system/chef_server_root_dir'
-require 'chef/chef_fs/file_system/chef_repository_file_system_root_dir'
-require 'chef/chef_fs/file_pattern'
-require 'chef/chef_fs/path_utils'
-require 'chef/chef_fs/parallelizer'
-require 'chef/config'
+require 'chef/knife'
class Chef
module ChefFS
class Knife < Chef::Knife
- def self.common_options
+ # Workaround for CHEF-3932
+ def self.deps
+ super do
+ require 'chef/chef_fs/file_system/chef_server_root_dir'
+ require 'chef/chef_fs/file_system/chef_repository_file_system_root_dir'
+ require 'chef/chef_fs/file_pattern'
+ require 'chef/chef_fs/path_utils'
+ require 'chef/chef_fs/parallelizer'
+ require 'chef/config'
+ yield
+ end
+
option :repo_mode,
:long => '--repo-mode MODE',
:description => "Specifies the local repository layout. Values: static, everything, hosted_everything. Default: everything/hosted_everything"
@@ -40,6 +46,13 @@ class Chef
:description => 'Maximum number of simultaneous requests to send (default: 10)'
end
+ def self.inherited(c)
+ super
+ # Ensure we always get to do our includes, whether subclass calls deps or not
+ c.deps do
+ end
+ end
+
def configure_chef
super
Chef::Config[:repo_mode] = config[:repo_mode] if config[:repo_mode]
diff --git a/lib/chef/knife/delete.rb b/lib/chef/knife/delete.rb
index cf65b8994b..344d3bed97 100644
--- a/lib/chef/knife/delete.rb
+++ b/lib/chef/knife/delete.rb
@@ -1,12 +1,13 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/file_system'
class Chef
class Knife
class Delete < Chef::ChefFS::Knife
banner "knife delete [PATTERN1 ... PATTERNn]"
- common_options
+ deps do
+ require 'chef/chef_fs/file_system'
+ end
option :recurse,
:short => '-r',
diff --git a/lib/chef/knife/deps.rb b/lib/chef/knife/deps.rb
index d020629f64..c4b3678ff8 100644
--- a/lib/chef/knife/deps.rb
+++ b/lib/chef/knife/deps.rb
@@ -1,13 +1,14 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/file_system'
-require 'chef/run_list'
class Chef
class Knife
class Deps < Chef::ChefFS::Knife
banner "knife deps PATTERN1 [PATTERNn]"
- common_options
+ deps do
+ require 'chef/chef_fs/file_system'
+ require 'chef/run_list'
+ end
option :recurse,
:long => '--[no-]recurse',
diff --git a/lib/chef/knife/diff.rb b/lib/chef/knife/diff.rb
index 154a5940e9..5a3a80544d 100644
--- a/lib/chef/knife/diff.rb
+++ b/lib/chef/knife/diff.rb
@@ -1,12 +1,13 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/command_line'
class Chef
class Knife
class Diff < Chef::ChefFS::Knife
banner "knife diff PATTERNS"
- common_options
+ deps do
+ require 'chef/chef_fs/command_line'
+ end
option :recurse,
:long => '--[no-]recurse',
diff --git a/lib/chef/knife/download.rb b/lib/chef/knife/download.rb
index a8178a9434..e8f26a74aa 100644
--- a/lib/chef/knife/download.rb
+++ b/lib/chef/knife/download.rb
@@ -1,12 +1,13 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/command_line'
class Chef
class Knife
class Download < Chef::ChefFS::Knife
banner "knife download PATTERNS"
- common_options
+ deps do
+ require 'chef/chef_fs/command_line'
+ end
option :recurse,
:long => '--[no-]recurse',
diff --git a/lib/chef/knife/edit.rb b/lib/chef/knife/edit.rb
index 79e46957ca..ea068cb250 100644
--- a/lib/chef/knife/edit.rb
+++ b/lib/chef/knife/edit.rb
@@ -1,13 +1,14 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/file_system'
-require 'chef/chef_fs/file_system/not_found_error'
class Chef
class Knife
class Edit < Chef::ChefFS::Knife
banner "knife edit [PATTERN1 ... PATTERNn]"
- common_options
+ deps do
+ require 'chef/chef_fs/file_system'
+ require 'chef/chef_fs/file_system/not_found_error'
+ end
option :local,
:long => '--local',
diff --git a/lib/chef/knife/list.rb b/lib/chef/knife/list.rb
index 296a5392ad..83d5c5a8c4 100644
--- a/lib/chef/knife/list.rb
+++ b/lib/chef/knife/list.rb
@@ -1,13 +1,14 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/file_system'
-require 'highline'
class Chef
class Knife
class List < Chef::ChefFS::Knife
banner "knife list [-dfR1p] [PATTERN1 ... PATTERNn]"
- common_options
+ deps do
+ require 'chef/chef_fs/file_system'
+ require 'highline'
+ end
option :recursive,
:short => '-R',
diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb
index 3aa4fd8049..c2195ad224 100644
--- a/lib/chef/knife/raw.rb
+++ b/lib/chef/knife/raw.rb
@@ -1,12 +1,16 @@
-require 'json'
-require 'chef/chef_fs/data_handler/data_handler_base'
-require 'chef/chef_fs/raw_request'
+require 'chef/knife'
class Chef
class Knife
class Raw < Chef::Knife
banner "knife raw REQUEST_PATH"
+ deps do
+ require 'json'
+ require 'chef/chef_fs/data_handler/data_handler_base'
+ require 'chef/chef_fs/raw_request'
+ end
+
option :method,
:long => '--method METHOD',
:short => '-m METHOD',
diff --git a/lib/chef/knife/show.rb b/lib/chef/knife/show.rb
index 518d8c9ca5..b5e8aa9882 100644
--- a/lib/chef/knife/show.rb
+++ b/lib/chef/knife/show.rb
@@ -1,13 +1,14 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/file_system'
-require 'chef/chef_fs/file_system/not_found_error'
class Chef
class Knife
class Show < Chef::ChefFS::Knife
banner "knife show [PATTERN1 ... PATTERNn]"
- common_options
+ deps do
+ require 'chef/chef_fs/file_system'
+ require 'chef/chef_fs/file_system/not_found_error'
+ end
option :local,
:long => '--local',
diff --git a/lib/chef/knife/upload.rb b/lib/chef/knife/upload.rb
index 8bc3f411ff..d2e5708aa8 100644
--- a/lib/chef/knife/upload.rb
+++ b/lib/chef/knife/upload.rb
@@ -1,12 +1,13 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/command_line'
class Chef
class Knife
class Upload < Chef::ChefFS::Knife
banner "knife upload PATTERNS"
- common_options
+ deps do
+ require 'chef/chef_fs/command_line'
+ end
option :recurse,
:long => '--[no-]recurse',
diff --git a/lib/chef/knife/xargs.rb b/lib/chef/knife/xargs.rb
index 0a34f380ce..be6db9d64f 100644
--- a/lib/chef/knife/xargs.rb
+++ b/lib/chef/knife/xargs.rb
@@ -1,13 +1,14 @@
require 'chef/chef_fs/knife'
-require 'chef/chef_fs/file_system'
-require 'chef/chef_fs/file_system/not_found_error'
class Chef
class Knife
class Xargs < Chef::ChefFS::Knife
banner "knife xargs [COMMAND]"
- common_options
+ deps do
+ require 'chef/chef_fs/file_system'
+ require 'chef/chef_fs/file_system/not_found_error'
+ end
# TODO modify to remote-only / local-only pattern (more like delete)
option :local,
diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb
index 7f4078f591..ce07414a65 100644
--- a/spec/support/shared/integration/knife_support.rb
+++ b/spec/support/shared/integration/knife_support.rb
@@ -27,8 +27,8 @@ module KnifeSupport
:skip_expires => true
}
- # This is Chef::Knife.run without load_commands and load_deps--we'll
- # load stuff ourselves, thank you very much
+ # This is Chef::Knife.run without load_commands--we'll load stuff
+ # ourselves, thank you very much
stdout = StringIO.new
stderr = StringIO.new
old_loggers = Chef::Log.loggers
@@ -37,6 +37,7 @@ module KnifeSupport
puts "knife: #{args.join(' ')}" if DEBUG
subcommand_class = Chef::Knife.subcommand_class_from(args)
subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options)
+ subcommand_class.load_deps
instance = subcommand_class.new(args)
# Capture stdout/stderr