class Ripl::Runner

Constants

MESSAGES
OPTIONS
OPTIONS_ARR

Attributes

app[RW]
argv[RW]

Public Class Methods

add_options(*options) click to toggle source

Adds commandline options for –help

# File lib/ripl/runner.rb, line 23
def self.add_options(*options)
  options.each {|e|
    OPTIONS[e[0][/-\w+/]] = e
    OPTIONS_ARR << e[0][/-\w+/]
  }
end
load_rc(file) click to toggle source
# File lib/ripl/runner.rb, line 52
def self.load_rc(file)
  load file if File.exists?(File.expand_path(file))
rescue StandardError, SyntaxError, LoadError
  $stderr.puts "#{app}: #{MESSAGES['load_rc'] % file}:", format_error($!)
end
run(argv=ARGV) click to toggle source
# File lib/ripl/runner.rb, line 30
def self.run(argv=ARGV)
  argv[0].to_s[/^[^-]/] ? run_command(argv) : start(:argv => argv)
end
run_command(argv) click to toggle source
# File lib/ripl/runner.rb, line 34
def self.run_command(argv)
  exec "#{app}-#{cmd = argv.shift}", *argv
rescue SystemCallError
  raise unless $!.message =~ /No such file or directory.*#{app}-(\w+)/ ||
    $!.message.include?("Invalid argument - execvp(2) failed")
  abort MESSAGES['run_command'] % [cmd, app]
end
start(options={}) click to toggle source
# File lib/ripl/runner.rb, line 42
def self.start(options={})
  @argv = options.delete(:argv) || ARGV
  argv = @argv.dup
  load_rc(Ripl.config[:riplrc]) unless argv.delete('-F') || options[:riplrc] == false
  argv.each {|e| e[/^-/] ? break : argv.shift } if $0[/#{app}-\w+$/]
  parse_options(argv) if $0[/#{app}$|#{app}-\w+$/]
  warn "#{app}: #{MESSAGES['start']}: #{argv.inspect}" if !argv.empty?
  Ripl.shell(options).loop
end