mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-28 17:47:03 +03:00
Word wrap options description in CLI help
This commit is contained in:
parent
63e39f51c2
commit
aa82a533dc
@ -635,14 +635,20 @@ module CommandParser
|
||||
end
|
||||
|
||||
def print_option(o)
|
||||
opt_format = "#{' '*5}%-25s %s"
|
||||
opt_format = "#{' '*5}%-25s"
|
||||
|
||||
str = ""
|
||||
str << o[:short].split(' ').first << ', ' if o[:short]
|
||||
str << o[:large]
|
||||
|
||||
printf opt_format, str, o[:description]
|
||||
puts
|
||||
params=sprintf(opt_format, str)
|
||||
|
||||
first_line=80-params.length
|
||||
|
||||
description=word_wrap(80-32, o[:description], first_line).
|
||||
join(("\n"+" "*31))
|
||||
|
||||
puts "#{params} #{description}"
|
||||
end
|
||||
|
||||
def print_commands
|
||||
@ -707,6 +713,30 @@ module CommandParser
|
||||
}
|
||||
end
|
||||
|
||||
def word_wrap(size, text, first_size=nil)
|
||||
output=[]
|
||||
line=""
|
||||
if first_size
|
||||
line_size=first_size
|
||||
else
|
||||
line_size=size
|
||||
end
|
||||
|
||||
text.scan(/[^\s]+/) do |word|
|
||||
if line.length+word.length+1<=line_size
|
||||
line+=" #{word}"
|
||||
else
|
||||
output<<line
|
||||
line=word
|
||||
line_size=size
|
||||
end
|
||||
end
|
||||
|
||||
output<<line
|
||||
output[0].strip!
|
||||
output
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Default Formatters for arguments
|
||||
########################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user