Convert all commands to classes

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>
This commit is contained in:
Kyrylo Silin 2012-12-25 23:35:17 +02:00
parent c2050dbb49
commit ebccd57013
44 changed files with 242 additions and 117 deletions

View File

@ -1,8 +1,9 @@
class Pry class Pry
Pry::Commands.create_command(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/) do class Command::AmendLine < Pry::ClassCommand
match /amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/
group 'Editing' group 'Editing'
description "Amend a line of input in multi-line mode." description 'Amend a line of input in multi-line mode.'
command_options :interpolate => false, :listing => "amend-line" command_options :interpolate => false, :listing => 'amend-line'
banner <<-'BANNER' banner <<-'BANNER'
Amend a line of input in multi-line mode. `amend-line N`, where the N in `amend-line N` represents line to replace. Amend a line of input in multi-line mode. `amend-line N`, where the N in `amend-line N` represents line to replace.
@ -40,5 +41,7 @@ class Pry
run "show-input" run "show-input"
end end
end end
Pry::Commands.add_command(Pry::Command::AmendLine)
end end

View File

@ -1,13 +1,16 @@
class Pry class Pry
Pry::Commands.create_command "!" do class Command::Bang < Pry::ClassCommand
match '!'
group 'Editing' group 'Editing'
description "Clear the input buffer. Useful if the parsing process goes " \ description 'Clear the input buffer. Useful if the parsing process goes ' \
"wrong and you get stuck in the read loop." 'wrong and you get stuck in the read loop.'
command_options :use_prefix => false command_options :use_prefix => false
def process def process
output.puts "Input buffer cleared!" output.puts 'Input buffer cleared!'
eval_string.replace("") eval_string.replace('')
end end
end end
Pry::Commands.add_command(Pry::Command::Bang)
end end

View File

@ -1,11 +1,14 @@
class Pry class Pry
Pry::Commands.create_command "!pry" do class Command::BangPry < Pry::ClassCommand
match '!pry'
group 'Navigating Pry' group 'Navigating Pry'
description "Start a Pry session on current self; this even works mid " \ description 'Start a Pry session on current self; this even works mid ' \
"multi-line expression." 'multi-line expression.'
def process def process
target.pry target.pry
end end
end end
Pry::Commands.add_command(Pry::Command::BangPry)
end end

View File

@ -1,5 +1,6 @@
class Pry class Pry
Pry::Commands.create_command "cat" do class Command::Cat < Pry::ClassCommand
match 'cat'
group 'Input and Output' group 'Input and Output'
description "Show code from a file, Pry's input buffer, or the last " \ description "Show code from a file, Pry's input buffer, or the last " \
"exception." "exception."
@ -175,4 +176,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::Cat)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "cd" do class Command::Cd < Pry::ClassCommand
group "Context" match 'cd'
description "Move into a new context (object or scope)." group 'Context'
description 'Move into a new context (object or scope).'
banner <<-BANNER banner <<-BANNER
Usage: cd [OPTIONS] [--help] Usage: cd [OPTIONS] [--help]
@ -25,4 +26,6 @@ class Pry
_pry_.binding_stack = stack if stack _pry_.binding_stack = stack if stack
end end
end end
Pry::Commands.add_command(Pry::Command::Cd)
end end

View File

@ -1,5 +1,6 @@
class Pry class Pry
Pry::Commands.create_command "disable-pry" do class Command::DisablePry < Pry::ClassCommand
match 'disable-pry'
group 'Navigating Pry' group 'Navigating Pry'
description 'Stops all future calls to pry and exits the current session.' description 'Stops all future calls to pry and exits the current session.'
@ -21,4 +22,6 @@ class Pry
_pry_.run_command "exit" _pry_.run_command "exit"
end end
end end
Pry::Commands.add_command(Pry::Command::DisablePry)
end end

View File

