class Hotdog::Commands::Help

Public Instance Methods

run(args=[], options={}) click to toggle source
# File lib/hotdog/commands/help.rb, line 8
def run(args=[], options={})
  commands = command_files.map { |file| File.basename(file, ".rb") }.sort.uniq
  if "commands" == args.first
    STDOUT.puts("hotdog commands are:")
    commands.each do |command|
      STDOUT.puts("- #{command}")
    end
  else
    ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
    if commands.include?(args.first)
      exit(system(ruby, $0, args.first, "--help") ? 0 : 1)
    else
      exit(system(ruby, $0, "--help") ? 0 : 1)
    end
  end
end

Private Instance Methods

command_files() click to toggle source
# File lib/hotdog/commands/help.rb, line 30
def command_files()
  load_path.flat_map { |path| Dir.glob(File.join(path, "*.rb")) }.select { |file| File.file?(file) }
end
load_path() click to toggle source
# File lib/hotdog/commands/help.rb, line 26
def load_path()
  $LOAD_PATH.map { |path| File.join(path, "hotdog/commands") }.select { |path| File.directory?(path) }
end