class Rack::App::CLI::Runner

Constants

CommandNotFound

Public Class Methods

new(app) click to toggle source
# File lib/rack/app/cli/runner.rb, line 5
def initialize(app)
  @cli = app.respond_to?(:cli) ? app.cli : Rack::App::CLI.new
end

Public Instance Methods

start(argv) click to toggle source
# File lib/rack/app/cli/runner.rb, line 9
def start(argv)
  command_name = argv.shift
  start_command_for(command_name,argv)
end

Protected Instance Methods

command_for(name) click to toggle source
# File lib/rack/app/cli/runner.rb, line 64
def command_for(name)
  commands[(name || raise(CommandNotFound)).to_s.to_sym] || raise(CommandNotFound)
end
commands() click to toggle source
# File lib/rack/app/cli/runner.rb, line 68
def commands
  @cli.commands
end
configure_command(command, command_name) click to toggle source
# File lib/rack/app/cli/runner.rb, line 58
def configure_command(command, command_name)
  option_parser = OptionParser.new
  Rack::App::CLI::Command::Configurator.configure(command, command_name, option_parser)
  return option_parser
end
run_command(argv, command, command_name) click to toggle source
# File lib/rack/app/cli/runner.rb, line 49
def run_command(argv, command, command_name)
  return if command.nil?

  option_parser = configure_command(command, command_name)
  option_parser.parse!(argv)
  command.start(argv)

end
show_commands() click to toggle source
# File lib/rack/app/cli/runner.rb, line 16
def show_commands
  $stdout.puts(Rack::App::CLI::DefaultCommands::ListCommands.get_message(commands))
end
show_help_message(argv) click to toggle source
# File lib/rack/app/cli/runner.rb, line 20
def show_help_message(argv)
  command_name = argv.shift
  command = command_for(command_name)
  options_parser = configure_command(command,command_name)
  $stdout.puts(options_parser.help)
end
start_command_for(command_name, argv) click to toggle source
# File lib/rack/app/cli/runner.rb, line 27
def start_command_for(command_name, argv)
  case command_name.to_s

    when 'help'
      show_help_message(argv)

    when 'routes'
      command = Rack::App::CLI::DefaultCommands::ShowRoutes.new
      run_command(argv, command, "routes")

    when 'irb'
      Rack::App::CLI::DefaultCommands::IRB.new.start(argv)

    else
      command = command_for(command_name)
      run_command(argv, command, command_name)

  end
rescue CommandNotFound
  show_commands
end