module Ripl::Runner::API

Public Instance Methods

format_error(err) click to toggle source
# File lib/ripl/runner.rb, line 88
def format_error(err)
  stack = err.backtrace.take_while {|line| line !~ %r{/ripl/\S+\.rb} }
  "#{err.class}: #{err.message}#{$/}    #{stack.join("#{$/}    ")}"
end
help() click to toggle source
# File lib/ripl/runner.rb, line 74
def help
  return("#{app} #{$1} [ARGS] [OPTIONS]") if $0[/#{app}-(\w+)/]
  name_max = OPTIONS.values.map {|e| e[0].length }.max
  desc_max = OPTIONS.values.map {|e| e[1].length }.max
  m = MESSAGES
  ["%s: #{app} [%s] [%s] [%s]" % ( [m['usage'], m['command'], m['args'],
    m['options'].upcase] ), "#{$/}#{m['options']}:", OPTIONS_ARR.
    map {|e| n,d = OPTIONS[e]; "  %-*s  %-*s" % [name_max, n, desc_max, d] }]
end
parse_option(option, argv) click to toggle source
# File lib/ripl/runner.rb, line 84
def parse_option(option, argv)
  warn "#{app}: #{MESSAGES['parse_option']} `#{option.sub(/^-+/, '')}'"
end
parse_options(argv) click to toggle source
# File lib/ripl/runner.rb, line 59
def parse_options(argv)
  while argv[0] =~ /^-/
    case argv.shift
    when /-I=?(.*)/
      $LOAD_PATH.unshift(*($1.empty? ? argv.shift.to_s : $1).split(":"))
    when /-r=?(.*)/        then require($1.empty? ? argv.shift.to_s : $1)
    when '-d'              then $DEBUG = true
    when '-v', '--version' then puts(Object.const_get(app.capitalize)::VERSION); exit
    when '-f'              then Ripl.config[:irbrc] = false
    when '-h', '--help'    then puts(help); exit
    when /^(--?[^-]+)/     then parse_option($1, argv)
    end
  end
end