Module: Ripl::Runner::API
- Included in:
- Ripl::Runner
- Defined in:
- lib/ripl/runner.rb
Instance Method Summary collapse
- #format_error(err) ⇒ Object
- #help ⇒ Object
- #parse_option(option, argv) ⇒ Object
- #parse_options(argv) ⇒ Object
Instance Method Details
#format_error(err) ⇒ Object
88 89 90 91 |
# 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.}#{$/} #{stack.join("#{$/} ")}" end |
#help ⇒ Object
74 75 76 77 78 79 80 81 82 |
# 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) ⇒ Object
84 85 86 |
# File 'lib/ripl/runner.rb', line 84 def parse_option(option, argv) warn "#{app}: #{MESSAGES['parse_option']} `#{option.sub(/^-+/, '')}'" end |
#parse_options(argv) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ripl/runner.rb', line 59 def (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 |