From 3f23d3a9e065b0903eac507a9bc7ef6d0e14fc66 Mon Sep 17 00:00:00 2001 From: "Marc A. Paradise" Date: Tue, 16 Feb 2021 15:50:24 -0500 Subject: Experimental: attempt to directly load known knife commands Instead of loading all of them then searching, try to load just the requested commanmd if we can find it by path. Signed-off-by: Marc A. Paradise --- lib/chef/knife/acl_base.rb | 1 + lib/chef/knife/core/subcommand_loader.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/acl_base.rb b/lib/chef/knife/acl_base.rb index 0835d1ac05..d9a0a222c3 100644 --- a/lib/chef/knife/acl_base.rb +++ b/lib/chef/knife/acl_base.rb @@ -22,6 +22,7 @@ require_relative "../knife" class Chef class Knife module AclBase + Kernel.puts "LOADING ANYWAY HAHAHAH" PERM_TYPES = %w{create read update delete grant}.freeze unless defined? PERM_TYPES MEMBER_TYPES = %w{client group user}.freeze unless defined? MEMBER_TYPES diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 26d7e0277c..6a67711d7f 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -111,7 +111,20 @@ class Chef load_commands end - def load_command(_command_args) + def load_command(command_args) + return true if @loaded + cmd_words = positional_arguments(command_args) + partial_path = "#{cmd_words.join("_")}.rb" + + # Take a best shot at loading the command before falling back to loading + # all commands. + subcommand_files.each do |file| + if file.end_with?(partial_path) + @loaded = true + Kernel.load file + end + end + # If we've set @loaded, this will noop load_commands end -- cgit v1.2.1