2011-05-11 05:39:15 -04:00
|
|
|
class Pry
|
2011-05-15 13:31:07 -04:00
|
|
|
module ExtendedCommands
|
2011-05-11 05:39:15 -04:00
|
|
|
|
|
|
|
UserCommandAPI = Pry::CommandSet.new do
|
|
|
|
|
2011-06-16 09:50:19 -04:00
|
|
|
command "define-command", "Define a command in the session, use same syntax as `command` method for command API" do |arg|
|
2011-05-11 05:39:15 -04:00
|
|
|
next output.puts("Provide an arg!") if arg.nil?
|
|
|
|
|
2011-05-29 23:57:06 -04:00
|
|
|
prime_string = "command #{arg_string}\n"
|
2011-05-11 05:39:15 -04:00
|
|
|
command_string = Pry.active_instance.r(target, prime_string)
|
|
|
|
|
2011-05-29 23:57:06 -04:00
|
|
|
eval_string.replace <<-HERE
|
2011-05-11 05:39:15 -04:00
|
|
|
_pry_.commands.instance_eval do
|
|
|
|
#{command_string}
|
|
|
|
end
|
|
|
|
HERE
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-08-01 17:30:13 -04:00
|
|
|
command "reload-command", "Reload a command. reload-command CMD_NAME CMD_SET" do |command_name, set_name|
|
2011-08-02 18:29:25 -04:00
|
|
|
next output.puts "Must provide command name" if command_name.nil?
|
|
|
|
next output.puts "Must provide command set name" if set_name.nil?
|
|
|
|
|
2011-08-01 17:30:13 -04:00
|
|
|
cmd = Pry.config.commands.commands[command_name]
|
2011-08-02 18:29:25 -04:00
|
|
|
file_name = cmd.block.source_location.first
|
|
|
|
|
|
|
|
silence_warnings do
|
|
|
|
load file_name
|
|
|
|
end
|
2011-08-01 17:30:13 -04:00
|
|
|
Pry.config.commands.import target.eval(set_name)
|
|
|
|
Pry.active_instance.commands.import target.eval(set_name)
|
2011-08-02 18:29:25 -04:00
|
|
|
set_file_and_dir_locals(file_name)
|
2011-08-01 17:30:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
command "edit-command", "Edit a command. edit-command CMD_NAME CMD_SET" do |command_name, set_name|
|
2011-08-02 18:29:25 -04:00
|
|
|
next output.puts "Must provide command name" if command_name.nil?
|
|
|
|
next output.puts "Must provide a command set name" if set_name.nil?
|
|
|
|
|
2011-08-01 17:30:13 -04:00
|
|
|
cmd = Pry.config.commands.commands[command_name]
|
2011-08-02 18:29:25 -04:00
|
|
|
file_name = cmd.block.source_location.first
|
|
|
|
|
2011-08-01 17:30:13 -04:00
|
|
|
invoke_editor(*cmd.block.source_location)
|
2011-08-02 18:29:25 -04:00
|
|
|
silence_warnings do
|
|
|
|
load file_name
|
|
|
|
end
|
2011-08-01 17:30:13 -04:00
|
|
|
Pry.config.commands.import target.eval(set_name)
|
|
|
|
Pry.active_instance.commands.import target.eval(set_name)
|
2011-08-02 18:29:25 -04:00
|
|
|
set_file_and_dir_locals(file_name)
|
2011-08-01 17:30:13 -04:00
|
|
|
end
|
|
|
|
|
2011-05-11 05:39:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|