@ -6,9 +6,10 @@ class Pry
# the entire source code because an exception may happen anywhere in the # the entire source code because an exception may happen anywhere in the
# code and there is no way to predict that. So we simply superimpose # code and there is no way to predict that. So we simply superimpose
# everything (admittedly, doing extra job). # everything (admittedly, doing extra job).
Pry::Commands.create_command "edit" do class Command::Edit < Pry::ClassCommand
match 'edit'
group 'Editing' group 'Editing'
description "Invoke the default editor on a file." description 'Invoke the default editor on a file.'
banner <<-BANNER banner <<-BANNER
Usage: edit [--no-reload|--reload] [--line LINE] [--temp|--ex|FILE[:LINE]|--in N] Usage: edit [--no-reload|--reload] [--line LINE] [--temp|--ex|FILE[:LINE]|--in N]
@ -175,4 +176,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::Edit)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "edit-method" do class Command::EditMethod < Pry::ClassCommand
match 'edit-method'
group 'Editing' group 'Editing'
description "Edit the source code for a method." description 'Edit the source code for a method.'
banner <<-BANNER banner <<-BANNER
Usage: edit-method [OPTIONS] [METH] Usage: edit-method [OPTIONS] [METH]
@ -177,4 +178,6 @@ class Pry
source source
end end
end end
Pry::Commands.add_command(Pry::Command::EditMethod)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "exit" do class Command::Exit < Pry::ClassCommand
match 'exit'
group 'Navigating Pry' group 'Navigating Pry'
description "Pop the previous binding (does NOT exit program). Aliases: quit" description 'Pop the previous binding (does NOT exit program). Aliases: quit'
banner <<-BANNER banner <<-BANNER
Usage: exit [OPTIONS] [--help] Usage: exit [OPTIONS] [--help]
@ -38,5 +39,6 @@ class Pry
end end
end end
Pry::Commands.alias_command "quit", "exit" Pry::Commands.add_command(Pry::Command::Exit)
Pry::Commands.alias_command 'quit', 'exit'
end end

View File

@ -1,8 +1,9 @@
class Pry class Pry
Pry::Commands.create_command "exit-all" do class Command::ExitAll < Pry::ClassCommand
match 'exit-all'
group 'Navigating Pry' group 'Navigating Pry'
description "End the current Pry session (popping all bindings) and " \ description 'End the current Pry session (popping all bindings) and ' \
"returning to caller. Accepts optional return value. Aliases: !!@" 'returning to caller. Accepts optional return value. Aliases: !!@'
def process def process
# calculate user-given value # calculate user-given value
@ -16,5 +17,6 @@ class Pry
end end
end end
Pry::Commands.alias_command "!!@", "exit-all" Pry::Commands.add_command(Pry::Command::ExitAll)
Pry::Commands.alias_command '!!@', 'exit-all'
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "exit-program" do class Command::ExitProgram < Pry::ClassCommand
match 'exit-program'
group 'Navigating Pry' group 'Navigating Pry'
description "End the current program. Aliases: quit-program, !!!" description 'End the current program. Aliases: quit-program, !!!'
def process def process
Pry.save_history if Pry.config.history.should_save Pry.save_history if Pry.config.history.should_save
@ -9,6 +10,7 @@ class Pry
end end
end end
Pry::Commands.alias_command "quit-program", "exit-program" Pry::Commands.add_command(Pry::Command::ExitProgram)
Pry::Commands.alias_command "!!!", "exit-program" Pry::Commands.alias_command 'quit-program', 'exit-program'
Pry::Commands.alias_command '!!!', 'exit-program'
end end

View File

