diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-07-10 18:47:18 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-07-10 18:47:18 -0700 |
commit | c78512254c655de1d66d0a300b5a7db4cd09adce (patch) | |
tree | 07017ad1aea4725bcc0c01ab309aa5415f87bceb | |
parent | 41881272af33a831baec0c491565586cd5f1b77f (diff) | |
download | chef-c78512254c655de1d66d0a300b5a7db4cd09adce.tar.gz |
Add support for knife commands with hyphens.
This works exactly like with an underscore, but is a bit more user-friendly sometimes (e.g. `get_config` vs `get-config`).
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r-- | lib/chef/knife.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/core/subcommand_loader.rb | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index e28ca81f71..6e525bdf3d 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -304,8 +304,12 @@ class Chef # knife node run_list add requires that we have extra logic to handle # the case that command name words could be joined by an underscore :/ - command_name_words = command_name_words.join("_") - @name_args.reject! { |name_arg| command_name_words == name_arg } + command_name_joined = command_name_words.join("_") + @name_args.reject! { |name_arg| command_name_joined == name_arg } + + # Similar handling for hyphens. + command_name_joined = command_name_words.join("-") + @name_args.reject! { |name_arg| command_name_joined == name_arg } if config[:help] msg opt_parser diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 146411a399..fb3723de50 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -142,7 +142,7 @@ class Chef words = words.dup match = nil until match || words.empty? - candidate = words.join(sep) + candidate = words.join(sep).tr("-", "_") if hash.key?(candidate) match = candidate else |