module Rails::Sh

Public Class Methods

execute(line) click to toggle source
# File lib/rails/sh.rb, line 47
def execute(line)
  if command = Command.find(line)
    start = Time.now
    arg = line.split(/\s+/, 2)[1] rescue nil
    command.call(arg)
    puts "\e[34m#{Time.now - start}sec\e[0m"
  else
    puts "\e[41mCommand not found\e[0m"
  end
end
prompt() click to toggle source
# File lib/rails/sh.rb, line 38
def prompt
  "%s> " % "rails-sh(#{::Rails.root.basename})"
end
setup_readline() click to toggle source
# File lib/rails/sh.rb, line 42
def setup_readline
  Readline.basic_word_break_characters = ""
  Readline.completion_proc = Command.completion_proc
end
start() click to toggle source
# File lib/rails/sh.rb, line 12
def start
  ::Rails::Sh::Rails.init
  ::Rails::Sh::Rake.init

  require 'rails/sh/commands'

  begin; load "~/.railsshrc"; rescue LoadError; end

  puts "\e[36mRails.env: #{::Rails.env}\e[0m"
  puts "\e[36mtype `help` to print help\e[0m"

  setup_readline
  while buf = Readline.readline(prompt, true)
    line = buf.strip
    next if line.empty?
    begin
      execute(line)
    rescue SystemExit
      raise
    rescue Exception => e
      puts "\e[41m#{e.message}\n#{e.backtrace.join("\n")}\e[0m"
    end
    setup_readline
  end
end