class Birdwatcher::Commands::Help

Public Class Methods

detailed_usage() click to toggle source
# File lib/birdwatcher/commands/help.rb, line 10
      def self.detailed_usage
<<-USAGE
The #{'help'.bold} command shows a general overview of available commands as well as help
and detailed usage for specific commands.

#{'USAGE:'.bold}

#{'See available commands and short descriptions:'.bold}
  help

#{'See help and detailed usage for specific command:'.bold}
  help COMMAND
USAGE
      end

Public Instance Methods

run() click to toggle source
# File lib/birdwatcher/commands/help.rb, line 25
def run
  if arguments?
    show_command_help
  else
    show_general_help
  end
end

Private Instance Methods

show_command_help() click to toggle source
# File lib/birdwatcher/commands/help.rb, line 35
def show_command_help
  command_name = arguments.first.downcase
  commands.each do |command|
    next unless command.has_name?(command_name)
    if command.detailed_usage
      newline
      output command.detailed_usage
    else
      info("There is no detailed usage for this command")
    end
    return
  end
  error "Unknown command: #{command_name}"
end
show_general_help() click to toggle source
# File lib/birdwatcher/commands/help.rb, line 50
def show_general_help
  longest_command_usage = commands.map { |c| c.meta[:usage] }.max_by(&:length)
  info "Available commands:\n"
  commands.sort_by { |c| c.meta[:usage] }.each do |command|
    output_formatted("    %-#{longest_command_usage.bold.length}s\t\t%s\n", command.meta[:usage].bold, command.meta[:description])
  end
  newline
end