@ -1,13 +1,13 @@
class Pry class Pry
Pry::Commands.create_command "find-method" do class Command::FindMethod < Pry::ClassCommand
extend Pry::Helpers::BaseHelpers extend Pry::Helpers::BaseHelpers
group "Context" match 'find-method'
group 'Context'
options :requires_gem => "ruby18_source_location" if mri_18? options :requires_gem => 'ruby18_source_location' if mri_18?
options :shellwords => false options :shellwords => false
description "Recursively search for a method within a Class/Module or the current namespace. find-method [-n | -c] METHOD [NAMESPACE]" description 'Recursively search for a method within a Class/Module or the current namespace. find-method [-n | -c] METHOD [NAMESPACE]'
banner <<-BANNER banner <<-BANNER
Usage: find-method [-n | -c] METHOD [NAMESPACE] Usage: find-method [-n | -c] METHOD [NAMESPACE]
@ -162,4 +162,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::FindMethod)
end end

View File

@ -1,5 +1,6 @@
class Pry class Pry
Pry::Commands.create_command "gem-cd" do |gem| class Command::GemCd < Pry::ClassCommand
match 'gem-cd'
group 'Gems' group 'Gems'
description "Change working directory to specified gem's directory." description "Change working directory to specified gem's directory."
command_options :argument_required => true command_options :argument_required => true
@ -19,4 +20,6 @@ class Pry
gem_complete(str) gem_complete(str)
end end
end end
Pry::Commands.add_command(Pry::Command::GemCd)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "gem-install" do |gem| class Command::GemInstall < Pry::ClassCommand
match 'gem-install'
group 'Gems' group 'Gems'
description "Install a gem and refresh the gem cache." description 'Install a gem and refresh the gem cache.'
command_options :argument_required => true command_options :argument_required => true
banner <<-BANNER banner <<-BANNER
@ -30,4 +31,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::GemInstall)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "gem-list" do |pattern| class Command::GemList < Pry::ClassCommand
match 'gem-list'
group 'Gems' group 'Gems'
description "List and search installed gems." description 'List and search installed gems.'
banner <<-BANNER banner <<-BANNER
Usage: gem-list [REGEX] Usage: gem-list [REGEX]
@ -10,7 +11,7 @@ class Pry
match the regex. match the regex.
BANNER BANNER
def process(pattern=nil) def process(pattern = nil)
pattern = Regexp.compile(pattern || '') pattern = Regexp.compile(pattern || '')
gems = gem_list(pattern).group_by(&:name) gems = gem_list(pattern).group_by(&:name)
@ -27,4 +28,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::GemList)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "gem-open" do |gem| class Command::GemOpen < Pry::ClassCommand
match 'gem-open'
group 'Gems' group 'Gems'
description "Opens the working directory of the gem in your editor" description 'Opens the working directory of the gem in your editor'
command_options :argument_required => true command_options :argument_required => true
banner <<-BANNER banner <<-BANNER
@ -21,4 +22,6 @@ class Pry
gem_complete(str) gem_complete(str)
end end
end end
Pry::Commands.add_command(Pry::Command::GemOpen)
end end

View File

@ -28,9 +28,10 @@ class Pry
end end
end end
Pry::Commands.create_command "gist" do class Command::Gist < Pry::ClassCommand
include Pry::Helpers::DocumentationHelpers include Pry::Helpers::DocumentationHelpers
match 'gist'
group 'Misc' group 'Misc'
description Pry::Gist::DESCRIPTION description Pry::Gist::DESCRIPTION
command_options :requires_gem => 'jist', :shellwords => false command_options :requires_gem => 'jist', :shellwords => false
@ -192,6 +193,7 @@ class Pry
end end
Pry::Commands.alias_command "clipit", "gist --clip" Pry::Commands.add_command(Pry::Command::Gist)
Pry::Commands.alias_command "jist", "gist" Pry::Commands.alias_command 'clipit', 'gist --clip'
Pry::Commands.alias_command 'jist', 'gist'
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "help" do |cmd| class Command::Help < Pry::ClassCommand
match 'help'
group 'Help' group 'Help'
description "Show a list of commands. Type `help <foo>` for information about <foo>." description 'Show a list of commands. Type `help <foo>` for information about <foo>.'
banner <<-BANNER banner <<-BANNER
Usage: help [ COMMAND ] Usage: help [ COMMAND ]
@ -121,4 +122,6 @@ class Pry
[%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name] [%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name]
end end
end end
Pry::Commands.add_command(Pry::Command::Help)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "hist" do class Command::Hist < Pry::ClassCommand
group "Editing" match 'hist'
description "Show and replay Readline history. Aliases: history" group 'Editing'
description 'Show and replay Readline history. Aliases: history'
banner <<-USAGE banner <<-USAGE
Usage: hist Usage: hist
@ -153,5 +154,6 @@ class Pry
end end
end end
Pry::Commands.alias_command "history", "hist" Pry::Commands.add_command(Pry::Command::Hist)
Pry::Commands.alias_command 'history', 'hist'
end end

