summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-14 18:01:01 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-14 18:01:01 -0700
commit297c549dc21c90db806478a526f2167c8769a600 (patch)
tree3831d5654477ca6bce1b5d0f5d3faca89c943b59 /lib
parent421013ce1b3ef89fc3d5fbb631b4816cb59f71eb (diff)
downloadchef-297c549dc21c90db806478a526f2167c8769a600.tar.gz
Move the rehash methods into the subcommand loaderrehash_to_loader
This way we can use them in chef-cli to rehash any time we install a gem. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/knife/core/subcommand_loader.rb19
-rw-r--r--lib/chef/knife/rehash.rb24
2 files changed, 22 insertions, 21 deletions
diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb
index b0f8381d64..26d7e0277c 100644
--- a/lib/chef/knife/core/subcommand_loader.rb
+++ b/lib/chef/knife/core/subcommand_loader.rb
@@ -75,6 +75,25 @@ class Chef
Chef::Util::PathHelper.home(".chef", "plugin_manifest.json")
end
+ def self.generate_hash
+ output = if plugin_manifest?
+ plugin_manifest
+ else
+ { Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY => {} }
+ end
+ output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_paths"] = Chef::Knife.subcommand_files
+ output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_by_category"] = Chef::Knife.subcommands_by_category
+ output
+ end
+
+ def self.write_hash(data)
+ plugin_manifest_dir = File.expand_path("..", plugin_manifest_path)
+ FileUtils.mkdir_p(plugin_manifest_dir) unless File.directory?(plugin_manifest_dir)
+ File.open(plugin_manifest_path, "w") do |f|
+ f.write(Chef::JSONCompat.to_json_pretty(data))
+ end
+ end
+
def initialize(chef_config_dir)
@chef_config_dir = chef_config_dir
end
diff --git a/lib/chef/knife/rehash.rb b/lib/chef/knife/rehash.rb
index 2d7c0c7700..69ee19229a 100644
--- a/lib/chef/knife/rehash.rb
+++ b/lib/chef/knife/rehash.rb
@@ -34,7 +34,9 @@ class Chef
else
reload_plugins
end
- write_hash(generate_hash)
+
+ ui.msg "Knife subcommands are cached in #{Chef::Knife::SubcommandLoader.plugin_manifest_path}. Delete this file to disable the caching."
+ Chef::Knife::SubcommandLoader.write_hash(Chef::Knife::SubcommandLoader.generate_hash)
end
def reload_plugins
@@ -43,26 +45,6 @@ class Chef
# loaded plugins and `load_commands` shouldn't have an effect.
Chef::Knife.subcommand_loader.load_commands
end
-
- def generate_hash
- output = if Chef::Knife::SubcommandLoader.plugin_manifest?
- Chef::Knife::SubcommandLoader.plugin_manifest
- else
- { Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY => {} }
- end
- output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_paths"] = Chef::Knife.subcommand_files
- output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_by_category"] = Chef::Knife.subcommands_by_category
- output
- end
-
- def write_hash(data)
- plugin_manifest_dir = File.expand_path("..", Chef::Knife::SubcommandLoader.plugin_manifest_path)
- FileUtils.mkdir_p(plugin_manifest_dir) unless File.directory?(plugin_manifest_dir)
- File.open(Chef::Knife::SubcommandLoader.plugin_manifest_path, "w") do |f|
- f.write(Chef::JSONCompat.to_json_pretty(data))
- ui.msg "Knife subcommands are cached in #{Chef::Knife::SubcommandLoader.plugin_manifest_path}. Delete this file to disable the caching."
- end
- end
end
end
end