class Turbot::Command::Help

List commands and display help

Constants

PRIMARY_NAMESPACES

Public Instance Methods

index() click to toggle source
help [COMMAND]

List available commands or display help for a specific command.

Examples:

$ turbot help
Usage: turbot COMMAND [--bot APP] [command-specific-options]

Primary help topics, type "turbot help TOPIC" for more details:

  auth  #  Login or logout from Turbot
  bots  #  Manage bots (generate skeleton, validate data, submit code)

Additional topics:

  help     #  List commands and display help
  version  #  Display version

$ turbot help auth:whoam
Usage: turbot auth:whoami

Display your Turbot email address.

Example:

 $ turbot auth:whoami
 email@example.com
# File lib/turbot/command/help.rb, line 35
def index
  command = args.shift
  if command
    help_for_command(command)
  else
    help_for_root
  end
end

Private Instance Methods

additional_namespaces() click to toggle source
# File lib/turbot/command/help.rb, line 65
def additional_namespaces
  namespaces.reject { |name,_| PRIMARY_NAMESPACES.include?(name) }.values
end
commands() click to toggle source

Command

# File lib/turbot/command/help.rb, line 88
def commands
  Turbot::Command.commands
end
commands_for_namespace(name) click to toggle source
# File lib/turbot/command/help.rb, line 92
def commands_for_namespace(name)
  commands.values.select do |command|
    command[:namespace] == name && command[:command] != name
  end
end
help_for(items, name_key, description_key) click to toggle source
# File lib/turbot/command/help.rb, line 48
def help_for(items, name_key, description_key)
  size = items.map { |namespace| namespace[name_key].size }.max
  items.sort_by { |namespace| namespace[name_key] }.each do |namespace|
    puts "  %-#{size}s  # %s" % [namespace[name_key], namespace[description_key]]
  end
end
help_for_command(name) click to toggle source
# File lib/turbot/command/help.rb, line 102
def help_for_command(name)
  command_alias = Turbot::Command.command_aliases[name]
  if command_alias
    puts "Alias: #{name} redirects to #{command_alias}"
    name = command_alias
  end

  command = commands[name]
  if command
    puts "Usage: turbot #{command[:banner]}"
    puts command[:help].split("\n").drop(1).join("\n")
    puts
  end

  namespace_commands = commands_for_namespace(name)
  if !namespace_commands.empty?
    puts 'Additional commands, type "turbot help COMMAND" for more details:'
    puts
    help_for_namespace(namespace_commands)
    puts
  elsif command.nil?
    error "#{name} is not a turbot command. See `turbot help`."
  end
end
help_for_namespace(namespace_commands) click to toggle source
# File lib/turbot/command/help.rb, line 98
def help_for_namespace(namespace_commands)
  help_for(namespace_commands, :banner, :summary)
end
help_for_root() click to toggle source
# File lib/turbot/command/help.rb, line 73
def help_for_root
  puts 'Usage: turbot COMMAND [--bot APP] [command-specific-options]'
  puts
  puts 'Primary help topics, type "turbot help TOPIC" for more details:'
  puts
  summary_for_namespaces(primary_namespaces)
  puts
  puts 'Additional topics:'
  puts
  summary_for_namespaces(additional_namespaces)
  puts
end
namespaces() click to toggle source

Root

# File lib/turbot/command/help.rb, line 57
def namespaces
  Turbot::Command.namespaces
end
primary_namespaces() click to toggle source
# File lib/turbot/command/help.rb, line 61
def primary_namespaces
  namespaces.select { |name,_| PRIMARY_NAMESPACES.include?(name) }.values
end
summary_for_namespaces(namespaces) click to toggle source
# File lib/turbot/command/help.rb, line 69
def summary_for_namespaces(namespaces)
  help_for(namespaces, :name, :description)
end