Class: Smartdict::Commands::HelpCommand
Constant Summary
AbstractCommand::INDENT_SIZE
Instance Method Summary
collapse
arguments, default, #extract_arguments_and_options, help_message, help_syntax_message, help_usage_message, inherited, #initialize, options, prog_name, run, #set_arguments!, #set_arguments_and_options!, set_description, set_name, #set_options!, set_summary, set_syntax, set_usage
Instance Method Details
#execute ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/smartdict/commands/help_command.rb', line 23
def execute
if cmd_name = @arguments[:command]
if cmd_class = CommandManager.find(cmd_name)
puts cmd_class.help_message
else
abort "Uknown command: #{cmd_name}"
end
else
puts help_message
end
end
|
#help_commands_message ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/smartdict/commands/help_command.rb', line 42
def help_commands_message
width = CommandManager.all.keys.map(&:size).max
result = " " * INDENT_SIZE + "Commands:\n"
CommandManager.all.each do |command_name, command_class|
result << " " * 2 * INDENT_SIZE + "#{command_name.ljust(width)}"
result << " #{command_class.summary}\n"
end
result
end
|
#help_message ⇒ Object
35
36
37
38
39
|
# File 'lib/smartdict/commands/help_command.rb', line 35
def help_message
message = "#{description}\n\n"
message << "#{self.class.help_syntax_message}\n"
message << help_commands_message
end
|