summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Carey <matthew.b.carey@gmail.com>2012-11-08 19:59:24 -0500
committerMatthew Carey <matthew.b.carey@gmail.com>2012-11-08 19:59:24 -0500
commitd88900756e37de83b83b39b5e7a21c4cd9e6a636 (patch)
tree3173537b7cd71cf8003b17eb5730ca0439cb32b9
parent5ec6b84198f7317fa7deb65f80833808ca3694d7 (diff)
downloadpry-feature/pipe-syntax.tar.gz
Added pipe syntax for commands. Tests to be added soon.feature/pipe-syntax
-rw-r--r--lib/pry/command.rb36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/pry/command.rb b/lib/pry/command.rb
index 27d78a8a..73b17412 100644
--- a/lib/pry/command.rb
+++ b/lib/pry/command.rb
@@ -290,7 +290,6 @@ class Pry
# @return [Array]
def tokenize(val)
val.replace(interpolate_string(val)) if command_options[:interpolate]
-
self.class.command_regex =~ val
# please call Command.matches? before Command#call_safely
@@ -315,10 +314,45 @@ class Pry
[val[0..pos].rstrip, arg_string, captures, args]
end
+ # Compiled and stationary regex for optimization
+ PIPE = %r/((?<=[^'"])(?<=.)?\|(?!.*(?!do\s*(\|.*\|)*|\{(\|.*\|)*|\'|\")))/
+
# Process a line that Command.matches? this command.
# @param [String] line The line to process
# @return [Object, Command::VOID_VALUE]
def process_line(line)
+ if line =~ PIPE
+ command_stack = line.split PIPE
+ command_stack.map!(&:strip)
+ clr = Pry.config.color
+ out = Pry.config.output
+ stdout = $stdout
+ Pry.config.color = false
+ begin
+ obj = ""
+ command_stack[0..-2].each do |cmd|
+ args = obj
+ s = ""
+ o = StringIO.new(s)
+ Pry.config.output = o
+ $stdout = o
+ if Pry.commands[cmd.split[0]].description =~ /Alias for `(.+?)`/ then cmd = $1 + " " + cmd.split[1..-1].join end
+ Pry.run_command(cmd + " " + args)
+ obj = s
+ end
+ Pry.config.color = clr
+ Pry.config.output = out
+ $stdout = stdout
+ cmd = command_stack.last
+ if Pry.commands[cmd.split[0]].description =~ /Alias for `(.+?)`/ then cmd = $1 + " " + cmd.split[1..-1].join end
+ Pry.run_command(cmd + " #{obj}")
+ ensure
+ Pry.config.color = clr
+ Pry.config.output = out
+ $stdout = stdout
+ return void
+ end
+ end
command_match, arg_string, captures, args = tokenize(line)
check_for_command_collision(command_match, arg_string) if Pry.config.collision_warning