class CC::CLI::Help

Constants

ARGUMENT_LIST
HELP
SHORT_HELP

Public Instance Methods

run() click to toggle source
# File lib/cc/cli/help.rb, line 13
def run
  if @args.any?
    @args.each do |command|
      show_help(command)
    end
  else
    show_help_summary
  end
end

Private Instance Methods

show_help(command_name) click to toggle source
# File lib/cc/cli/help.rb, line 25
def show_help(command_name)
  if (command = Command[command_name])
    say "Usage: codeclimate #{command.synopsis}\n"
    say "\n"
    say "#{command.help}\n"
    say "\n\n"
  else
    say "Unknown command: #{command_name}"
  end
end
show_help_summary() click to toggle source
# File lib/cc/cli/help.rb, line 36
def show_help_summary
  short_helps =
    Command.all.sort_by(&:command_name).map do |command|
      [command.synopsis, command.short_help]
    end.compact.to_h

  longest_command_length = short_helps.keys.map(&:length).max

  say "Usage: codeclimate COMMAND ...\n\nAvailable commands:\n"
  short_helps.each do |command, help|
    say format("    %-#{longest_command_length}s    %s\n", command, help)
  end
end