class Nehm::HelpCommand
Constants
- SPACES_BTWN_NAME_AND_DESC
Public Instance Methods
arguments()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 21 def arguments { 'COMMAND' => 'name of command (can be abbreviated) to show help' } end
execute()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 6 def execute command_name = options[:args].pop if command_name.nil? UI.say HELP UI.term end @cmd = CommandManager.find_command(command_name) show_usage show_summary show_arguments unless @cmd.arguments.empty? show_options unless @cmd.options.empty? end
program_name()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 25 def program_name 'nehm help' end
summary()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 29 def summary 'Show help for specified command' end
usage()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 33 def usage "#{program_name} COMMAND" end
Private Instance Methods
find_longest_name(names)
click to toggle source
# File lib/nehm/commands/help_command.rb, line 39 def find_longest_name(names) names.inject do |longest, word| word.length > longest.length ? word : longest end end
show_arguments()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 55 def show_arguments UI.newline UI.say "#{'Arguments:'.yellow}" show_info(@cmd.arguments) end
show_info(hash)
click to toggle source
# File lib/nehm/commands/help_command.rb, line 67 def show_info(hash) @longest ||= Proc.new do names = [] names += @cmd.arguments.keys unless @cmd.arguments.empty? names += @cmd.options_descs.keys unless @cmd.options_descs.empty? find_longest_name(names).length end.call hash.each do |name, desc| space_count = @longest + SPACES_BTWN_NAME_AND_DESC UI.say " #{name.green.ljust(space_count)}#{desc}" end end
show_options()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 61 def show_options UI.newline UI.say "#{'Options:'.yellow}" show_info(@cmd.options_descs) end
show_summary()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 49 def show_summary UI.newline UI.say "#{'Summary:'.yellow}" UI.say " #{@cmd.summary}" end
show_usage()
click to toggle source
# File lib/nehm/commands/help_command.rb, line 45 def show_usage UI.say "#{'Usage:'.yellow} #{@cmd.usage}" end