summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2011-04-14 14:45:58 -0700
committerDaniel DeLeo <dan@opscode.com>2011-04-14 14:47:19 -0700
commitaaf38501ef93abecd9761428accf4898299c5937 (patch)
tree3995b7329338f56d96802de53f6d21292985b293
parentb5324dd7a58e1f6fddddd288d690bde31f2d1946 (diff)
downloadchef-aaf38501ef93abecd9761428accf4898299c5937.tar.gz
allow knife commands to be given in hypenated form
e.g., knife node-create
-rw-r--r--chef/lib/chef/knife.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/chef/lib/chef/knife.rb b/chef/lib/chef/knife.rb
index 1b28f5382e..78831a4150 100644
--- a/chef/lib/chef/knife.rb
+++ b/chef/lib/chef/knife.rb
@@ -167,7 +167,8 @@ class Chef
end
def self.guess_category(args)
- category_words = args.select {|arg| arg =~ /^([[:alnum:]]|_)+$/ }
+ category_words = args.select {|arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ }
+ category_words.map! {|w| w.split('-')}.flatten!
matching_category = nil
while (!matching_category) && (!category_words.empty?)
candidate_category = category_words.join(' ')
@@ -178,7 +179,8 @@ class Chef
end
def self.subcommand_class_from(args)
- command_words = args.select {|arg| arg =~ /^([[:alnum:]]|_)+$/ }
+ command_words = args.select {|arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ }
+
subcommand_class = nil
while ( !subcommand_class ) && ( !command_words.empty? )
@@ -187,6 +189,8 @@ class Chef
command_words.pop
end
end
+ # see if we got the command as e.g., knife node-list
+ subcommand_class ||= subcommands[args.first.gsub('-', '_')]
subcommand_class || subcommand_not_found!(args)
end
@@ -249,6 +253,7 @@ class Chef
# Mixlib::CLI ignores the embedded name_args
@name_args = parse_options(argv)
+ @name_args.delete(command_name_words.join('-'))
@name_args.reject! { |name_arg| command_name_words.delete(name_arg) }
# knife node run_list add requires that we have extra logic to handle
@@ -459,7 +464,7 @@ class Chef
pretty_name ||= output
- self.msg("Created (or updated) #{pretty_name}")
+ self.msg("Created #{pretty_name}")
output(output) if config[:print_after]
end