1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Regex working

This commit is contained in:
John Mair 2011-01-18 16:40:28 +13:00
parent f45e8bfbd0
commit b95b5e64b5
3 changed files with 25 additions and 24 deletions

View file

@ -16,8 +16,24 @@ class Pry
# Defines a new Pry command.
# @param [String, Array] name The name of the command (or array of
# command name aliases).
# @yield [command] The action to perform. The parameters in the block
# determines the parameters the command will receive.
# @param [String] description A description of the command.
# @yield The action to perform. The parameters in the block
# determines the parameters the command will receive. All
# parameters passed into the block will be strings. Successive
# command parameters are separated by whitespace at the Pry prompt.
# @example
# class MyCommands < Pry::CommandBase
# command "greet", "Greet somebody" do |name|
# puts "Good afternoon #{name.capitalize}!"
# end
# end
#
# # From pry:
# # pry(main)> _pry_.commands = MyCommands
# # pry(main)> greet john
# # Good afternoon John!
# # pry(main)> help greet
# # Greet somebody
def command(name, description="No description.", &block)
@commands ||= {}
@command_info ||= {}
@ -26,10 +42,10 @@ class Pry
if name.is_a?(Array)
matcher = []
name.each do |n|
matcher << /^#{n}#{arg_match}?/
matcher << /^#{n}(?!\S)#{arg_match}?/
end
else
matcher = /^#{name}#{arg_match}?/
matcher = /^#{name}(?!\S)#{arg_match}?/
end
commands[matcher] = block
@ -57,6 +73,7 @@ class Pry
end
end
# Ensures that commands can be inherited
def self.inherited(klass)
klass.commands = commands.dup
klass.command_info = command_info.dup

View file

@ -2,26 +2,8 @@ direc = File.dirname(__FILE__)
require "#{direc}/command_base"
class Pry
# Default commands used by Pry.
# @note
# If you plan to replace the default Commands class with a custom
# one then it must be a class that inherits from
# `Pry::CommandBase` or from `Pry::Commands` (if you want to keep
# default commands).
# @example Creating a custom command set
# class MyCommands < Pry::CommandBase
# command "greeting" do
# describe "give a greeting"
# action { puts "hello world!" }
# end
#
# command "goodbye" do
# describe "say goodbye and quit"
# action { puts "goodbye!"; exit }
# end
# end
#
# Pry.commands = MyCommands
class Commands < CommandBase
command "!", "Refresh the REPL" do

View file

@ -199,7 +199,9 @@ class Pry
}
# because procs are defined in different places (e.g 'help' in CommandBase)
# we cannot simply use `commands.opts=...`
# we cannot simply use `commands.opts=...`; instead we have to
# retrieve the object where the block was defined; since that is
# the `opts` method that the block will have access to.
action_self = action.binding.eval('self')
action_self.opts = options