View File

@ -1,7 +1,10 @@
class Pry class Pry
Pry::Commands.create_command "import-set" do class Command::ImportSet < Pry::ClassCommand
group "Commands" match 'import-set'
description "Import a command set." group 'Commands'
# TODO: Provide a better description with examples and a general conception
# of this command.
description 'Import a Pry command set.'
def process(command_set_name) def process(command_set_name)
raise CommandError, "Provide a command set name" if command_set.nil? raise CommandError, "Provide a command set name" if command_set.nil?
@ -10,4 +13,6 @@ class Pry
_pry_.commands.import set _pry_.commands.import set
end end
end end
Pry::Commands.add_command(Pry::Command::ImportSet)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "install-command" do class Command::InstallCommand < Pry::ClassCommand
match 'install-command'
group 'Commands' group 'Commands'
description "Install a disabled command." description 'Install a disabled command.'
banner <<-BANNER banner <<-BANNER
Usage: install-command COMMAND Usage: install-command COMMAND
@ -45,4 +46,6 @@ class Pry
output.puts "Installation of `#{name}` successful! Type `help #{name}` for information" output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
end end
end end
Pry::Commands.add_command(Pry::Command::InstallCommand)
end end

View File

@ -1,8 +1,9 @@
class Pry class Pry
Pry::Commands.create_command "jump-to" do class Command::JumpTo < Pry::ClassCommand
match 'jump-to'
group 'Navigating Pry' group 'Navigating Pry'
description "Jump to a binding further up the stack, popping all " \ description 'Jump to a binding further up the stack, popping all ' \
"bindings below." 'bindings below.'
def process(break_level) def process(break_level)
break_level = break_level.to_i break_level = break_level.to_i
@ -20,4 +21,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::JumpTo)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "ls" do class Command::Ls < Pry::ClassCommand
group "Context" match 'ls'
description "Show the list of vars and methods in the current scope." group 'Context'
description 'Show the list of vars and methods in the current scope.'
command_options :shellwords => false, :interpolate => false command_options :shellwords => false, :interpolate => false
def options(opt) def options(opt)
@ -320,4 +321,6 @@ class Pry
text.send(Pry.config.ls.send(:"#{type}_color"), str) text.send(Pry.config.ls.send(:"#{type}_color"), str)
end end
end end
Pry::Commands.add_command(Pry::Command::Ls)
end end

View File

@ -1,11 +1,12 @@
class Pry class Pry
Pry::Commands.create_command "nesting" do class Command::Nesting < Pry::ClassCommand
match 'nesting'
group 'Navigating Pry' group 'Navigating Pry'
description "Show nesting information." description 'Show nesting information.'
def process def process
output.puts "Nesting status:" output.puts 'Nesting status:'
output.puts "--" output.puts '--'
_pry_.binding_stack.each_with_index do |obj, level| _pry_.binding_stack.each_with_index do |obj, level|
if level == 0 if level == 0
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)" output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)"
@ -15,4 +16,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::Nesting)
end end

View File

@ -1,9 +1,10 @@
class Pry class Pry
Pry::Commands.create_command "play" do class Command::Play < Pry::ClassCommand
include Pry::Helpers::DocumentationHelpers include Pry::Helpers::DocumentationHelpers
match 'play'
group 'Editing' group 'Editing'
description "Play back a string variable or a method or a file as input." description 'Play back a string variable or a method or a file as input.'
banner <<-BANNER banner <<-BANNER
Usage: play [OPTIONS] [--help] Usage: play [OPTIONS] [--help]
@ -115,6 +116,7 @@ class Pry
self.content << File.read(_pry_.last_file) self.content << File.read(_pry_.last_file)
self.content = restrict_to_lines(self.content, lines) self.content = restrict_to_lines(self.content, lines)
end end
end end
Pry::Commands.add_command(Pry::Command::Play)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "pry-backtrace" do class Command::PryBacktrace < Pry::ClassCommand
match 'pry-backtrace'
group 'Context' group 'Context'
description "Show the backtrace for the Pry session." description 'Show the backtrace for the Pry session.'
banner <<-BANNER banner <<-BANNER
Usage: pry-backtrace [OPTIONS] [--help] Usage: pry-backtrace [OPTIONS] [--help]
@ -21,4 +22,6 @@ class Pry
stagger_output _pry_.backtrace.join("\n") stagger_output _pry_.backtrace.join("\n")
end end
end end
Pry::Commands.add_command(Pry::Command::PryBacktrace)
end end

View File

@ -1,10 +1,13 @@
class Pry class Pry
Pry::Commands.create_command "pry-version" do class Command::Version < Pry::ClassCommand
match 'pry-version'
group 'Misc' group 'Misc'
description "Show Pry version." description 'Show Pry version.'
def process def process
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}." output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
end end
end end
Pry::Commands.add_command(Pry::Command::Version)
end end

View File

@ -1,8 +1,9 @@
class Pry class Pry
# N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing. # N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing.
Pry::Commands.create_command(/raise-up(!?\b.*)/) do class Command::RaiseUp < Pry::ClassCommand
match /raise-up(!?\b.*)/
group 'Context' group 'Context'
description "Raise an exception out of the current pry instance." description 'Raise an exception out of the current pry instance.'
command_options :listing => 'raise-up' command_options :listing => 'raise-up'
banner <<-BANNER banner <<-BANNER
@ -23,4 +24,6 @@ class Pry
target.eval("_pry_.raise_up#{captures[0]}") target.eval("_pry_.raise_up#{captures[0]}")
end end
end end
Pry::Commands.add_command(Pry::Command::RaiseUp)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "reload-method" do class Command::ReloadMethod < Pry::ClassCommand
match 'reload-method'
group 'Misc' group 'Misc'
description "Reload the source file that contains the specified method" description 'Reload the source file that contains the specified method'
def process(meth_name) def process(meth_name)
meth = get_method_or_raise(meth_name, target, {}, :omit_help) meth = get_method_or_raise(meth_name, target, {}, :omit_help)
@ -17,4 +18,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::ReloadMethod)
end end

View File

@ -1,11 +1,14 @@
class Pry class Pry
Pry::Commands.create_command "reset" do class Command::Reset < Pry::ClassCommand
match 'reset'
group 'Context' group 'Context'
description "Reset the REPL to a clean state." description 'Reset the REPL to a clean state.'
def process def process
output.puts "Pry reset." output.puts 'Pry reset.'
exec "pry" exec 'pry'
end end
end end
Pry::Commands.add_command(Pry::Command::Reset)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "ri" do class Command::Ri < Pry::ClassCommand
match 'ri'
group 'Introspection' group 'Introspection'
description "View ri documentation. e.g `ri Array#each`" description 'View ri documentation. e.g `ri Array#each`'
banner <<-BANNER banner <<-BANNER
Usage: ri [spec] Usage: ri [spec]
@ -48,4 +49,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::Ri)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "save-file" do class Command::SaveFile < Pry::ClassCommand
match 'save-file'
group 'Input and Output' group 'Input and Output'
description "Export to a file using content from the REPL." description 'Export to a file using content from the REPL.'
banner <<-USAGE banner <<-USAGE
Usage: save-file [OPTIONS] [FILE] Usage: save-file [OPTIONS] [FILE]
@ -96,4 +97,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::SaveFile)
end end

