From 0b97bd0df57dd6732db5f52fc7360f61e74dba2e Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 5 Apr 2011 11:36:18 -0700 Subject: (#6972) Clean up OptParse name extraction a little. During testing, an obvious cleanup showed up for the name extraction here, so we implement it. This extends the regexp to better extract the data we want rather than hacking it up post-match and having to do extra validation to make sure it actually worked. Reviewed-By: Dan Bode --- lib/puppet/string/option.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/string/option.rb b/lib/puppet/string/option.rb index f499e4b95..be7bbb76e 100644 --- a/lib/puppet/string/option.rb +++ b/lib/puppet/string/option.rb @@ -70,10 +70,10 @@ class Puppet::String::Option end def optparse_to_name(declaration) - unless found = declaration.match(/^-+([^= ]+)/) or found.length != 1 then + unless found = declaration.match(/^-+(?:\[no-\])?([^ =]+)/) then raise ArgumentError, "Can't find a name in the declaration #{declaration.inspect}" end - name = found.captures.first.sub('[no-]', '').tr('-', '_') + name = found.captures.first.tr('-', '_') raise "#{name.inspect} is an invalid option name" unless name.to_s =~ /^[a-z]\w*$/ name.to_sym end -- cgit