diff options
author | Tim Smith <tsmith@chef.io> | 2018-07-10 21:29:55 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-07-10 21:29:55 -0700 |
commit | b9c07e97cc1570f6850abf567685952fc6815bd6 (patch) | |
tree | 32834c7d76e0f2764812b4cfccceb04d1aadc5b6 | |
parent | 293eb409c165b0080178f378211dde1cbb81c916 (diff) | |
download | chef-b9c07e97cc1570f6850abf567685952fc6815bd6.tar.gz |
Mildly speed up knife by moving deps into dep blocks
We can lazily load the requirements for knife plugins, but we don't do that for all our plugins. We should. Is this a game changer? Nope. It does make it 4% faster though, which makes it worth doing.
Side note: We have some dupe requires in here and we also requires mixlib-shellout and mixin-shellout when we only used mixin-shellout.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/configure.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_install.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 9 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_upload.rb | 1 | ||||
-rw-r--r-- | lib/chef/knife/data_bag_from_file.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/exec.rb | 5 | ||||
-rw-r--r-- | lib/chef/knife/node_show.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/raw.rb | 1 | ||||
-rw-r--r-- | lib/chef/knife/recipe_list.rb | 1 | ||||
-rw-r--r-- | lib/chef/knife/serve.rb | 5 | ||||
-rw-r--r-- | lib/chef/knife/ssh.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/status.rb | 7 |
13 files changed, 24 insertions, 22 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 797080abe3..25b5e43b63 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -18,7 +18,6 @@ require "chef/knife" require "chef/knife/data_bag_secret_options" -require "erubis" require "chef/knife/bootstrap/chef_vault_handler" require "chef/knife/bootstrap/client_builder" require "chef/util/path_helper" @@ -32,6 +31,7 @@ class Chef attr_accessor :chef_vault_handler deps do + require "erubis" require "chef/knife/core/bootstrap_context" require "chef/json_compat" require "tempfile" diff --git a/lib/chef/knife/configure.rb b/lib/chef/knife/configure.rb index 4b33998eaa..4be7fa94bc 100644 --- a/lib/chef/knife/configure.rb +++ b/lib/chef/knife/configure.rb @@ -17,7 +17,6 @@ # require "chef/knife" -require "chef/util/path_helper" class Chef class Knife @@ -26,6 +25,7 @@ class Chef attr_reader :chef_repo, :new_client_key, :validation_client_name, :validation_key deps do + require "chef/util/path_helper" require "ohai" Chef::Knife::ClientCreate.load_deps Chef::Knife::UserCreate.load_deps diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index 18cddb19f4..040ae894e4 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -17,9 +17,6 @@ # require "chef/knife" -require "chef/exceptions" -require "shellwords" -require "mixlib/archive" class Chef class Knife @@ -29,6 +26,9 @@ class Chef require "chef/mixin/shell_out" require "chef/knife/core/cookbook_scm_repo" require "chef/cookbook/metadata" + require "chef/exceptions" + require "shellwords" + require "mixlib/archive" end banner "knife cookbook site install COOKBOOK [VERSION] (options)" diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index dcfd224295..bf75c61ef4 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -18,22 +18,19 @@ # require "chef/knife" -require "chef/mixin/shell_out" class Chef class Knife class CookbookSiteShare < Knife - include Chef::Mixin::ShellOut - deps do require "chef/cookbook_loader" require "chef/cookbook_uploader" require "chef/cookbook_site_streaming_uploader" - require "mixlib/shellout" - end + require "chef/mixin/shell_out" - include Chef::Mixin::ShellOut + include Chef::Mixin::ShellOut + end banner "knife cookbook site share COOKBOOK [CATEGORY] (options)" category "cookbook site" diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb index 2b3c6ba948..162df9dfb6 100644 --- a/lib/chef/knife/cookbook_upload.rb +++ b/lib/chef/knife/cookbook_upload.rb @@ -19,7 +19,6 @@ # require "chef/knife" -require "chef/cookbook_uploader" class Chef class Knife diff --git a/lib/chef/knife/data_bag_from_file.rb b/lib/chef/knife/data_bag_from_file.rb index 91adcb3129..9b1b84a295 100644 --- a/lib/chef/knife/data_bag_from_file.rb +++ b/lib/chef/knife/data_bag_from_file.rb @@ -18,7 +18,6 @@ # require "chef/knife" -require "chef/util/path_helper" require "chef/knife/data_bag_secret_options" class Chef @@ -27,6 +26,7 @@ class Chef include DataBagSecretOptions deps do + require "chef/util/path_helper" require "chef/data_bag" require "chef/data_bag_item" require "chef/knife/core/object_loader" diff --git a/lib/chef/knife/exec.rb b/lib/chef/knife/exec.rb index ed7101c0cc..6688403404 100644 --- a/lib/chef/knife/exec.rb +++ b/lib/chef/knife/exec.rb @@ -17,12 +17,15 @@ # require "chef/knife" -require "chef/util/path_helper" class Chef::Knife::Exec < Chef::Knife banner "knife exec [SCRIPT] (options)" + deps do + require "chef/util/path_helper" + end + option :exec, short: "-E CODE", long: "--exec CODE", diff --git a/lib/chef/knife/node_show.rb b/lib/chef/knife/node_show.rb index 43e7e9dbee..8fcd462030 100644 --- a/lib/chef/knife/node_show.rb +++ b/lib/chef/knife/node_show.rb @@ -17,7 +17,6 @@ # require "chef/knife" -require "chef/knife/core/node_presenter" class Chef class Knife @@ -27,6 +26,7 @@ class Chef include Knife::Core::MultiAttributeReturnOption deps do + require "chef/knife/core/node_presenter" require "chef/node" require "chef/json_compat" end diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb index 2d49c457fc..dc8f10ec4f 100644 --- a/lib/chef/knife/raw.rb +++ b/lib/chef/knife/raw.rb @@ -15,7 +15,6 @@ # require "chef/knife" -require "chef/http" class Chef class Knife diff --git a/lib/chef/knife/recipe_list.rb b/lib/chef/knife/recipe_list.rb index 8f76e494ad..67943cf146 100644 --- a/lib/chef/knife/recipe_list.rb +++ b/lib/chef/knife/recipe_list.rb @@ -17,6 +17,7 @@ # require "chef/knife" + class Chef::Knife::RecipeList < Chef::Knife banner "knife recipe list [PATTERN]" diff --git a/lib/chef/knife/serve.rb b/lib/chef/knife/serve.rb index eb5c98963c..6ad4ef25d5 100644 --- a/lib/chef/knife/serve.rb +++ b/lib/chef/knife/serve.rb @@ -15,7 +15,6 @@ # require "chef/knife" -require "chef/local_mode" class Chef class Knife @@ -23,6 +22,10 @@ class Chef banner "knife serve (options)" + deps do + require "chef/local_mode" + end + option :repo_mode, long: "--repo-mode MODE", description: "Specifies the local repository layout. Values: static (only environments/roles/data_bags/cookbooks), everything (includes nodes/clients/users), hosted_everything (includes acls/groups/etc. for Enterprise/Hosted Chef). Default: everything/hosted_everything" diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index cd29b62b75..4b550920dc 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -16,7 +16,6 @@ # limitations under the License. # -require "chef/mixin/shell_out" require "chef/knife" class Chef @@ -30,7 +29,7 @@ class Chef require "chef/exceptions" require "chef/search/query" require "chef/util/path_helper" - require "mixlib/shellout" + require "chef/mixin/shell_out" end include Chef::Mixin::ShellOut diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb index 413bff4f66..cee32490ec 100644 --- a/lib/chef/knife/status.rb +++ b/lib/chef/knife/status.rb @@ -17,16 +17,17 @@ # require "chef/knife" -require "chef/knife/core/status_presenter" -require "chef/knife/core/node_presenter" class Chef class Knife class Status < Knife - include Knife::Core::NodeFormattingOptions deps do + require "chef/knife/core/status_presenter" + require "chef/knife/core/node_presenter" require "chef/search/query" + + include Knife::Core::NodeFormattingOptions end banner "knife status QUERY (options)" |