Permalink
Browse files

Improve `-I` option support

Namely, add support for multiple arguments for the `-I` option. For
example:

  % pry -Ilib:../code/src

Where `:` is the delimiter for paths. In the example above `./lib` and
`../code/src` directories will be added to $LOAD_PATH array.

Also, there was a bug in Slop with respect to parsing of "fuzzy options
with arguments"[1]. It is fixed now, so the next version of Slop will
indirectly resolve our issue #674 (-r/--require doesn't behave like
irb's)[2].

And finally, wrap some very long lines in the "cli.rb" (this is just a
cosmetic change).

[1]: leejarvis/slop#74
[2]: #674

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
  • Loading branch information...
1 parent b4e80be commit 2e33c98d97b88fa296b6b2159c09a756a92b188a @kyrylo kyrylo committed Aug 16, 2012
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/pry/cli.rb
View
@@ -57,12 +57,18 @@ def reset
end
def parse_options(args=ARGV.dup)
- raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." if !options
+ unless options
+ raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options."
+ end
self.input_args = args
opts = Slop.parse!(args, :help => true, :multiple_switches => false, &options)
- option_processors.each { |processor| processor.call(opts) } if option_processors # option processors are optional
+
+ # Option processors are optional.
+ if option_processors
+ option_processors.each { |processor| processor.call(opts) }
+ end
self
end
@@ -139,8 +145,12 @@ def parse_options(args=ARGV.dup)
Pry.config.requires << file
end
- on :I, "Add a path to the $LOAD_PATH", :argument => true do |path|
- $LOAD_PATH << path
+ on :I, "Add a path to the $LOAD_PATH", :argument => true, :as => Array, :delimiter => ":" do |load_path|
+ load_path.map! do |path|
+ /\A\.\// =~ path ? path : File.expand_path(path)
+ end
+
+ $LOAD_PATH.unshift(*load_path)
end
on :v, :version, "Display the Pry version" do

0 comments on commit 2e33c98

Please sign in to comment.