View File

@ -1,8 +1,9 @@
class Pry class Pry
Pry::Commands.create_command(/\.(.*)/) do class Command::ShellCommand < Pry::ClassCommand
match /\.(.*)/
group 'Input and Output' group 'Input and Output'
description "All text following a '.' is forwarded to the shell." description "All text following a '.' is forwarded to the shell."
command_options :listing => ".<shell command>", :use_prefix => false, command_options :listing => '.<shell command>', :use_prefix => false,
:takes_block => true :takes_block => true
def process(cmd) def process(cmd)
@ -28,4 +29,6 @@ class Pry
super + Bond::Rc.files(search.split(" ").last || '') super + Bond::Rc.files(search.split(" ").last || '')
end end
end end
Pry::Commands.add_command(Pry::Command::ShellCommand)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "shell-mode" do class Command::ShellMode < Pry::ClassCommand
match 'shell-mode'
group 'Input and Output' group 'Input and Output'
description "Toggle shell mode. Bring in pwd prompt and file completion." description 'Toggle shell mode. Bring in pwd prompt and file completion.'
def process def process
case _pry_.prompt case _pry_.prompt
@ -17,5 +18,6 @@ class Pry
end end
end end
Pry::Commands.alias_command "file-mode", "shell-mode" Pry::Commands.add_command(Pry::Command::ShellMode)
Pry::Commands.alias_command 'file-mode', 'shell-mode'
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "show-command" do class Command::ShowCommand < Pry::ClassCommand
match 'show-command'
group 'Introspection' group 'Introspection'
description "Show the source for CMD." description 'Show the source for CMD.'
def process(*args) def process(*args)
target = target() target = target()
@ -19,4 +20,6 @@ class Pry
render_output opts.banner render_output opts.banner
end end
end end
Pry::Commands.add_command(Pry::Command::ShowCommand)
end end

View File

@ -1,12 +1,13 @@
class Pry class Pry
Pry::Commands.create_command "show-doc" do class Command::ShowDoc < Pry::ClassCommand
include Pry::Helpers::DocumentationHelpers include Pry::Helpers::DocumentationHelpers
extend Pry::Helpers::BaseHelpers extend Pry::Helpers::BaseHelpers
match 'show-doc'
group 'Introspection' group 'Introspection'
description "Show the documentation for a method or class. Aliases: \?" description 'Show the documentation for a method or class. Aliases: \?'
command_options :shellwords => false command_options :shellwords => false
command_options :requires_gem => "ruby18_source_location" if mri_18? command_options :requires_gem => 'ruby18_source_location' if mri_18?
banner <<-BANNER banner <<-BANNER
Usage: show-doc [OPTIONS] [METH] Usage: show-doc [OPTIONS] [METH]
@ -174,5 +175,6 @@ class Pry
end end
end end
Pry::Commands.alias_command "?", "show-doc" Pry::Commands.add_command(Pry::Command::ShowDoc)
Pry::Commands.alias_command '?', 'show-doc'
end end

View File

@ -1,10 +1,13 @@
class Pry class Pry
Pry::Commands.create_command "show-input" do class Command::ShowInput < Pry::ClassCommand
match 'show-input'
group 'Editing' group 'Editing'
description "Show the contents of the input buffer for the current multi-line expression." description 'Show the contents of the input buffer for the current multi-line expression.'
def process def process
output.puts Code.new(eval_string).with_line_numbers output.puts Code.new(eval_string).with_line_numbers
end end
end end
Pry::Commands.add_command(Pry::Command::ShowInput)
end end

