Module: Ripl::Runner::API

Included in:
Ripl::Runner
Defined in:
lib/ripl/runner.rb

Instance Method Summary collapse

Instance Method Details

#format_error(err) ⇒ Object



85
86
87
# File 'lib/ripl/runner.rb', line 85

def format_error(err)
  "#{err.class}: #{err.message}\n    #{err.backtrace.join("\n    ")}"
end

#helpObject



73
74
75
76
77
78
79
# File 'lib/ripl/runner.rb', line 73

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
  ["Usage: #{app} [COMMAND] [ARGS] [OPTIONS]", "\nOptions:", OPTIONS_ARR.
    map {|e| n,d = OPTIONS[e]; "  %-*s  %-*s" % [name_max, n, desc_max, d] }]
end

#parse_option(option, argv) ⇒ Object



81
82
83
# File 'lib/ripl/runner.rb', line 81

def parse_option(option, argv)
  warn "#{app}: #{MESSAGES['parse_option']} `#{option.sub(/^-+/, '')}'"
end

#parse_options(argv) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ripl/runner.rb', line 58

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