View on GitHub
Defines a new Pry command.
@param [String, Regexp] match The start of invocations of this command.
@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 [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-source. Necessary for commands with regex matches.
@option options [Boolean] :use_prefix Whether the command uses
`Pry.config.command_prefix` prefix (if one is defined). Defaults
to true.
@option options [Boolean] :shellwords Whether the command's arguments
should be split using Shellwords instead of just split on spaces.
Defaults to true.
@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
MyCommands = Pry::CommandSet.new do
command "greet", "Greet somebody" do |name|
puts "Good afternoon #{name.capitalize}!"
end
end
# From pry:
# pry(main)> pry_instance.commands = MyCommands
# pry(main)> greet john
# 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_instance.commands = MyCommands
# pry(main)> number-10 john
# hello john, nice number: 10
# pry(main)> help number
# number-N regex command