lib/slop/option.rb in slop-1.5.3 vs lib/slop/option.rb in slop-1.5.4

- old
+ new

@@ -22,15 +22,21 @@ attr_reader :match # @return [Object] true/false, or an optional help string to append attr_reader :help + # @return [Boolean] true if this options argument value has been forced + attr_reader :forced + # @overload argument_value=(value) # Set this options argument value # @param [Object] value The value you'd like applied to this option attr_writer :argument_value + # @return [Integer] The amount of times this option has been invoked + attr_accessor :count + # @param [Slop] slop # @param [String, #to_s] short # @param [String, #to_s] long # @param [String] description # @param [Boolean] argument @@ -54,30 +60,23 @@ @expects_argument = argument @expects_argument = true if options[:optional] == false @tail = options[:tail] @match = options[:match] + @delimiter = options[:delimiter] || ',' + @limit = options[:limit] || 0 @help = options[:help] @help = true if @help.nil? @forced = false @argument_value = nil + @count = 0 - @delimiter = options[:delimiter] || ',' - @limit = options[:limit] || 0 - - if @long_flag && @long_flag.size > @slop.longest_flag - if @help.respond_to? :to_str - size = @long_flag.size + @help.size - else - size = @long_flag.size - end - @slop.longest_flag = size - end - @callback = blk if block_given? @callback ||= options[:callback] + + build_longest_flag end # @return [Boolean] true if this option expects an argument def expects_argument? @expects_argument || @options[:argument] @@ -103,13 +102,13 @@ case @options[:as].to_s.downcase when 'array' value.split @delimiter, @limit when 'range' value_to_range value - when 'string'; value.to_s - when 'symbol'; value.to_s.to_sym - when 'integer'; value.to_s.to_i + when 'string', 'str'; value.to_s + when 'symbol', 'sym'; value.to_s.to_sym + when 'integer', 'int'; value.to_s.to_i when 'float'; value.to_s.to_f else value end end @@ -121,15 +120,10 @@ def force_argument_value(value) @argument_value = value @forced = true end - # @return [Boolean] true if this argument value has been forced - def forced? - @forced - end - # This option in a nice pretty string, including a short flag, long # flag, and description (if they exist). # @see Slop#help # @return [String] def to_s @@ -172,9 +166,20 @@ Integer($1) ... Integer($2) when /\A\d+\z/ Integer(value) else value + end + end + + def build_longest_flag + if @long_flag && @long_flag.size > @slop.longest_flag + if @help.respond_to? :to_str + size = @long_flag.size + @help.size + else + size = @long_flag.size + end + @slop.longest_flag = size end end end end