Class: Ppl::Command::Help
- Inherits:
-
Application::Command
- Object
- Application::Command
- Ppl::Command::Help
- Defined in:
- lib/ppl/command/help.rb
Instance Attribute Summary collapse
-
#command_suite ⇒ Object
Returns the value of attribute command_suite.
Attributes inherited from Application::Command
Instance Method Summary collapse
- #execute(input, output) ⇒ Object
-
#initialize ⇒ Help
constructor
A new instance of Help.
Methods inherited from Application::Command
Constructor Details
#initialize ⇒ Help
Returns a new instance of Help.
6 7 8 9 |
# File 'lib/ppl/command/help.rb', line 6 def initialize @name = "help" @description = "Show a list of commands" end |
Instance Attribute Details
#command_suite ⇒ Object
Returns the value of attribute command_suite.
4 5 6 |
# File 'lib/ppl/command/help.rb', line 4 def command_suite @command_suite end |
Instance Method Details
#execute(input, output) ⇒ 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 |
# File 'lib/ppl/command/help.rb', line 11 def execute(input, output) @command_suite.sort_by_name max_name_length = 0 @command_suite.each do |command| name_length = command.name.length if name_length > max_name_length max_name_length = name_length end end output.line("usage: ppl <command>") output.line(nil) @command_suite.each do |command| name = command.name description = command.description if @name == name next end line = sprintf(" %-#{max_name_length}s %s", name, description) output.line(line) end output.line(nil) return true end |