Restore groups, convert most commands to class syntax
This commit is contained in:
parent
8ce49ee081
commit
1af4207c63
|
@ -1,5 +1,6 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/) do
|
||||
group 'Editing'
|
||||
description "Amend a line of input in multi-line mode."
|
||||
command_options :interpolate => false, :listing => "amend-line"
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop.", :use_prefix => false do
|
||||
Pry::Commands.create_command "!" do
|
||||
group 'Editing'
|
||||
description "Clear the input buffer. Useful if the parsing process goes " \
|
||||
"wrong and you get stuck in the read loop."
|
||||
command_options :use_prefix => false
|
||||
|
||||
def process
|
||||
output.puts "Input buffer cleared!"
|
||||
eval_string.replace("")
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
class Pry
|
||||
Pry::Commands.command "!pry", "Start a Pry session on current self; this even works mid multi-line expression." do
|
||||
Pry::Commands.create_command "!pry" do
|
||||
group 'Navigating Pry'
|
||||
description "Start a Pry session on current self; this even works mid " \
|
||||
"multi-line expression."
|
||||
|
||||
def process
|
||||
target.pry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "cat", "Show code from a file, Pry's input buffer, or the last exception." do
|
||||
Pry::Commands.create_command "cat" do
|
||||
group 'Input and Output'
|
||||
description "Show code from a file, Pry's input buffer, or the last " \
|
||||
"exception."
|
||||
|
||||
banner <<-USAGE
|
||||
Usage: cat FILE
|
||||
cat --ex [STACK_INDEX]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "edit" do
|
||||
group 'Editing'
|
||||
description "Invoke the default editor on a file."
|
||||
|
||||
banner <<-BANNER
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "edit-method" do
|
||||
group 'Editing'
|
||||
description "Edit the source code for a method."
|
||||
|
||||
banner <<-BANNER
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "exit" do
|
||||
group 'Navigating Pry'
|
||||
description "Pop the previous binding (does NOT exit program). Aliases: quit"
|
||||
|
||||
banner <<-BANNER
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
class Pry
|
||||
Pry::Commands.command "exit-all", "End the current Pry session (popping all bindings) and returning to caller. Accepts optional return value. Aliases: !!@" do
|
||||
Pry::Commands.create_command "exit-all" do
|
||||
group 'Navigating Pry'
|
||||
description "End the current Pry session (popping all bindings) and " \
|
||||
"returning to caller. Accepts optional return value. Aliases: !!@"
|
||||
|
||||
def process
|
||||
# calculate user-given value
|
||||
exit_value = target.eval(arg_string)
|
||||
|
||||
|
@ -9,6 +14,7 @@ class Pry
|
|||
# break out of the repl loop
|
||||
throw(:breakout, exit_value)
|
||||
end
|
||||
end
|
||||
|
||||
Pry::Commands.alias_command "!!@", "exit-all"
|
||||
end
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
class Pry
|
||||
Pry::Commands.command "exit-program", "End the current program. Aliases: quit-program, !!!" do
|
||||
Pry::Commands.create_command "exit-program" do
|
||||
group 'Navigating Pry'
|
||||
description "End the current program. Aliases: quit-program, !!!"
|
||||
|
||||
def process
|
||||
Pry.save_history if Pry.config.history.should_save
|
||||
Kernel.exit target.eval(arg_string).to_i
|
||||
end
|
||||
end
|
||||
|
||||
Pry::Commands.alias_command "quit-program", "exit-program"
|
||||
Pry::Commands.alias_command "!!!", "exit-program"
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "gem-cd", "Change working directory to specified gem's directory.", :argument_required => true do |gem|
|
||||
Pry::Commands.create_command "gem-cd" do |gem|
|
||||
group 'Gems'
|
||||
description "Change working directory to specified gem's directory."
|
||||
command_options :argument_required => true
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: gem-cd GEM_NAME
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "gem-install", "Install a gem and refresh the gem cache.", :argument_required => true do |gem|
|
||||
Pry::Commands.create_command "gem-install" do |gem|
|
||||
group 'Gems'
|
||||
description "Install a gem and refresh the gem cache."
|
||||
command_options :argument_required => true
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: gem-install GEM_NAME
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "gem-list", "List and search installed gems." do |pattern|
|
||||
Pry::Commands.create_command "gem-list" do |pattern|
|
||||
group 'Gems'
|
||||
description "List and search installed gems."
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: gem-list [REGEX]
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "gist", "Gist a method or expression history to GitHub.", :requires_gem => "jist" do
|
||||
Pry::Commands.create_command "gist" do
|
||||
include Pry::Helpers::DocumentationHelpers
|
||||
|
||||
group 'Misc'
|
||||
description "Gist a method or expression history to GitHub."
|
||||
command_options :requires_gem => 'jist', :shellwords => false
|
||||
|
||||
banner <<-USAGE
|
||||
Usage: gist [OPTIONS] [METH]
|
||||
Gist method (doc or source) or input expression to GitHub.
|
||||
|
@ -17,8 +21,6 @@ class Pry
|
|||
e.g: gist -m my_method --clip # Copy my_method source to clipboard, do not gist it.
|
||||
USAGE
|
||||
|
||||
command_options :shellwords => false
|
||||
|
||||
attr_accessor :content
|
||||
attr_accessor :filename
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "hist", "Show and replay Readline history. Aliases: history" do
|
||||
Pry::Commands.create_command "hist" do
|
||||
group "Editing"
|
||||
description "Show and replay Readline history. Aliases: history"
|
||||
|
||||
banner <<-USAGE
|
||||
Usage: hist
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "import-set", "Import a command set" do
|
||||
Pry::Commands.create_command "import-set" do
|
||||
group "Commands"
|
||||
description "Import a command set."
|
||||
|
||||
def process(command_set_name)
|
||||
raise CommandError, "Provide a command set name" if command_set.nil?
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "install-command", "Install a disabled command." do |name|
|
||||
Pry::Commands.create_command "install-command" do
|
||||
group 'Commands'
|
||||
description "Install a disabled command."
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: install-command COMMAND
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
class Pry
|
||||
Pry::Commands.command "jump-to", "Jump to a binding further up the stack, popping all bindings below." do |break_level|
|
||||
Pry::Commands.create_command "jump-to" do
|
||||
group 'Navigating Pry'
|
||||
description "Jump to a binding further up the stack, popping all " \
|
||||
"bindings below."
|
||||
|
||||
def process(break_level)
|
||||
break_level = break_level.to_i
|
||||
nesting_level = _pry_.binding_stack.size - 1
|
||||
|
||||
|
@ -15,3 +20,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "ls","Show the list of vars and methods in the current scope.",
|
||||
:shellwords => false, :interpolate => false do
|
||||
|
||||
Pry::Commands.create_command "ls" do
|
||||
group "Context"
|
||||
description "Show the list of vars and methods in the current scope."
|
||||
command_options :shellwords => false, :interpolate => false
|
||||
|
||||
def options(opt)
|
||||
opt.banner unindent <<-USAGE
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.command "nesting", "Show nesting information." do
|
||||
Pry::Commands.create_command "nesting" do
|
||||
group 'Navigating Pry'
|
||||
description "Show nesting information."
|
||||
|
||||
def process
|
||||
output.puts "Nesting status:"
|
||||
output.puts "--"
|
||||
_pry_.binding_stack.each_with_index do |obj, level|
|
||||
|
@ -11,3 +15,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ class Pry
|
|||
Pry::Commands.create_command "play" do
|
||||
include Pry::Helpers::DocumentationHelpers
|
||||
|
||||
group 'Editing'
|
||||
description "Play back a string variable or a method or a file as input."
|
||||
|
||||
banner <<-BANNER
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "pry-backtrace", "Show the backtrace for the Pry session." do
|
||||
Pry::Commands.create_command "pry-backtrace" do
|
||||
group 'Context'
|
||||
description "Show the backtrace for the Pry session."
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: pry-backtrace [OPTIONS] [--help]
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
class Pry
|
||||
Pry::Commands.command "pry-version", "Show Pry version." do
|
||||
Pry::Commands.create_command "pry-version" do
|
||||
group 'Misc'
|
||||
description "Show Pry version."
|
||||
|
||||
def process
|
||||
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
class Pry
|
||||
# N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing.
|
||||
Pry::Commands.create_command(/raise-up(!?\b.*)/, :listing => 'raise-up') do
|
||||
Pry::Commands.create_command(/raise-up(!?\b.*)/) do
|
||||
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_).
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.command "reload-method", "Reload the source file that contains the specified method" do |meth_name|
|
||||
Pry::Commands.create_command "reload-method" do
|
||||
group 'Misc'
|
||||
description "Reload the source file that contains the specified method"
|
||||
|
||||
def process(meth_name)
|
||||
meth = get_method_or_raise(meth_name, target, {}, :omit_help)
|
||||
|
||||
if meth.source_type == :c
|
||||
|
@ -13,3 +17,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
class Pry
|
||||
Pry::Commands.command "reset", "Reset the REPL to a clean state." do
|
||||
Pry::Commands.create_command "reset" do
|
||||
group 'Context'
|
||||
description "Reset the REPL to a clean state."
|
||||
|
||||
def process
|
||||
output.puts "Pry reset."
|
||||
exec "pry"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "ri", "View ri documentation. e.g `ri Array#each`" do
|
||||
Pry::Commands.create_command "ri" do
|
||||
group 'Introspection'
|
||||
description "View ri documentation. e.g `ri Array#each`"
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: ri [spec]
|
||||
e.g. ri Array#each
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "save-file", "Export to a file using content from the REPL." do
|
||||
Pry::Commands.create_command "save-file" do
|
||||
group 'Input and Output'
|
||||
description "Export to a file using content from the REPL."
|
||||
|
||||
banner <<-USAGE
|
||||
Usage: save-file [OPTIONS] [FILE]
|
||||
Save REPL content to a file.
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
class Pry
|
||||
Pry::Commands.command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>", :use_prefix => false, :takes_block => true) do |cmd|
|
||||
Pry::Commands.create_command(/\.(.*)/) do
|
||||
group 'Input and Output'
|
||||
description "All text following a '.' is forwarded to the shell."
|
||||
command_options :listing => ".<shell command>", :use_prefix => false,
|
||||
:takes_block => true
|
||||
|
||||
def process(cmd)
|
||||
if cmd =~ /^cd\s+(.+)/i
|
||||
dest = $1
|
||||
begin
|
||||
|
@ -18,3 +24,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do
|
||||
Pry::Commands.create_command "shell-mode" do
|
||||
group 'Input and Output'
|
||||
description "Toggle shell mode. Bring in pwd prompt and file completion."
|
||||
|
||||
def process
|
||||
case _pry_.prompt
|
||||
when Pry::SHELL_PROMPT
|
||||
_pry_.pop_prompt
|
||||
|
@ -11,6 +15,7 @@ class Pry
|
|||
_pry_.instance_eval(&Pry::FILE_COMPLETIONS)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Pry::Commands.alias_command "file-mode", "shell-mode"
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.command "show-command", "Show the source for CMD." do |*args|
|
||||
Pry::Commands.create_command "show-command" do
|
||||
group 'Introspection'
|
||||
description "Show the source for CMD."
|
||||
|
||||
def process(*args)
|
||||
target = target()
|
||||
|
||||
opts = Slop.parse!(args) do |opt|
|
||||
|
@ -16,7 +20,7 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
next if opts.present?(:help)
|
||||
return if opts.present?(:help)
|
||||
|
||||
command_name = args.shift
|
||||
if !command_name
|
||||
|
@ -26,7 +30,7 @@ class Pry
|
|||
if find_command(command_name)
|
||||
block = Pry::Method.new(find_command(command_name).block)
|
||||
|
||||
next unless block.source
|
||||
return unless block.source
|
||||
set_file_and_dir_locals(block.source_file)
|
||||
|
||||
output.puts make_header(block)
|
||||
|
@ -40,3 +44,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "show-doc", "Show the documentation for a method or class. Aliases: \?", :shellwords => false do
|
||||
Pry::Commands.create_command "show-doc" do
|
||||
include Pry::Helpers::ModuleIntrospectionHelpers
|
||||
include Pry::Helpers::DocumentationHelpers
|
||||
extend Pry::Helpers::BaseHelpers
|
||||
|
||||
group 'Introspection'
|
||||
description "Show the documentation for a method or class. Aliases: \?"
|
||||
command_options :shellwords => false
|
||||
command_options :requires_gem => "ruby18_source_location" if mri_18?
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: show-doc [OPTIONS] [METH]
|
||||
Aliases: ?
|
||||
|
@ -14,8 +19,6 @@ class Pry
|
|||
e.g show-doc Pry -a # docs for all definitions of Pry class (all monkey patches)
|
||||
BANNER
|
||||
|
||||
options :requires_gem => "ruby18_source_location" if mri_18?
|
||||
|
||||
def setup
|
||||
require 'ruby18_source_location' if mri_18?
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "show-input", "Show the contents of the input buffer for the current multi-line expression." do
|
||||
Pry::Commands.create_command "show-input" do
|
||||
group 'Editing'
|
||||
description "Show the contents of the input buffer for the current multi-line expression."
|
||||
|
||||
def process
|
||||
output.puts Code.new(eval_string).with_line_numbers
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ class Pry
|
|||
include Pry::Helpers::ModuleIntrospectionHelpers
|
||||
extend Pry::Helpers::BaseHelpers
|
||||
|
||||
group 'Introspection'
|
||||
description "Show the source for a method or class. Aliases: $, show-method"
|
||||
|
||||
banner <<-BANNER
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.command "simple-prompt", "Toggle the simple prompt." do
|
||||
Pry::Commands.create_command "simple-prompt" do
|
||||
group 'Misc'
|
||||
description "Toggle the simple prompt."
|
||||
|
||||
def process
|
||||
case _pry_.prompt
|
||||
when Pry::SIMPLE_PROMPT
|
||||
_pry_.pop_prompt
|
||||
|
@ -8,3 +12,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command "stat", "View method information and set _file_ and _dir_ locals.", :shellwords => false do
|
||||
Pry::Commands.create_command "stat" do
|
||||
group 'Introspection'
|
||||
description "View method information and set _file_ and _dir_ locals."
|
||||
command_options :shellwords => false
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: stat [OPTIONS] [METH]
|
||||
Show method information for method METH and set _file_ and _dir_ locals.
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
class Pry
|
||||
Pry::Commands.command "switch-to", "Start a new sub-session on a binding in the current stack (numbered by nesting)." do |selection|
|
||||
Pry::Commands.create_command "switch-to" do
|
||||
group 'Navigating Pry'
|
||||
description "Start a new sub-session on a binding in the current stack " \
|
||||
"(numbered by nesting)."
|
||||
|
||||
def process(selection)
|
||||
selection = selection.to_i
|
||||
|
||||
if selection < 0 || selection > _pry_.binding_stack.size - 1
|
||||
|
@ -9,3 +14,4 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
class Pry
|
||||
Pry::Commands.command "toggle-color", "Toggle syntax highlighting." do
|
||||
Pry::Commands.create_command "toggle-color" do
|
||||
group 'Misc'
|
||||
description "Toggle syntax highlighting."
|
||||
|
||||
def process
|
||||
Pry.color = !Pry.color
|
||||
output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command(/wtf([?!]*)/, "Show the backtrace of the most recent exception") do
|
||||
Pry::Commands.create_command(/wtf([?!]*)/) do
|
||||
group 'Context'
|
||||
description "Show the backtrace of the most recent exception"
|
||||
options :listing => 'wtf?'
|
||||
|
||||
banner <<-BANNER
|
||||
|
|
Loading…
Reference in New Issue