mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
ebccd57013
John "banister" Mair describes the following key features of commands as classes: 1. It enables people to extend them by either subclassing or monkeypatching. 2. It enables them to provide their own API, so that for example, the Pry::Command::Edit class could have class methods for people to configure it. Please, note that I didn't touch easter eggs commands. I also prettified some strings (your source code reading experience should vastly improve!). Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
29 lines
1.1 KiB
Ruby
29 lines
1.1 KiB
Ruby
class Pry
|
|
# N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing.
|
|
class Command::RaiseUp < Pry::ClassCommand
|
|
match /raise-up(!?\b.*)/
|
|
group 'Context'
|
|
description 'Raise an exception out of the current pry instance.'
|
|
command_options :listing => 'raise-up'
|
|
|
|
banner <<-BANNER
|
|
Raise up, like exit, allows you to quit pry. Instead of returning a value however, it raises an exception.
|
|
If you don't provide the exception to be raised, it will use the most recent exception (in pry _ex_).
|
|
|
|
e.g. `raise-up "get-me-out-of-here"` is equivalent to:
|
|
`raise "get-me-out-of-here"
|
|
raise-up`
|
|
|
|
When called as raise-up! (with an exclamation mark), this command raises the exception through
|
|
any nested prys you have created by "cd"ing into objects.
|
|
BANNER
|
|
|
|
def process
|
|
return stagger_output help if captures[0] =~ /(-h|--help)\b/
|
|
# Handle 'raise-up', 'raise-up "foo"', 'raise-up RuntimeError, 'farble' in a rubyesque manner
|
|
target.eval("_pry_.raise_up#{captures[0]}")
|
|
end
|
|
end
|
|
|
|
Pry::Commands.add_command(Pry::Command::RaiseUp)
|
|
end
|