@@ -2,10 +2,11 @@ module Geode::Commands
22 protected def self.format_command (command : Cling ::Command ) : String
33 String .build do |str |
44 if header = command.header
5- str << header << " \n\n "
5+ str << header << '\n'
66 else
77 str << " Command" .colorize.magenta << " • " << command.name << '\n'
88 end
9+ str << '\n'
910
1011 if description = command.description
1112 str << description
@@ -14,17 +15,16 @@ module Geode::Commands
1415
1516 unless command.usage.empty?
1617 str << " Usage" .colorize.magenta << '\n'
17- command.usage.each do |use |
18- str << " » " << use << '\n'
19- end
18+ command.usage.each { |use | str << " » " << use << '\n' }
2019 str << '\n'
2120 end
2221
2322 unless command.children.empty?
2423 str << " Commands" .colorize.magenta << '\n'
2524 max_size = command.children.keys.map(& .size).max + 4
25+
2626 command.children.each do |name , cmd |
27- str << " » #{ name } "
27+ str << " » " << name
2828 if summary = cmd.summary
2929 str << " " * (max_size - name.size)
3030 str << summary
@@ -36,16 +36,21 @@ module Geode::Commands
3636
3737 unless command.arguments.empty?
3838 str << " Arguments" .colorize.magenta << '\n'
39+ max_size = 4 + command.arguments.keys.max_of & .size
40+
3941 command.arguments.each do |name , argument |
40- str << " » #{ name } \t #{ argument.description } "
42+ str << " » " << name
43+ str << " " * (max_size - name.size)
44+ str << argument.description
4145 str << " (required)" if argument.required?
4246 str << '\n'
4347 end
4448 str << '\n'
4549 end
4650
4751 str << " Options" .colorize.magenta << '\n'
48- max_size = command.options.map { |n , o | n.size + (o.short ? 2 : 0 ) + 2 }.max + 2
52+ max_size = 2 + command.options.max_of { |n , o | 2 + n.size + (o.short ? 2 : 0 ) }
53+
4954 command.options.each do |name , option |
5055 name_size = 2 + option.long.size + (option.short ? 2 : -2 )
5156
0 commit comments