View File

@ -1,9 +1,10 @@
class Pry class Pry
Pry::Commands.create_command "show-source" do class Command::ShowSource < Pry::ClassCommand
extend Pry::Helpers::BaseHelpers extend Pry::Helpers::BaseHelpers
match 'show-source'
group 'Introspection' group 'Introspection'
description "Show the source for a method or class. Aliases: $, show-method" description 'Show the source for a method or class. Aliases: $, show-method'
banner <<-BANNER banner <<-BANNER
Usage: show-source [OPTIONS] [METH|CLASS] Usage: show-source [OPTIONS] [METH|CLASS]
@ -130,6 +131,7 @@ class Pry
end end
end end
Pry::Commands.alias_command "show-method", "show-source" Pry::Commands.add_command(Pry::Command::ShowSource)
Pry::Commands.alias_command "$", "show-source" Pry::Commands.alias_command 'show-method', 'show-source'
Pry::Commands.alias_command '$', 'show-source'
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "simple-prompt" do class Command::SimplePrompt < Pry::ClassCommand
match 'simple-prompt'
group 'Misc' group 'Misc'
description "Toggle the simple prompt." description 'Toggle the simple prompt.'
def process def process
case _pry_.prompt case _pry_.prompt
@ -12,4 +13,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::SimplePrompt)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command "stat" do class Command::Stat < Pry::ClassCommand
match 'stat'
group 'Introspection' group 'Introspection'
description "View method information and set _file_ and _dir_ locals." description 'View method information and set _file_ and _dir_ locals.'
command_options :shellwords => false command_options :shellwords => false
banner <<-BANNER banner <<-BANNER
@ -32,4 +33,6 @@ class Pry
EOS EOS
end end
end end
Pry::Commands.add_command(Pry::Command::Stat)
end end

View File

@ -1,8 +1,9 @@
class Pry class Pry
Pry::Commands.create_command "switch-to" do class Command::SwitchTo < Pry::ClassCommand
match 'switch-to'
group 'Navigating Pry' group 'Navigating Pry'
description "Start a new sub-session on a binding in the current stack " \ description 'Start a new subsession on a binding in the current stack ' \
"(numbered by nesting)." '(numbered by nesting).'
def process(selection) def process(selection)
selection = selection.to_i selection = selection.to_i
@ -14,4 +15,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::SwitchTo)
end end

View File

@ -1,11 +1,14 @@
class Pry class Pry
Pry::Commands.create_command "toggle-color" do class Command::ToggleColor < Pry::ClassCommand
match 'toggle-color'
group 'Misc' group 'Misc'
description "Toggle syntax highlighting." description 'Toggle syntax highlighting.'
def process def process
Pry.color = !Pry.color Pry.color = !Pry.color
output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}" output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}"
end end
end end
Pry::Commands.add_command(Pry::Command::ToggleColor)
end end

View File

@ -1,7 +1,9 @@
class Pry class Pry
Pry::Commands.create_command "whereami" do class Command::Whereami < Pry::ClassCommand
description "Show code surrounding the current context." match 'whereami'
description 'Show code surrounding the current context.'
group 'Context' group 'Context'
banner <<-BANNER banner <<-BANNER
Usage: whereami [-q] [N] Usage: whereami [-q] [N]
@ -84,4 +86,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::Whereami)
end end

View File

@ -1,7 +1,8 @@
class Pry class Pry
Pry::Commands.create_command(/wtf([?!]*)/) do class Command::Wtf < Pry::ClassCommand
match /wtf([?!]*)/
group 'Context' group 'Context'
description "Show the backtrace of the most recent exception" description 'Show the backtrace of the most recent exception'
options :listing => 'wtf?' options :listing => 'wtf?'
banner <<-BANNER banner <<-BANNER
@ -35,4 +36,6 @@ class Pry
end end
end end
end end
Pry::Commands.add_command(Pry::Command::Wtf)
end end