Class: OptionParser::Switch
- Defined in:
- lib/tap/patches/optparse/summarize.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "") ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tap/patches/optparse/summarize.rb', line 15 def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "") sopts, lopts = [], [] @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long return if sopts.empty? and lopts.empty? # completely hidden left = [sopts.join(', ')] right = desc.dup while str = lopts.shift l = left[-1].length + str.length l += arg.length if left.size == 1 && arg #l < max or left << '' left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << str end #left[0] << arg if arg left[-1] << arg if arg mlen = left.collect {|s| s.length}.max.to_i while mlen > width and l = left.shift mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen yield(indent + l) end # uncomment to justify long comments # comment_indent = width + indent.length + 2 # split_right = [] # right.each do |obj| # start_index = 0 # str = obj.to_str # while start_index < str.length # split_right << str[start_index, comment_indent].strip # start_index += comment_indent # end # end # right = split_right while begin l = left.shift; r = right.shift; l or r end l = l.to_s.ljust(width) + ' ' + r if r and !r.empty? #yield(indent + l) yield(indent + l) unless l == nil end self end |