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

- old
+ new

@@ -19,10 +19,13 @@ # @return [Regexp] If provided, an options argument **must** match this # regexp, otherwise Slop will raise an InvalidArgumentError attr_reader :match + # @return [Object] true/false, or an optional help string to append + attr_reader :help + # @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 @@ -38,10 +41,11 @@ # @option options [Proc, #call] :callback # @option options [String, #to_s] :delimiter (',') # @option options [Integer] :limit (0) # @option options [Boolean] :tail (false) # @option options [Regexp] :match + # @option options [Boolean, String] :help def initialize(slop, short, long, description, argument, options={}, &blk) @slop = slop @short_flag = short @long_flag = long @description = description @@ -50,19 +54,26 @@ @expects_argument = argument @expects_argument = true if options[:optional] == false @tail = options[:tail] @match = options[:match] + @help = options[:help] + @help = true if @help.nil? @forced = false @argument_value = nil @delimiter = options[:delimiter] || ',' @limit = options[:limit] || 0 if @long_flag && @long_flag.size > @slop.longest_flag - @slop.longest_flag = @long_flag.size + 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] end @@ -125,10 +136,16 @@ out = " " out += @short_flag ? "-#{@short_flag}, " : ' ' * 4 if @long_flag out += "--#{@long_flag}" - diff = @slop.longest_flag - @long_flag.size + if @help.respond_to? :to_str + out += " #{@help}" + size = @long_flag.size + @help.size + 1 + else + size = @long_flag.size + end + diff = @slop.longest_flag - size spaces = " " * (diff + 6) out += spaces else spaces = " " * (@slop.longest_flag + 8) out += spaces