diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index be2911a7..710384f7 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -50,12 +50,23 @@ class Pry end # Defines a new Pry command. - # @param [String] name The name of the command + # @param [String, Regexp] name The name of the command. Can be + # Regexp as well as String. # @param [String] description A description of the command. # @param [Hash] options The optional configuration parameters. # @option options [Boolean] :keep_retval Whether or not to use return value # of the block for return of `command` or just to return `nil` # (the default). + # @option options [Array] :requires_gem Whether the command has + # any gem dependencies, if it does and dependencies not met then + # command is disabled and a stub proc giving instructions to + # install command is provided. + # @option options [Boolean] :interpolate Whether string #{} based + # interpolation is applied to the command arguments before + # executing the command. Defaults to true. + # @option options [String] :listing The listing name of the + # command. That is the name by which the command is looked up by + # help and by show-command. Necessary for regex based commands. # @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 @@ -73,6 +84,19 @@ class Pry # # Good afternoon John! # # pry(main)> help greet # # Greet somebody + # @example Regexp command + # MyCommands = Pry::CommandSet.new do + # command /number-(\d+)/, "number-N regex command", :listing => "number" do |num, name| + # puts "hello #{name}, nice number: #{num}" + # end + # end + # + # # From pry: + # # pry(main)> _pry_.commands = MyCommands + # # pry(main)> number-10 john + # # hello john, nice number: 10 + # # pry(main)> help number + # # number-N regex command def command(name, description="No description.", options={}, &block) options = { diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index e2a42061..9298c6d6 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -215,8 +215,8 @@ class Pry def process_rdoc(comment, code_type) comment = comment.dup comment.gsub(/(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }. - gsub(/(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }. - gsub(/(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[34m#{$1}\e[0m" : $1 }. + gsub(/(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[1m#{$1}\e[0m": $1 }. + gsub(/(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[1m#{$1}\e[0m" : $1 }. gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }. gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }. gsub(/`(?:\s*\n)?(.*?)\s*`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }