lib/thor/parser/option.rb in thor-1.2.2 vs lib/thor/parser/option.rb in thor-1.3.0

- old
+ new

@@ -9,11 +9,11 @@ options[:required] = false unless options.key?(:required) @repeatable = options.fetch(:repeatable, false) super @lazy_default = options[:lazy_default] @group = options[:group].to_s.capitalize if options[:group] - @aliases = Array(options[:aliases]) + @aliases = normalize_aliases(options[:aliases]) @hide = options[:hide] end # This parse quick options given as method_options. It makes several # assumptions, but you can be more specific using the option method. @@ -67,11 +67,11 @@ :numeric when Hash, Array, String value.class.name.downcase.to_sym end - new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases) + new(name.to_s, required: required, type: type, default: default, aliases: aliases) end def switch_name @switch_name ||= dasherized? ? name : dasherize(name) end @@ -88,11 +88,11 @@ end sample = "[#{sample}]".dup unless required? if boolean? - sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-") + sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.match(/\Ano[\-_]/) end aliases_for_usage.ljust(padding) + sample end @@ -102,10 +102,19 @@ else "#{aliases.join(', ')}, " end end + def show_default? + case default + when TrueClass, FalseClass + true + else + super + end + end + VALID_TYPES.each do |type| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{type}? self.type == #{type.inspect} end @@ -140,12 +149,12 @@ if @check_default_type raise ArgumentError, err elsif @check_default_type == nil Thor.deprecation_warning "#{err}.\n" + - 'This will be rejected in the future unless you explicitly pass the options `check_default_type: false`' + - ' or call `allow_incompatible_default_type!` in your code' + "This will be rejected in the future unless you explicitly pass the options `check_default_type: false`" + + " or call `allow_incompatible_default_type!` in your code" end end end def dasherized? @@ -156,8 +165,14 @@ str.sub(/^-{1,2}/, "") end def dasherize(str) (str.length > 1 ? "--" : "-") + str.tr("_", "-") + end + + private + + def normalize_aliases(aliases) + Array(aliases).map { |short| short.to_s.sub(/^(?!\-)/, "-") } end end end