summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-03-30 16:56:40 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-04 10:19:53 -0700
commit512778f95058a423a3d2e08d1803eb4a90fb975a (patch)
treec2bdda6ef44b3e040a4272f576cbdc4528f961d5 /lib
parent3bb614525f625a688baf8d67c5a580f8a51f4cad (diff)
downloadpuppet-512778f95058a423a3d2e08d1803eb4a90fb975a.tar.gz
puppet-512778f95058a423a3d2e08d1803eb4a90fb975a.tar.xz
puppet-512778f95058a423a3d2e08d1803eb4a90fb975a.zip
(#6749) detect duplicate aliases in a single option statement.
This ensures that an option declaration that shadows itself is found, and reported to the user, rather than silently eating one of the two. This could have actually lost, for example, the distinction between an argument-requiring and an argument-missing variant of the same thing. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/string/option.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/puppet/string/option.rb b/lib/puppet/string/option.rb
index 26b769c2e..70d62a01f 100644
--- a/lib/puppet/string/option.rb
+++ b/lib/puppet/string/option.rb
@@ -1,5 +1,5 @@
class Puppet::String::Option
- attr_reader :string
+ attr_reader :parent
attr_reader :name
attr_reader :aliases
attr_accessor :desc
@@ -11,17 +11,26 @@ class Puppet::String::Option
!!@optional_argument
end
- def initialize(string, *declaration, &block)
- @string = string
+ def initialize(parent, *declaration, &block)
+ @parent = parent
@optparse = []
# Collect and sort the arguments in the declaration.
+ dups = {}
declaration.each do |item|
if item.is_a? String and item.to_s =~ /^-/ then
unless item =~ /^-[a-z]\b/ or item =~ /^--[^-]/ then
raise ArgumentError, "#{item.inspect}: long options need two dashes (--)"
end
@optparse << item
+
+ # Duplicate checking...
+ name = optparse_to_name(item)
+ if dup = dups[name] then
+ raise ArgumentError, "#{item.inspect}: duplicates existing alias #{dup.inspect} in #{@parent}"
+ else
+ dups[name] = item
+ end
else
raise ArgumentError, "#{item.inspect} is not valid for an option argument"
end