ljust the option names so we don't have funky alignment for multi-char option names

git-svn-id: file:///home/svn/framework3/trunk@12335 4d416f70-5f16-0410-b530-b9f4589650da
unstable
James Lee 2011-04-16 15:57:52 +00:00
parent 9c1b4ddca5
commit 827bec98d6
1 changed files with 8 additions and 2 deletions

View File

@ -26,6 +26,11 @@ class Arguments
#
def initialize(fmt)
self.fmt = fmt
# I think reduce is a better name for this method, but it doesn't exist
# before 1.8.7, so use the stupid inject instead.
self.longest = fmt.keys.inject(0) { |max, str|
max = ((max > str.length) ? max : str.length)
}
end
#
@ -77,7 +82,7 @@ class Arguments
fmt.sort.each { |entry|
fmtspec, val = entry
txt << " #{fmtspec}" + ((val[0] == true) ? " <opt> " : " ")
txt << " #{fmtspec.ljust(longest)}" + ((val[0] == true) ? " <opt> " : " ")
txt << val[1] + "\n"
}
@ -90,6 +95,7 @@ class Arguments
end
attr_accessor :fmt # :nodoc:
attr_accessor :longest # :nodoc:
end