lib/rib/runner.rb in rib-1.2.91 vs lib/rib/runner.rb in rib-1.3.0
- old
+ new
@@ -21,10 +21,11 @@
['-r, --require LIBRARY' ,
'Require the library, before executing your script' ],
['rib options:' , '' ],
['-c, --config FILE', 'Load config from FILE' ],
+ ['-p, --prefix PATH', 'Prefix to locate the app. Default to .' ],
['-n, --no-config' , 'Suppress loading ~/.config/rib/config.rb'],
['-h, --help' , 'Print this message' ],
['-v, --version' , 'Print the version' ]] +
[['rib commands:' , '']] + commands
@@ -65,18 +66,18 @@
end
def run argv=ARGV
(@running_commands ||= []) << Rib.config[:name]
unused = parse(argv)
- # if it's running a Rib command, the loop would be inside Rib itself
- # so here we only parse args for the command
- return if @running_commands.pop != 'rib'
- # by coming to this line, it means now we're running Rib main loop,
- # not any other Rib command
- Rib.warn("Unused arguments: #{unused.inspect}") unless unused.empty?
- require 'rib/core' if Rib.config.delete(:mimic_irb)
- loop
+ # we only want to run the loop if we're running the rib command,
+ # otherwise, it must be a rib app, which we only want to parse
+ # the arguments and proceed (this is recursive!)
+ if @running_commands.pop == 'rib'
+ Rib.warn("Unused arguments: #{unused.inspect}") unless unused.empty?
+ require 'rib/core' if Rib.config.delete(:mimic_irb)
+ loop
+ end
end
def loop retry_times=5
Rib.shell.loop
rescue => e
@@ -118,9 +119,12 @@
when /^-r=?(.+)?/, /^--require=?(.+)?/
require($1 || argv.shift)
when /^-c=?(.+)?/, /^--config=?(.+)?/
Rib.config[:config] = $1 || argv.shift
+
+ when /^-p=?(.+)?/, /^--prefix=?(.+)?/
+ Rib.config[:prefix] = $1 || argv.shift
when /^-n/, '--no-config'
Rib.config.delete(:config)
parse_next(argv, arg)