summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-07-15 11:15:21 -0700
committerGitHub <noreply@github.com>2020-07-15 11:15:21 -0700
commit5974b0eeb54b7f90967b393cf83caf086a1064fa (patch)
tree56cb6fe281382e0d03454b61bc3be5cc60806181
parent885e007cfc4381ac4a22f988e154ed2325636366 (diff)
parent297c549dc21c90db806478a526f2167c8769a600 (diff)
downloadchef-5974b0eeb54b7f90967b393cf83caf086a1064fa.tar.gz
Merge pull request #10159 from chef/rehash_to_loader
Move the rehash methods into the subcommand loader
-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