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
87 88 89 90 |
# File 'lib/ripl/runner.rb', line 87 def format_error(err) stack = err.backtrace.take_while {|line| line !~ %r{/ripl/\S+\.rb} } "#{err.class}: #{err.}\n #{stack.join("\n ")}" end |
#help ⇒ Object
73 74 75 76 77 78 79 80 81 |
# 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 m = MESSAGES ["%s: #{app} [%s] [%s] [%s]" % ( [m['usage'], m['command'], m['args'], m['options'].upcase] ), "\n#{m['options']}:", OPTIONS_ARR. map {|e| n,d = OPTIONS[e]; " %-*s %-*s" % [name_max, n, desc_max, d] }] end |
#parse_option(option, argv) ⇒ Object
83 84 85 |
# File 'lib/ripl/runner.rb', line 83 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 (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 |