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

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

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

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

Additional topics:

  account      #  manage remind101 account options
  accounts     #  manage multiple remind101 accounts
  ...

$ remind101 help apps:create
Usage: remind101 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 "remind101"
 -s, --stack STACK          # the stack on which to create the app
# File lib/remind101/command/help.rb, line 40
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/remind101/command/help.rb, line 83
def additional_namespaces
  (namespaces.values - primary_namespaces)
end
commands() click to toggle source
# File lib/remind101/command/help.rb, line 63
def commands
  Remind101::Command.commands
end
commands_for_namespace(name) click to toggle source
# File lib/remind101/command/help.rb, line 53
def commands_for_namespace(name)
  Remind101::Command.commands.values.select do |command|
    command[:namespace] == name && command[:command] != name
  end
end
help_for_command(name) click to toggle source
# File lib/remind101/command/help.rb, line 123
def help_for_command(name)
  if command_alias = Remind101::Command.command_aliases[name]
    display("Alias: #{name} redirects to #{command_alias}")
    name = command_alias
  end
  if command = commands[name]
    puts "Usage: remind101 #{command[:banner]}"

    if command[:help].strip.length > 0
      help = command[:help].split("\n").reject do |line|
        line =~ /HIDDEN/
      end
      puts help[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 \"remind101 help COMMAND\" for more details:"
    puts
    help_for_namespace(name)
    puts
  elsif command.nil?
    error "#{name} is not a remind101 command. See `remind101 help`."
  end
end
help_for_namespace(name) click to toggle source
# File lib/remind101/command/help.rb, line 110
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 skip_command?(command)
      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/remind101/command/help.rb, line 97
def help_for_root
  puts "Usage: remind101 COMMAND [command-specific-options]"
  puts
  puts "Primary help topics, type \"remind101 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
# File lib/remind101/command/help.rb, line 59
def namespaces
  Remind101::Command.namespaces
end
primary_namespaces() click to toggle source
# File lib/remind101/command/help.rb, line 79
def primary_namespaces
  PRIMARY_NAMESPACES.map { |name| namespaces[name] }.compact
end
skip_command?(command) click to toggle source
# File lib/remind101/command/help.rb, line 73
def skip_command?(command)
  return true if command[:help] =~ /DEPRECATED:/
  return true if command[:help] =~ /^ HIDDEN:/
  false
end
skip_namespace?(ns) click to toggle source
# File lib/remind101/command/help.rb, line 67
def skip_namespace?(ns)
  return true if ns[:description] =~ /DEPRECATED:/
  return true if ns[:description] =~ /HIDDEN:/
  false
end
summary_for_namespaces(namespaces) click to toggle source
# File lib/remind101/command/help.rb, line 87
def summary_for_namespaces(namespaces)
  size = longest(namespaces.map { |n| n[:name] })
  namespaces.sort_by {|namespace| namespace[:name]}.each do |namespace|
    next if skip_namespace?(namespace)
    name = namespace[:name]
    namespace[:description] ||= legacy_help_for_namespace(name)
    puts "  %-#{size}s  # %s" % [ name, namespace[:description] ]
  end
end