Class: Hobo::HelpFormatter
- Inherits:
-
Object
- Object
- Hobo::HelpFormatter
- Defined in:
- lib/hobo/help_formatter.rb
Constant Summary collapse
- ALIGN_PAD =
4
Instance Attribute Summary collapse
-
#command_map ⇒ Object
Returns the value of attribute command_map.
Instance Method Summary collapse
- #help(opts = {}) ⇒ Object
-
#initialize(global) ⇒ HelpFormatter
constructor
A new instance of HelpFormatter.
Constructor Details
#initialize(global) ⇒ HelpFormatter
Returns a new instance of HelpFormatter.
6 7 8 9 |
# File 'lib/hobo/help_formatter.rb', line 6 def initialize global @global = global @command_map = {} end |
Instance Attribute Details
#command_map ⇒ Object
Returns the value of attribute command_map.
3 4 5 |
# File 'lib/hobo/help_formatter.rb', line 3 def command_map @command_map end |
Instance Method Details
#help(opts = {}) ⇒ Object
11 12 13 14 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 |
# File 'lib/hobo/help_formatter.rb', line 11 def help opts = {} target = opts[:target] || nil output = [""] command = @command_map[target] if !command command_opts = [] commands = commands_for(@global, opts) command = @global else command_opts = (command) commands = commands_for(command, opts) end global_opts = (@global) align_to = longest([global_opts, command_opts, commands]) + ALIGN_PAD if command != @global description = [ command.long_description, command.description ].compact.first output.push Hobo.ui.color("#{description}\n", :description) if description end output.push section("Usage", [usage(command, target)]) output.push section("Global options", global_opts, align_to) output.push section("Command options", command_opts, align_to) output.push section("Commands", commands, align_to) return output.compact.join("\n") end |