class Heroku::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:

$ heroku help
Usage: heroku COMMAND [--app APP] [command-specific-options]

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

  addons    #  manage addon resources
  apps      #  manage apps (create, destroy)
  ...

Additional topics:

  account      #  manage heroku account options
  accounts     #  manage multiple heroku accounts
  ...

$ heroku help apps:create
Usage: heroku apps:create [NAME]

 create a new app

     --addons ADDONS        # a comma-delimited list of addons to install
 -b, --buildpack BUILDPACK  # a buildpack url to use for this app
 -r, --remote REMOTE        # the git remote to create, default "heroku"
 -s, --stack STACK          # the stack on which to create the app
# File lib/heroku/command/help.rb, line 43
def index
  if command = args.shift
    help_for_command(command)
  else
    help_for_root
  end
end

Private Instance Methods

additional_namespaces() click to toggle source
# File lib/heroku/command/help.rb, line 94
def additional_namespaces
  (namespaces.values - primary_namespaces)
end
commands() click to toggle source
# File lib/heroku/command/help.rb, line 68
def commands
  Heroku::Command.commands
end
commands_for_namespace(name) click to toggle source
# File lib/heroku/command/help.rb, line 56
def commands_for_namespace(name)
  Heroku::Command.commands.values.select do |command|
    command[:namespace] == name && command[:command] != name
  end
end
help_for_command(name) click to toggle source
# File lib/heroku/command/help.rb, line 133
def help_for_command(name)
  if command_alias = Heroku::Command.command_aliases[name]
    display("Alias: #{name} redirects to #{command_alias}")
    name = command_alias
  end
  if command = commands[name]
    puts "Usage: heroku #{command[:banner]}"

    if command[:help].strip.length > 0
      puts command[:help].split("\n")[1..-1].join("\n")
    else
      puts
      puts " " + legacy_help_for_command(name).to_s
    end
    puts
  end

  namespace_commands = commands_for_namespace(name).reject do |command|
    command[:help] =~ /DEPRECATED/
  end

  if !namespace_commands.empty?
    puts "Additional commands, type \"heroku help COMMAND\" for more details:"
    puts
    help_for_namespace(name)
    puts
  elsif command.nil?
    error "#{name} is not a heroku command. See `heroku help`."
  end
end
help_for_namespace(name) click to toggle source
# File lib/heroku/command/help.rb, line 120
def help_for_namespace(name)
  namespace_commands = commands_for_namespace(name)

  unless namespace_commands.empty?
    size = longest(namespace_commands.map { |c| c[:banner] })
    namespace_commands.sort_by { |c| c[:banner].to_s }.each do |command|
      next if command[:help] =~ /DEPRECATED/
      command[:summary] ||= legacy_help_for_command(command[:command])
      puts "  %-#{size}s  # %s" % [ command[:banner], command[:summary] ]
    end
  end
end
help_for_root() click to toggle source
# File lib/heroku/command/help.rb, line 107
def help_for_root
  puts "Usage: heroku COMMAND [--app APP] [command-specific-options]"
  puts
  puts "Primary help topics, type \"heroku help TOPIC\" for more details:"
  puts
  summary_for_namespaces(primary_namespaces)
  puts
  puts "Additional topics:"
  puts
  summary_for_namespaces(additional_namespaces)
  puts
end
legacy_help_for_command(command) click to toggle source
# File lib/heroku/command/help.rb, line 81
def legacy_help_for_command(command)
  Heroku::Command::Help.groups.each do |group|
    group.each do |cmd, description|
      return description if cmd.split(" ").first == command
    end
  end
  nil
end
legacy_help_for_namespace(namespace) click to toggle source
# File lib/heroku/command/help.rb, line 72
def legacy_help_for_namespace(namespace)
  instance = Heroku::Command::Help.groups.map do |group|
    [ group.title, group.select { |c| c.first =~ /^#{namespace}/ }.length ]
  end.sort_by { |l| l.last }.last
  return nil unless instance
  return nil if instance.last.zero?
  instance.first
end
namespaces() click to toggle source
# File lib/heroku/command/help.rb, line 62
def namespaces
  namespaces = Heroku::Command.namespaces
  namespaces.delete("app")
  namespaces
end
primary_namespaces() click to toggle source
# File lib/heroku/command/help.rb, line 90
def primary_namespaces
  PRIMARY_NAMESPACES.map { |name| namespaces[name] }.compact
end
summary_for_namespaces(namespaces) click to toggle source
# File lib/heroku/command/help.rb, line 98
def summary_for_namespaces(namespaces)
  size = longest(namespaces.map { |n| n[:name] })
  namespaces.sort_by {|namespace| namespace[:name]}.each do |namespace|
    name = namespace[:name]
    namespace[:description] ||= legacy_help_for_namespace(name)
    puts "  %-#{size}s  # %s" % [ name, namespace[:description] ]
  end
end