pry 0.10.pre.1-i386-mswin32 → 0.10.0.pre3-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +122 -183
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +23 -0
- data/lib/pry/commands/find_method.rb +193 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +32 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/completion.rb +0 -221
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -1,120 +0,0 @@
|
|
1
|
-
class Pry
|
2
|
-
module DefaultCommands
|
3
|
-
Hist = Pry::CommandSet.new do
|
4
|
-
|
5
|
-
create_command "hist", "Show and replay Readline history. Aliases: history" do
|
6
|
-
group "Editing"
|
7
|
-
banner <<-USAGE
|
8
|
-
Usage: hist
|
9
|
-
hist --head N
|
10
|
-
hist --tail N
|
11
|
-
hist --show START..END
|
12
|
-
hist --grep PATTERN
|
13
|
-
hist --clear
|
14
|
-
hist --replay START..END
|
15
|
-
hist --save [START..END] FILE
|
16
|
-
USAGE
|
17
|
-
|
18
|
-
def options(opt)
|
19
|
-
opt.on :H, :head, "Display the first N items.", :optional_argument => true, :as => Integer
|
20
|
-
opt.on :T, :tail, "Display the last N items.", :optional_argument => true, :as => Integer
|
21
|
-
opt.on :s, :show, "Show the given range of lines.", :optional_argument => true, :as => Range
|
22
|
-
opt.on :G, :grep, "Show lines matching the given pattern.", :argument => true, :as => String
|
23
|
-
opt.on :c, :clear, "Clear the current session's history."
|
24
|
-
opt.on :r, :replay, "Replay a line or range of lines.", :argument => true, :as => Range
|
25
|
-
opt.on :save, "Save history to a file.", :argument => true, :as => Range
|
26
|
-
|
27
|
-
opt.on :e, :'exclude-pry', "Exclude Pry commands from the history."
|
28
|
-
opt.on :n, :'no-numbers', "Omit line numbers."
|
29
|
-
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
30
|
-
end
|
31
|
-
|
32
|
-
def process
|
33
|
-
@history = Pry::Code(Pry.history.to_a)
|
34
|
-
|
35
|
-
if opts.present?(:show)
|
36
|
-
@history = @history.between(opts[:show])
|
37
|
-
end
|
38
|
-
|
39
|
-
if opts.present?(:grep)
|
40
|
-
@history = @history.grep(opts[:grep])
|
41
|
-
end
|
42
|
-
|
43
|
-
@history = case
|
44
|
-
when opts.present?(:head)
|
45
|
-
@history.take_lines(1, opts[:head] || 10)
|
46
|
-
when opts.present?(:tail)
|
47
|
-
@history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
|
48
|
-
when opts.present?(:show)
|
49
|
-
@history.between(opts[:show])
|
50
|
-
else
|
51
|
-
@history
|
52
|
-
end
|
53
|
-
|
54
|
-
if opts.present?(:'exclude-pry')
|
55
|
-
@history = @history.select { |l, ln| !command_set.valid_command?(l) }
|
56
|
-
end
|
57
|
-
|
58
|
-
if opts.present?(:save)
|
59
|
-
process_save
|
60
|
-
elsif opts.present?(:clear)
|
61
|
-
process_clear
|
62
|
-
elsif opts.present?(:replay)
|
63
|
-
process_replay
|
64
|
-
else
|
65
|
-
process_display
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def process_display
|
70
|
-
unless opts.present?(:'no-numbers')
|
71
|
-
@history = @history.with_line_numbers
|
72
|
-
end
|
73
|
-
|
74
|
-
render_output(@history, opts)
|
75
|
-
end
|
76
|
-
|
77
|
-
def process_save
|
78
|
-
case opts[:save]
|
79
|
-
when Range
|
80
|
-
@history = @history.between(opts[:save])
|
81
|
-
|
82
|
-
unless args.first
|
83
|
-
raise CommandError, "Must provide a file name."
|
84
|
-
end
|
85
|
-
|
86
|
-
file_name = File.expand_path(args.first)
|
87
|
-
when String
|
88
|
-
file_name = File.expand_path(opts[:save])
|
89
|
-
end
|
90
|
-
|
91
|
-
output.puts "Saving history in #{file_name}..."
|
92
|
-
|
93
|
-
File.open(file_name, 'w') { |f| f.write(@history.raw) }
|
94
|
-
|
95
|
-
output.puts "History saved."
|
96
|
-
end
|
97
|
-
|
98
|
-
def process_clear
|
99
|
-
Pry.history.clear
|
100
|
-
output.puts "History cleared."
|
101
|
-
end
|
102
|
-
|
103
|
-
def process_replay
|
104
|
-
@history = @history.between(opts[:r])
|
105
|
-
|
106
|
-
_pry_.input_stack.push _pry_.input
|
107
|
-
_pry_.input = StringIO.new(@history.raw)
|
108
|
-
# eval_string << "#{@history.raw}\n"
|
109
|
-
# run "show-input" unless _pry_.complete_expression?(eval_string)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
alias_command "history", "hist"
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,306 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
require 'pry/default_commands/gist'
|
3
|
-
|
4
|
-
class Pry
|
5
|
-
module DefaultCommands
|
6
|
-
|
7
|
-
InputAndOutput = Pry::CommandSet.new do
|
8
|
-
import Gist
|
9
|
-
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>", :use_prefix => false, :takes_block => true) do |cmd|
|
10
|
-
if cmd =~ /^cd\s+(.+)/i
|
11
|
-
dest = $1
|
12
|
-
begin
|
13
|
-
Dir.chdir File.expand_path(dest)
|
14
|
-
rescue Errno::ENOENT
|
15
|
-
raise CommandError, "No such directory: #{dest}"
|
16
|
-
end
|
17
|
-
else
|
18
|
-
pass_block(cmd)
|
19
|
-
|
20
|
-
if command_block
|
21
|
-
command_block.call `#{cmd}`
|
22
|
-
else
|
23
|
-
Pry.config.system.call(output, cmd, _pry_)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do
|
29
|
-
case _pry_.prompt
|
30
|
-
when Pry::SHELL_PROMPT
|
31
|
-
_pry_.pop_prompt
|
32
|
-
_pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS
|
33
|
-
else
|
34
|
-
_pry_.push_prompt Pry::SHELL_PROMPT
|
35
|
-
_pry_.custom_completions = Pry::FILE_COMPLETIONS
|
36
|
-
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target,
|
37
|
-
_pry_.instance_eval(&Pry::FILE_COMPLETIONS)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
alias_command "file-mode", "shell-mode"
|
41
|
-
|
42
|
-
create_command "save-file", "Export to a file using content from the REPL." do
|
43
|
-
banner <<-USAGE
|
44
|
-
Usage: save-file [OPTIONS] [FILE]
|
45
|
-
Save REPL content to a file.
|
46
|
-
e.g: save-file -m my_method -m my_method2 ./hello.rb
|
47
|
-
e.g: save-file -i 1..10 ./hello.rb --append
|
48
|
-
e.g: save-file -k show-method ./my_command.rb
|
49
|
-
e.g: save-file -f sample_file --lines 2..10 ./output_file.rb
|
50
|
-
USAGE
|
51
|
-
|
52
|
-
attr_accessor :content
|
53
|
-
attr_accessor :file_name
|
54
|
-
|
55
|
-
def setup
|
56
|
-
self.content = ""
|
57
|
-
end
|
58
|
-
|
59
|
-
def convert_to_range(n)
|
60
|
-
if !n.is_a?(Range)
|
61
|
-
(n..n)
|
62
|
-
else
|
63
|
-
n
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def options(opt)
|
68
|
-
opt.on :m, :method, "Save a method's source.", :argument => true do |meth_name|
|
69
|
-
meth = get_method_or_raise(meth_name, target, {})
|
70
|
-
self.content << meth.source
|
71
|
-
end
|
72
|
-
opt.on :c, :class, "Save a class's source.", :argument => true do |class_name|
|
73
|
-
mod = Pry::WrappedModule.from_str(class_name, target)
|
74
|
-
self.content << mod.source
|
75
|
-
end
|
76
|
-
opt.on :k, :command, "Save a command's source.", :argument => true do |command_name|
|
77
|
-
command = find_command(command_name)
|
78
|
-
block = Pry::Method.new(command.block)
|
79
|
-
self.content << block.source
|
80
|
-
end
|
81
|
-
opt.on :f, :file, "Save a file.", :argument => true do |file|
|
82
|
-
self.content << File.read(File.expand_path(file))
|
83
|
-
end
|
84
|
-
opt.on :l, :lines, "Only save a subset of lines.", :optional_argument => true, :as => Range, :default => 1..-1
|
85
|
-
opt.on :o, :out, "Save entries from Pry's output result history. Takes an index or range.", :optional_argument => true,
|
86
|
-
:as => Range, :default => -5..-1 do |range|
|
87
|
-
range = convert_to_range(range)
|
88
|
-
|
89
|
-
range.each do |v|
|
90
|
-
self.content << Pry.config.gist.inspecter.call(_pry_.output_array[v])
|
91
|
-
end
|
92
|
-
|
93
|
-
self.content << "\n"
|
94
|
-
end
|
95
|
-
opt.on :i, :in, "Save entries from Pry's input expression history. Takes an index or range.", :optional_argument => true,
|
96
|
-
:as => Range, :default => -5..-1 do |range|
|
97
|
-
input_expressions = _pry_.input_array[range] || []
|
98
|
-
Array(input_expressions).each { |v| self.content << v }
|
99
|
-
end
|
100
|
-
opt.on :a, :append, "Append to the given file instead of overwriting it."
|
101
|
-
end
|
102
|
-
|
103
|
-
def process
|
104
|
-
if args.empty?
|
105
|
-
raise CommandError, "Must specify a file name."
|
106
|
-
end
|
107
|
-
|
108
|
-
self.file_name = File.expand_path(args.first)
|
109
|
-
|
110
|
-
save_file
|
111
|
-
end
|
112
|
-
|
113
|
-
def save_file
|
114
|
-
if self.content.empty?
|
115
|
-
raise CommandError, "Found no code to save."
|
116
|
-
end
|
117
|
-
|
118
|
-
File.open(file_name, mode) do |f|
|
119
|
-
if opts.present?(:lines)
|
120
|
-
f.puts restrict_to_lines(content, opts[:l])
|
121
|
-
else
|
122
|
-
f.puts content
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def mode
|
128
|
-
if opts.present?(:append)
|
129
|
-
"a"
|
130
|
-
else
|
131
|
-
"w"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
create_command "cat", "Show code from a file, Pry's input buffer, or the last exception." do
|
137
|
-
banner <<-USAGE
|
138
|
-
Usage: cat FILE
|
139
|
-
cat --ex [STACK_INDEX]
|
140
|
-
cat --in [INPUT_INDEX_OR_RANGE]
|
141
|
-
|
142
|
-
cat is capable of showing part or all of a source file, the context of the
|
143
|
-
last exception, or an expression from Pry's input history.
|
144
|
-
|
145
|
-
cat --ex defaults to showing the lines surrounding the location of the last
|
146
|
-
exception. Invoking it more than once travels up the exception's backtrace,
|
147
|
-
and providing a number shows the context of the given index of the backtrace.
|
148
|
-
USAGE
|
149
|
-
|
150
|
-
def options(opt)
|
151
|
-
opt.on :ex, "Show the context of the last exception.", :optional_argument => true, :as => Integer
|
152
|
-
opt.on :i, :in, "Show one or more entries from Pry's expression history.", :optional_argument => true, :as => Range, :default => -5..-1
|
153
|
-
|
154
|
-
opt.on :s, :start, "Starting line (defaults to the first line).", :optional_argument => true, :as => Integer
|
155
|
-
opt.on :e, :end, "Ending line (defaults to the last line).", :optional_argument => true, :as => Integer
|
156
|
-
opt.on :l, :'line-numbers', "Show line numbers."
|
157
|
-
opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python').", :argument => true, :as => Symbol
|
158
|
-
|
159
|
-
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
160
|
-
end
|
161
|
-
|
162
|
-
def process
|
163
|
-
handler = case
|
164
|
-
when opts.present?(:ex)
|
165
|
-
method :process_ex
|
166
|
-
when opts.present?(:in)
|
167
|
-
method :process_in
|
168
|
-
else
|
169
|
-
method :process_file
|
170
|
-
end
|
171
|
-
|
172
|
-
output = handler.call do |code|
|
173
|
-
code.code_type = opts[:type] || :ruby
|
174
|
-
|
175
|
-
code.between(opts[:start] || 1, opts[:end] || -1).
|
176
|
-
with_line_numbers(opts.present?(:'line-numbers') || opts.present?(:ex))
|
177
|
-
end
|
178
|
-
|
179
|
-
render_output(output, opts)
|
180
|
-
end
|
181
|
-
|
182
|
-
def process_ex
|
183
|
-
window_size = Pry.config.default_window_size || 5
|
184
|
-
ex = _pry_.last_exception
|
185
|
-
|
186
|
-
raise CommandError, "No exception found." unless ex
|
187
|
-
|
188
|
-
if opts[:ex].nil?
|
189
|
-
bt_index = ex.bt_index
|
190
|
-
ex.inc_bt_index
|
191
|
-
else
|
192
|
-
bt_index = opts[:ex]
|
193
|
-
ex.bt_index = bt_index
|
194
|
-
ex.inc_bt_index
|
195
|
-
end
|
196
|
-
|
197
|
-
ex_file, ex_line = ex.bt_source_location_for(bt_index)
|
198
|
-
|
199
|
-
raise CommandError, "The given backtrace level is out of bounds." unless ex_file
|
200
|
-
|
201
|
-
if RbxPath.is_core_path?(ex_file)
|
202
|
-
ex_file = RbxPath.convert_path_to_full(ex_file)
|
203
|
-
end
|
204
|
-
|
205
|
-
set_file_and_dir_locals(ex_file)
|
206
|
-
|
207
|
-
start_line = ex_line - window_size
|
208
|
-
start_line = 1 if start_line < 1
|
209
|
-
end_line = ex_line + window_size
|
210
|
-
|
211
|
-
header = unindent <<-HEADER
|
212
|
-
#{text.bold 'Exception:'} #{ex.class}: #{ex.message}
|
213
|
-
--
|
214
|
-
#{text.bold('From:')} #{ex_file} @ line #{ex_line} @ #{text.bold("level: #{bt_index}")} of backtrace (of #{ex.backtrace.size - 1}).
|
215
|
-
|
216
|
-
HEADER
|
217
|
-
|
218
|
-
code = yield(Pry::Code.from_file(ex_file).
|
219
|
-
between(start_line, end_line).
|
220
|
-
with_marker(ex_line))
|
221
|
-
|
222
|
-
"#{header}#{code}"
|
223
|
-
end
|
224
|
-
|
225
|
-
def process_in
|
226
|
-
normalized_range = absolute_index_range(opts[:i], _pry_.input_array.length)
|
227
|
-
input_items = _pry_.input_array[normalized_range] || []
|
228
|
-
|
229
|
-
zipped_items = normalized_range.zip(input_items).reject { |_, s| s.nil? || s == "" }
|
230
|
-
|
231
|
-
unless zipped_items.length > 0
|
232
|
-
raise CommandError, "No expressions found."
|
233
|
-
end
|
234
|
-
|
235
|
-
if zipped_items.length > 1
|
236
|
-
contents = ""
|
237
|
-
zipped_items.each do |i, s|
|
238
|
-
contents << "#{text.bold(i.to_s)}:\n"
|
239
|
-
contents << yield(Pry::Code(s).with_indentation(2)).to_s
|
240
|
-
end
|
241
|
-
else
|
242
|
-
contents = yield(Pry::Code(zipped_items.first.last))
|
243
|
-
end
|
244
|
-
|
245
|
-
contents
|
246
|
-
end
|
247
|
-
|
248
|
-
def process_file
|
249
|
-
file_name = args.shift
|
250
|
-
|
251
|
-
unless file_name
|
252
|
-
raise CommandError, "Must provide a filename, --in, or --ex."
|
253
|
-
end
|
254
|
-
|
255
|
-
file_name, line_num = file_name.split(':')
|
256
|
-
file_name = File.expand_path(file_name)
|
257
|
-
set_file_and_dir_locals(file_name)
|
258
|
-
|
259
|
-
code = yield(Pry::Code.from_file(file_name))
|
260
|
-
|
261
|
-
code.code_type = opts[:type] || detect_code_type_from_file(file_name)
|
262
|
-
if line_num
|
263
|
-
code = code.around(line_num.to_i,
|
264
|
-
Pry.config.default_window_size || 7)
|
265
|
-
end
|
266
|
-
|
267
|
-
code
|
268
|
-
end
|
269
|
-
|
270
|
-
def detect_code_type_from_file(file_name)
|
271
|
-
name, ext = File.basename(file_name).split('.', 2)
|
272
|
-
|
273
|
-
if ext
|
274
|
-
case ext
|
275
|
-
when "py"
|
276
|
-
:python
|
277
|
-
when "rb", "gemspec", "rakefile", "ru"
|
278
|
-
:ruby
|
279
|
-
when "js"
|
280
|
-
return :javascript
|
281
|
-
when "yml", "prytheme"
|
282
|
-
:yaml
|
283
|
-
when "groovy"
|
284
|
-
:groovy
|
285
|
-
when "c"
|
286
|
-
:c
|
287
|
-
when "cpp"
|
288
|
-
:cpp
|
289
|
-
when "java"
|
290
|
-
:java
|
291
|
-
else
|
292
|
-
:text
|
293
|
-
end
|
294
|
-
else
|
295
|
-
case name
|
296
|
-
when "Rakefile", "Gemfile"
|
297
|
-
:ruby
|
298
|
-
else
|
299
|
-
:text
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
@@ -1,410 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
class Pry
|
4
|
-
module DefaultCommands
|
5
|
-
|
6
|
-
# For show-doc and show-source
|
7
|
-
module ModuleIntrospectionHelpers
|
8
|
-
attr_accessor :module_object
|
9
|
-
|
10
|
-
def module?(name)
|
11
|
-
self.module_object = Pry::WrappedModule.from_str(name, target)
|
12
|
-
end
|
13
|
-
|
14
|
-
def method?
|
15
|
-
!!method_object
|
16
|
-
rescue CommandError
|
17
|
-
false
|
18
|
-
end
|
19
|
-
|
20
|
-
def process(name)
|
21
|
-
if module?(name)
|
22
|
-
code_or_doc = process_module
|
23
|
-
elsif method?
|
24
|
-
code_or_doc = process_method
|
25
|
-
else
|
26
|
-
code_or_doc = process_alternatives
|
27
|
-
end
|
28
|
-
|
29
|
-
render_output(code_or_doc, opts)
|
30
|
-
end
|
31
|
-
|
32
|
-
def process_alternatives
|
33
|
-
if args.empty? && internal_binding?(target)
|
34
|
-
mod = target_self.is_a?(Module) ? target_self : target_self.class
|
35
|
-
self.module_object = Pry::WrappedModule(mod)
|
36
|
-
|
37
|
-
process_module
|
38
|
-
else
|
39
|
-
process_method
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def module_start_line(mod, candidate_rank=0)
|
44
|
-
if opts.present?(:'base-one')
|
45
|
-
1
|
46
|
-
else
|
47
|
-
mod.candidate(candidate_rank).line
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def use_line_numbers?
|
52
|
-
opts.present?(:b) || opts.present?(:l)
|
53
|
-
end
|
54
|
-
|
55
|
-
def attempt
|
56
|
-
rank = 0
|
57
|
-
begin
|
58
|
-
yield(rank)
|
59
|
-
rescue Pry::CommandError
|
60
|
-
raise if rank > (module_object.number_of_candidates - 1)
|
61
|
-
rank += 1
|
62
|
-
retry
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
Introspection = Pry::CommandSet.new do
|
68
|
-
|
69
|
-
create_command "show-doc", "Show the documentation for a method or class. Aliases: \?", :shellwords => false do
|
70
|
-
include ModuleIntrospectionHelpers
|
71
|
-
include Helpers::DocumentationHelpers
|
72
|
-
extend Helpers::BaseHelpers
|
73
|
-
|
74
|
-
banner <<-BANNER
|
75
|
-
Usage: show-doc [OPTIONS] [METH]
|
76
|
-
Aliases: ?
|
77
|
-
|
78
|
-
Show the documentation for a method or class. Tries instance methods first and then methods by default.
|
79
|
-
e.g show-doc hello_method # docs for hello_method
|
80
|
-
e.g show-doc Pry # docs for Pry class
|
81
|
-
e.g show-doc Pry -a # docs for all definitions of Pry class (all monkey patches)
|
82
|
-
BANNER
|
83
|
-
|
84
|
-
options :requires_gem => "ruby18_source_location" if mri_18?
|
85
|
-
|
86
|
-
def setup
|
87
|
-
require 'ruby18_source_location' if mri_18?
|
88
|
-
end
|
89
|
-
|
90
|
-
def options(opt)
|
91
|
-
method_options(opt)
|
92
|
-
opt.on :l, "line-numbers", "Show line numbers."
|
93
|
-
opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)."
|
94
|
-
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
95
|
-
opt.on :a, :all, "Show docs for all definitions and monkeypatches of the module/class"
|
96
|
-
end
|
97
|
-
|
98
|
-
def process_module
|
99
|
-
if opts.present?(:all)
|
100
|
-
all_modules
|
101
|
-
else
|
102
|
-
normal_module
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def normal_module
|
107
|
-
doc = ""
|
108
|
-
if module_object.yard_docs?
|
109
|
-
file_name, line = module_object.yard_file, module_object.yard_line
|
110
|
-
doc << module_object.yard_doc
|
111
|
-
start_line = 1
|
112
|
-
else
|
113
|
-
attempt do |rank|
|
114
|
-
file_name, line = module_object.candidate(rank).source_location
|
115
|
-
set_file_and_dir_locals(file_name)
|
116
|
-
doc << module_object.candidate(rank).doc
|
117
|
-
start_line = module_start_line(module_object, rank)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
doc = Code.new(doc, start_line, :text).
|
122
|
-
with_line_numbers(use_line_numbers?).to_s
|
123
|
-
|
124
|
-
doc.insert(0, "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line ? line : "N/A"}:\n\n")
|
125
|
-
end
|
126
|
-
|
127
|
-
def all_modules
|
128
|
-
doc = ""
|
129
|
-
doc << "Found #{module_object.number_of_candidates} candidates for `#{module_object.name}` definition:\n"
|
130
|
-
module_object.number_of_candidates.times do |v|
|
131
|
-
candidate = module_object.candidate(v)
|
132
|
-
begin
|
133
|
-
doc << "\nCandidate #{v+1}/#{module_object.number_of_candidates}: #{candidate.file} @ #{candidate.line}:\n\n"
|
134
|
-
doc << candidate.doc
|
135
|
-
rescue Pry::RescuableException
|
136
|
-
doc << "No documentation found.\n"
|
137
|
-
next
|
138
|
-
end
|
139
|
-
end
|
140
|
-
doc
|
141
|
-
end
|
142
|
-
|
143
|
-
def process_method
|
144
|
-
raise Pry::CommandError, "No documentation found." if method_object.doc.nil? || method_object.doc.empty?
|
145
|
-
|
146
|
-
doc = process_comment_markup(method_object.doc, method_object.source_type)
|
147
|
-
output.puts make_header(method_object, doc)
|
148
|
-
output.puts "#{text.bold("Owner:")} #{method_object.owner || "N/A"}"
|
149
|
-
output.puts "#{text.bold("Visibility:")} #{method_object.visibility}"
|
150
|
-
output.puts "#{text.bold("Signature:")} #{method_object.signature}"
|
151
|
-
output.puts
|
152
|
-
|
153
|
-
if use_line_numbers?
|
154
|
-
doc = Code.new(doc, start_line, :text).
|
155
|
-
with_line_numbers(true).to_s
|
156
|
-
end
|
157
|
-
|
158
|
-
doc
|
159
|
-
end
|
160
|
-
|
161
|
-
def module_start_line(mod, candidate=0)
|
162
|
-
if opts.present?(:'base-one')
|
163
|
-
1
|
164
|
-
else
|
165
|
-
if mod.candidate(candidate).line
|
166
|
-
mod.candidate(candidate).line - mod.candidate(candidate).doc.lines.count
|
167
|
-
else
|
168
|
-
1
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def start_line
|
174
|
-
if opts.present?(:'base-one')
|
175
|
-
1
|
176
|
-
else
|
177
|
-
(method_object.source_line - method_object.doc.lines.count) || 1
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
alias_command "?", "show-doc"
|
183
|
-
|
184
|
-
create_command "stat", "View method information and set _file_ and _dir_ locals.", :shellwords => false do
|
185
|
-
banner <<-BANNER
|
186
|
-
Usage: stat [OPTIONS] [METH]
|
187
|
-
Show method information for method METH and set _file_ and _dir_ locals.
|
188
|
-
e.g: stat hello_method
|
189
|
-
BANNER
|
190
|
-
|
191
|
-
def options(opt)
|
192
|
-
method_options(opt)
|
193
|
-
end
|
194
|
-
|
195
|
-
def process
|
196
|
-
meth = method_object
|
197
|
-
output.puts unindent <<-EOS
|
198
|
-
Method Information:
|
199
|
-
--
|
200
|
-
Name: #{meth.name}
|
201
|
-
Owner: #{meth.owner ? meth.owner : "Unknown"}
|
202
|
-
Visibility: #{meth.visibility}
|
203
|
-
Type: #{meth.is_a?(::Method) ? "Bound" : "Unbound"}
|
204
|
-
Arity: #{meth.arity}
|
205
|
-
Method Signature: #{meth.signature}
|
206
|
-
Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
|
207
|
-
EOS
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
create_command "show-source" do
|
212
|
-
include ModuleIntrospectionHelpers
|
213
|
-
extend Helpers::BaseHelpers
|
214
|
-
|
215
|
-
description "Show the source for a method or class. Aliases: $, show-method"
|
216
|
-
|
217
|
-
banner <<-BANNER
|
218
|
-
Usage: show-source [OPTIONS] [METH|CLASS]
|
219
|
-
Aliases: $, show-method
|
220
|
-
|
221
|
-
Show the source for a method or class. Tries instance methods first and then methods by default.
|
222
|
-
|
223
|
-
e.g: `show-source hello_method`
|
224
|
-
e.g: `show-source -m hello_method`
|
225
|
-
e.g: `show-source Pry#rep` # source for Pry#rep method
|
226
|
-
e.g: `show-source Pry` # source for Pry class
|
227
|
-
e.g: `show-source Pry -a` # source for all Pry class definitions (all monkey patches)
|
228
|
-
|
229
|
-
https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
|
230
|
-
BANNER
|
231
|
-
|
232
|
-
options :shellwords => false
|
233
|
-
options :requires_gem => "ruby18_source_location" if mri_18?
|
234
|
-
|
235
|
-
def setup
|
236
|
-
require 'ruby18_source_location' if mri_18?
|
237
|
-
end
|
238
|
-
|
239
|
-
def options(opt)
|
240
|
-
method_options(opt)
|
241
|
-
opt.on :l, "line-numbers", "Show line numbers."
|
242
|
-
opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)."
|
243
|
-
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
244
|
-
opt.on :a, :all, "Show source for all definitions and monkeypatches of the module/class"
|
245
|
-
end
|
246
|
-
|
247
|
-
def process_method
|
248
|
-
raise CommandError, "Could not find method source" unless method_object.source
|
249
|
-
|
250
|
-
code = ""
|
251
|
-
code << make_header(method_object)
|
252
|
-
code << "#{text.bold("Owner:")} #{method_object.owner || "N/A"}\n"
|
253
|
-
code << "#{text.bold("Visibility:")} #{method_object.visibility}\n"
|
254
|
-
code << "\n"
|
255
|
-
|
256
|
-
code << Code.from_method(method_object, start_line).
|
257
|
-
with_line_numbers(use_line_numbers?).to_s
|
258
|
-
end
|
259
|
-
|
260
|
-
def process_module
|
261
|
-
if opts.present?(:all)
|
262
|
-
all_modules
|
263
|
-
else
|
264
|
-
normal_module
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
def normal_module
|
269
|
-
file_name = line = code = nil
|
270
|
-
attempt do |rank|
|
271
|
-
file_name, line = module_object.candidate(rank).source_location
|
272
|
-
set_file_and_dir_locals(file_name)
|
273
|
-
code = Code.from_module(module_object, module_start_line(module_object, rank), rank).
|
274
|
-
with_line_numbers(use_line_numbers?).to_s
|
275
|
-
end
|
276
|
-
|
277
|
-
result = ""
|
278
|
-
result << "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n"
|
279
|
-
result << "#{Pry::Helpers::Text.bold('Number of lines:')} #{code.lines.count}\n\n"
|
280
|
-
result << code
|
281
|
-
end
|
282
|
-
|
283
|
-
def all_modules
|
284
|
-
mod = module_object
|
285
|
-
|
286
|
-
result = ""
|
287
|
-
result << "Found #{mod.number_of_candidates} candidates for `#{mod.name}` definition:\n"
|
288
|
-
mod.number_of_candidates.times do |v|
|
289
|
-
candidate = mod.candidate(v)
|
290
|
-
begin
|
291
|
-
result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{candidate.file} @ line #{candidate.line}:\n"
|
292
|
-
code = Code.from_module(mod, module_start_line(mod, v), v).
|
293
|
-
with_line_numbers(use_line_numbers?).to_s
|
294
|
-
result << "Number of lines: #{code.lines.count}\n\n"
|
295
|
-
result << code
|
296
|
-
rescue Pry::RescuableException
|
297
|
-
result << "\nNo code found.\n"
|
298
|
-
next
|
299
|
-
end
|
300
|
-
end
|
301
|
-
result
|
302
|
-
end
|
303
|
-
|
304
|
-
def use_line_numbers?
|
305
|
-
opts.present?(:b) || opts.present?(:l)
|
306
|
-
end
|
307
|
-
|
308
|
-
def start_line
|
309
|
-
if opts.present?(:'base-one')
|
310
|
-
1
|
311
|
-
else
|
312
|
-
method_object.source_line || 1
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
alias_command "show-method", "show-source"
|
318
|
-
alias_command "$", "show-source"
|
319
|
-
|
320
|
-
command "show-command", "Show the source for CMD." do |*args|
|
321
|
-
target = target()
|
322
|
-
|
323
|
-
opts = Slop.parse!(args) do |opt|
|
324
|
-
opt.banner unindent <<-USAGE
|
325
|
-
Usage: show-command [OPTIONS] [CMD]
|
326
|
-
Show the source for command CMD.
|
327
|
-
e.g: show-command show-method
|
328
|
-
USAGE
|
329
|
-
|
330
|
-
opt.on :l, "line-numbers", "Show line numbers."
|
331
|
-
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
332
|
-
opt.on :h, :help, "This message." do
|
333
|
-
output.puts opt.help
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
next if opts.present?(:help)
|
338
|
-
|
339
|
-
command_name = args.shift
|
340
|
-
if !command_name
|
341
|
-
raise CommandError, "You must provide a command name."
|
342
|
-
end
|
343
|
-
|
344
|
-
if find_command(command_name)
|
345
|
-
block = Pry::Method.new(find_command(command_name).block)
|
346
|
-
|
347
|
-
next unless block.source
|
348
|
-
set_file_and_dir_locals(block.source_file)
|
349
|
-
|
350
|
-
output.puts make_header(block)
|
351
|
-
output.puts
|
352
|
-
|
353
|
-
code = Code.from_method(block).with_line_numbers(opts.present?(:'line-numbers')).to_s
|
354
|
-
|
355
|
-
render_output(code, opts)
|
356
|
-
else
|
357
|
-
raise CommandError, "No such command: #{command_name}."
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
create_command "ri", "View ri documentation. e.g `ri Array#each`" do
|
362
|
-
banner <<-BANNER
|
363
|
-
Usage: ri [spec]
|
364
|
-
e.g. ri Array#each
|
365
|
-
|
366
|
-
Relies on the rdoc gem being installed. See also: show-doc.
|
367
|
-
BANNER
|
368
|
-
|
369
|
-
def process(spec)
|
370
|
-
# Lazily load RI
|
371
|
-
require 'rdoc/ri/driver'
|
372
|
-
|
373
|
-
unless defined? RDoc::RI::PryDriver
|
374
|
-
|
375
|
-
# Subclass RI so that it formats its output nicely, and uses `lesspipe`.
|
376
|
-
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
377
|
-
|
378
|
-
subclass.class_eval do
|
379
|
-
def page
|
380
|
-
Pry::Helpers::BaseHelpers.lesspipe {|less| yield less}
|
381
|
-
end
|
382
|
-
|
383
|
-
def formatter(io)
|
384
|
-
if @formatter_klass then
|
385
|
-
@formatter_klass.new
|
386
|
-
else
|
387
|
-
RDoc::Markup::ToAnsi.new
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
RDoc::RI.const_set :PryDriver, subclass # hook it up!
|
393
|
-
end
|
394
|
-
|
395
|
-
# Spin-up an RI insance.
|
396
|
-
ri = RDoc::RI::PryDriver.new :use_stdout => true, :interactive => false
|
397
|
-
|
398
|
-
begin
|
399
|
-
ri.display_names [spec] # Get the documentation (finally!)
|
400
|
-
rescue RDoc::RI::Driver::NotFoundError => e
|
401
|
-
output.puts "error: '#{e.name}' not found"
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
end
|
406
|
-
|
407
|
-
end
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|