lib/thor/options.rb in josevalim-thor-0.10.13 vs lib/thor/options.rb in josevalim-thor-0.10.14
- old
+ new
@@ -55,17 +55,12 @@
@arguments, @shorts, @options = [], {}, {}
@non_assigned_required, @non_assigned_arguments, @trailing = [], [], []
@switches = switches.values.inject({}) do |mem, option|
@non_assigned_required << option if option.required?
+ @non_assigned_arguments << option if option.argument?
- if option.argument?
- @non_assigned_arguments << option
- elsif !option.default.nil?
- @options[option.human_name] = option.default
- end
-
# If there are no shortcuts specified, generate one using the first character
shorts = option.aliases.dup
shorts << "-" + option.human_name[0,1] if shorts.empty? and option.human_name.length > 1
shorts.each { |short| @shorts[short.to_s] ||= option.switch_name }
@@ -108,11 +103,10 @@
@trailing << shift
end
end
end
- assign_arguments_default_values!
check_validity!
@options
end
private
@@ -151,12 +145,12 @@
end
# Returns the option object for the given switch.
#
def switch_option(arg)
- if arg =~ /^--no-(\w+)$/
- @switches[arg] || @switches["--#{$1}"]
+ if arg =~ /^--(no|skip)-([-\w]+)$/
+ @switches[arg] || @switches["--#{$2}"]
else
@switches[arg]
end
end
@@ -171,16 +165,20 @@
# assigned requireds are kept.
#
def parse_option(switch, option, hash)
human_name = option.human_name
- case option.type
- when :default
- hash[human_name] = peek.nil? || peek.to_s =~ /^-/ || shift
+ type = if option.type == :default
+ peek.nil? || peek.to_s =~ /^-/ ? :boolean : :string
+ else
+ option.type
+ end
+
+ case type
when :boolean
- if !@switches.key?(switch) && switch =~ /^--no-(\w+)$/
- hash[$1] = false
+ if !@switches.key?(switch) && switch =~ /^--(no|skip)-([-\w]+)$/
+ hash[$2] = false
else
hash[human_name] = true
end
when :string
hash[human_name] = shift
@@ -260,17 +258,9 @@
names = @non_assigned_required.map do |o|
o.argument? ? o.human_name : o.switch_name
end.join("', '")
raise RequiredArgumentMissingError, "no value provided for required arguments '#{names}'"
- end
- end
-
- # Assign default values to the argument hash.
- #
- def assign_arguments_default_values!
- @non_assigned_arguments.each do |option|
- @arguments << option.default
end
end
# Remove shortcuts that happen to coincide with any of the main switches
#