Sha256: 3df337ec379074cdffef527132e0aaf1fb9845278d858bcb1e4f1af6848ada92
Contents?: true
Size: 1.95 KB
Versions: 4
Compression:
Stored size: 1.95 KB
Contents
module Ripl::Runner def self.included(mod) mod.extend(self) end module API def run(argv=ARGV) load_rc(Ripl.config[:riplrc]) @riplrc = true parse_options(argv) argv[0] ? run_command(argv) : start end 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=?(.*)/ require $1.empty? ? argv.shift.to_s : $1 when '-d' $DEBUG = true when '-v', '--version' puts Ripl::VERSION; exit when '-f' ENV['RIPL_IRBRC'] = 'false' when '-h', '--help' puts IO.readlines(__FILE__).grep(/^#/).map {|e| e.sub(/^#\s/,'') }; exit when /^--?([^-]+)/ warn "ripl: invalid option `#{$1}'" end end end def run_command(argv) exec "ripl-#{argv.shift}", *argv rescue Errno::ENOENT raise unless $!.message =~ /No such file or directory.*ripl-(\w+)/ abort "`#{$1}' is not a ripl command." end def start(options={}) load_rc(Ripl.config[:riplrc]) unless @riplrc Ripl.config[:irbrc] = ENV['RIPL_IRBRC'] != 'false' if ENV['RIPL_IRBRC'] Ripl.shell(options).loop end def load_rc(file) load file if File.exists?(File.expand_path(file)) rescue StandardError, SyntaxError warn "Error while loading #{file}:\n"+ format_error($!) end def format_error(err) "#{err.class}: #{err.message}\n #{err.backtrace.join("\n ")}" end end extend API end __END__ # Usage: ripl [OPTIONS] [COMMAND] [ARGS] # # Options: # -f Supress loading ~/.irbrc # -d, --debug Set $DEBUG to true (same as `ruby -d') # -I PATH Add to front of $LOAD_PATH. Delimit multiple paths with ':' # -r, --require FILE Require file (same as `ruby -r') # -v, --version Print ripl version # -h, --help Print help
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ripl-0.2.4 | lib/ripl/runner.rb |
ripl-0.2.3 | lib/ripl/runner.rb |
ripl-0.2.2 | lib/ripl/runner.rb |
ripl-0.2.1 | lib/ripl/runner.rb |