Class: Smith::Commands::Commands
- Inherits:
-
Smith::CommandBase
- Object
- Smith::CommandBase
- Smith::Commands::Commands
- Defined in:
- lib/smith/commands/smithctl/commands.rb
Instance Attribute Summary
Attributes inherited from Smith::CommandBase
Instance Method Summary collapse
Methods inherited from Smith::CommandBase
#banner, #format_help, #initialize, #parse_options
Methods included from Logger
Constructor Details
This class inherits a constructor from Smith::CommandBase
Instance Method Details
#execute ⇒ Object
5 6 7 8 |
# File 'lib/smith/commands/smithctl/commands.rb', line 5 def execute commands = (target.empty?) ? Command.commands : target responder.succeed(format(commands)) end |
#format(commands) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smith/commands/smithctl/commands.rb', line 10 def format(commands) if [:long] c = instantiate_commands(commands) if [:type] c.map { |k,v| sprintf("%1$*4$s - %2$s [%3$s]", k, remove_new_lines(v), Command.command_type(k), -(max_length(c) + 1)) }.join("\n") else c.map { |k,v| sprintf("%1$*3$s - %2$s", k, remove_new_lines(v), -(max_length(c) + 1)) }.join("\n") end else if [:type] instantiate_commands(commands).map { |k,v| sprintf("%s - %s", k, Command.command_type(k)) } else commands.sort.join("\n") end end end |