pry 0.9.12.6 → 0.10.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +37 -31
- data/lib/pry.rb +38 -151
- data/lib/pry/cli.rb +35 -17
- data/lib/pry/code.rb +24 -63
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +2 -1
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +40 -21
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +12 -9
- data/lib/pry/command_set.rb +81 -38
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +2 -2
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +11 -2
- data/lib/pry/commands/cat/exception_formatter.rb +5 -6
- data/lib/pry/commands/cat/file_formatter.rb +15 -32
- data/lib/pry/commands/cd.rb +14 -3
- 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 +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +10 -22
- data/lib/pry/commands/edit/exception_patcher.rb +2 -2
- data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
- data/lib/pry/commands/exit_program.rb +0 -1
- data/lib/pry/commands/find_method.rb +16 -22
- data/lib/pry/commands/gem_install.rb +5 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +10 -11
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +27 -8
- data/lib/pry/commands/install_command.rb +14 -12
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +72 -296
- 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/play.rb +44 -10
- data/lib/pry/commands/pry_backtrace.rb +1 -2
- data/lib/pry/commands/raise_up.rb +2 -2
- data/lib/pry/commands/reload_code.rb +16 -19
- data/lib/pry/commands/ri.rb +7 -3
- data/lib/pry/commands/shell_command.rb +18 -13
- data/lib/pry/commands/shell_mode.rb +2 -4
- data/lib/pry/commands/show_doc.rb +5 -0
- data/lib/pry/commands/show_info.rb +8 -13
- data/lib/pry/commands/show_source.rb +15 -3
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +8 -4
- 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 +18 -10
- data/lib/pry/commands/wtf.rb +3 -3
- data/lib/pry/config.rb +20 -254
- 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 +31 -21
- data/lib/pry/editor.rb +107 -103
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers/base_helpers.rb +22 -109
- data/lib/pry/helpers/command_helpers.rb +10 -8
- data/lib/pry/helpers/documentation_helpers.rb +1 -2
- data/lib/pry/helpers/text.rb +4 -5
- data/lib/pry/history.rb +46 -45
- data/lib/pry/history_array.rb +6 -1
- data/lib/pry/hooks.rb +9 -29
- data/lib/pry/indent.rb +6 -6
- 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 +82 -87
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
- data/lib/pry/module_candidate.rb +4 -14
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +191 -47
- data/lib/pry/plugins.rb +1 -1
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +149 -230
- data/lib/pry/pry_instance.rb +302 -413
- 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 +13 -5
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/test/helper.rb +26 -41
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +45 -59
- metadata +61 -224
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -25
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -12
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/completion.rb +0 -321
- data/lib/pry/custom_completions.rb +0 -6
- 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 -29
- data/spec/Procfile +0 -3
- data/spec/cli_spec.rb +0 -78
- data/spec/code_object_spec.rb +0 -277
- data/spec/code_spec.rb +0 -219
- data/spec/command_helpers_spec.rb +0 -29
- data/spec/command_integration_spec.rb +0 -644
- data/spec/command_set_spec.rb +0 -627
- data/spec/command_spec.rb +0 -821
- data/spec/commands/amend_line_spec.rb +0 -247
- data/spec/commands/bang_spec.rb +0 -19
- data/spec/commands/cat_spec.rb +0 -164
- data/spec/commands/cd_spec.rb +0 -250
- data/spec/commands/disable_pry_spec.rb +0 -25
- data/spec/commands/edit_spec.rb +0 -727
- data/spec/commands/exit_all_spec.rb +0 -34
- data/spec/commands/exit_program_spec.rb +0 -19
- data/spec/commands/exit_spec.rb +0 -34
- data/spec/commands/find_method_spec.rb +0 -70
- data/spec/commands/gem_list_spec.rb +0 -26
- data/spec/commands/gist_spec.rb +0 -79
- data/spec/commands/help_spec.rb +0 -56
- data/spec/commands/hist_spec.rb +0 -181
- data/spec/commands/jump_to_spec.rb +0 -15
- data/spec/commands/ls_spec.rb +0 -181
- data/spec/commands/play_spec.rb +0 -140
- data/spec/commands/raise_up_spec.rb +0 -56
- data/spec/commands/save_file_spec.rb +0 -177
- data/spec/commands/show_doc_spec.rb +0 -510
- data/spec/commands/show_input_spec.rb +0 -17
- data/spec/commands/show_source_spec.rb +0 -782
- data/spec/commands/whereami_spec.rb +0 -203
- data/spec/completion_spec.rb +0 -241
- data/spec/control_d_handler_spec.rb +0 -58
- data/spec/documentation_helper_spec.rb +0 -73
- data/spec/editor_spec.rb +0 -79
- data/spec/exception_whitelist_spec.rb +0 -21
- data/spec/fixtures/candidate_helper1.rb +0 -11
- data/spec/fixtures/candidate_helper2.rb +0 -8
- data/spec/fixtures/example.erb +0 -5
- data/spec/fixtures/example_nesting.rb +0 -33
- data/spec/fixtures/show_source_doc_examples.rb +0 -15
- data/spec/fixtures/testrc +0 -2
- data/spec/fixtures/testrcbad +0 -2
- data/spec/fixtures/whereami_helper.rb +0 -6
- data/spec/helper.rb +0 -34
- data/spec/helpers/bacon.rb +0 -86
- data/spec/helpers/mock_pry.rb +0 -43
- data/spec/helpers/table_spec.rb +0 -105
- data/spec/history_array_spec.rb +0 -67
- data/spec/hooks_spec.rb +0 -522
- data/spec/indent_spec.rb +0 -301
- data/spec/input_stack_spec.rb +0 -90
- data/spec/method_spec.rb +0 -482
- data/spec/prompt_spec.rb +0 -60
- data/spec/pry_defaults_spec.rb +0 -419
- data/spec/pry_history_spec.rb +0 -99
- data/spec/pry_output_spec.rb +0 -95
- data/spec/pry_spec.rb +0 -515
- data/spec/run_command_spec.rb +0 -25
- data/spec/sticky_locals_spec.rb +0 -157
- data/spec/syntax_checking_spec.rb +0 -81
- data/spec/wrapped_module_spec.rb +0 -261
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -0,0 +1,55 @@
|
|
1
|
+
# PP subclass for streaming inspect output in color.
|
2
|
+
class Pry
|
3
|
+
class ColorPrinter < ::PP
|
4
|
+
OBJ_COLOR = begin
|
5
|
+
code = CodeRay::Encoders::Terminal::TOKEN_COLORS[:keyword]
|
6
|
+
if code.start_with? "\e"
|
7
|
+
code
|
8
|
+
else
|
9
|
+
"\e[0m\e[0;#{code}m"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
CodeRay::Encoders::Terminal::TOKEN_COLORS[:comment][:self] = "\e[1;34m"
|
14
|
+
|
15
|
+
def self.pp(obj, out = $>, width = 79)
|
16
|
+
q = ColorPrinter.new(out, width)
|
17
|
+
q.guard_inspect_key { q.pp obj }
|
18
|
+
q.flush
|
19
|
+
out << "\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
def text(str, width = str.length)
|
23
|
+
# Don't recolorize output with color [Issue #751]
|
24
|
+
if str.include?("\e[")
|
25
|
+
super "#{str}\e[0m", width
|
26
|
+
elsif str.start_with?('#<') || str == '=' || str == '>'
|
27
|
+
super highlight_object_literal(str), width
|
28
|
+
else
|
29
|
+
super CodeRay.scan(str, :ruby).term, width
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def pp(obj)
|
34
|
+
super
|
35
|
+
rescue => e
|
36
|
+
raise if e.is_a? Pry::Pager::StopPaging
|
37
|
+
|
38
|
+
# Read the class name off of the singleton class to provide a default
|
39
|
+
# inspect.
|
40
|
+
singleton = class << obj; self; end
|
41
|
+
ancestors = Pry::Method.safe_send(singleton, :ancestors)
|
42
|
+
klass = ancestors.reject { |k| k == singleton }.first
|
43
|
+
obj_id = obj.__id__.to_s(16) rescue 0
|
44
|
+
str = "#<#{klass}:0x#{obj_id}>"
|
45
|
+
|
46
|
+
text highlight_object_literal(str)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def highlight_object_literal(object_literal)
|
52
|
+
"#{OBJ_COLOR}#{object_literal}\e[0m"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/pry/command.rb
CHANGED
@@ -30,13 +30,13 @@ class Pry
|
|
30
30
|
@command_options[:listing] = arg.is_a?(String) ? arg : arg.inspect
|
31
31
|
@match = arg
|
32
32
|
end
|
33
|
-
@match
|
33
|
+
@match ||= nil
|
34
34
|
end
|
35
35
|
|
36
36
|
# Define or get the command's description
|
37
37
|
def description(arg=nil)
|
38
38
|
@description = arg if arg
|
39
|
-
@description
|
39
|
+
@description ||= nil
|
40
40
|
end
|
41
41
|
|
42
42
|
# Define or get the command's options
|
@@ -175,7 +175,7 @@ class Pry
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def command_regex
|
178
|
-
pr =
|
178
|
+
pr = Pry.respond_to?(:config) ? Pry.config.command_prefix : ""
|
179
179
|
prefix = convert_to_regex(pr)
|
180
180
|
prefix = "(?:#{prefix})?" unless options[:use_prefix]
|
181
181
|
|
@@ -194,6 +194,7 @@ class Pry
|
|
194
194
|
# The group in which the command should be displayed in "help" output.
|
195
195
|
# This is usually auto-generated from directory naming, but it can be
|
196
196
|
# manually overridden if necessary.
|
197
|
+
# Group should not be changed once it is initialized.
|
197
198
|
def group(name=nil)
|
198
199
|
@group ||= if name
|
199
200
|
name
|
@@ -201,7 +202,7 @@ class Pry
|
|
201
202
|
case Pry::Method(block).source_file
|
202
203
|
when %r{/pry/.*_commands/(.*).rb}
|
203
204
|
$1.capitalize.gsub(/_/, " ")
|
204
|
-
when %r{(pry-\w+)-([\d\.]+([\w
|
205
|
+
when %r{(pry-\w+)-([\d\.]+([\w\.]+)?)}
|
205
206
|
name, version = $1, $2
|
206
207
|
"#{name.to_s} (v#{version.to_s})"
|
207
208
|
when /pryrc/
|
@@ -242,12 +243,13 @@ class Pry
|
|
242
243
|
# @example
|
243
244
|
# run "amend-line", "5", 'puts "hello world"'
|
244
245
|
def run(command_string, *args)
|
246
|
+
command_string = _pry_.config.command_prefix.to_s + command_string
|
245
247
|
complete_string = "#{command_string} #{args.join(" ")}".rstrip
|
246
248
|
command_set.process_line(complete_string, context)
|
247
249
|
end
|
248
250
|
|
249
251
|
def commands
|
250
|
-
command_set.
|
252
|
+
command_set.to_hash
|
251
253
|
end
|
252
254
|
|
253
255
|
def text
|
@@ -283,7 +285,7 @@ class Pry
|
|
283
285
|
# state.my_state = "my state" # this will not conflict with any
|
284
286
|
# # `state.my_state` used in another command.
|
285
287
|
def state
|
286
|
-
_pry_.command_state[match] ||=
|
288
|
+
_pry_.command_state[match] ||= Pry::Config.from_hash({})
|
287
289
|
end
|
288
290
|
|
289
291
|
# Revaluate the string (str) and perform interpolation.
|
@@ -307,8 +309,7 @@ class Pry
|
|
307
309
|
collision_type ||= 'local-variable' if arg_string.match(%r{\A\s*[-+*/%&|^]*=})
|
308
310
|
|
309
311
|
if collision_type
|
310
|
-
output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}',"
|
311
|
-
"which conflicts with a #{collision_type}.\n\n"
|
312
|
+
output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}', which conflicts with a #{collision_type}.\n\n"
|
312
313
|
end
|
313
314
|
rescue Pry::RescuableException
|
314
315
|
end
|
@@ -438,7 +439,9 @@ class Pry
|
|
438
439
|
#
|
439
440
|
# @param [String] search The line typed so far
|
440
441
|
# @return [Array<String>] Completion words
|
441
|
-
def complete(search)
|
442
|
+
def complete(search)
|
443
|
+
[]
|
444
|
+
end
|
442
445
|
|
443
446
|
private
|
444
447
|
|
data/lib/pry/command_set.rb
CHANGED
@@ -10,19 +10,15 @@ class Pry
|
|
10
10
|
class CommandSet
|
11
11
|
include Enumerable
|
12
12
|
include Pry::Helpers::BaseHelpers
|
13
|
-
|
14
|
-
attr_reader :commands
|
15
13
|
attr_reader :helper_module
|
16
14
|
|
17
|
-
# @param [Array<
|
18
|
-
# automatically
|
15
|
+
# @param [Array<Commandset>] imported_sets
|
16
|
+
# Sets which will be imported automatically
|
19
17
|
# @yield Optional block run to define commands
|
20
18
|
def initialize(*imported_sets, &block)
|
21
19
|
@commands = {}
|
22
20
|
@helper_module = Module.new
|
23
|
-
|
24
21
|
import(*imported_sets)
|
25
|
-
|
26
22
|
instance_eval(&block) if block
|
27
23
|
end
|
28
24
|
|
@@ -83,7 +79,7 @@ class Pry
|
|
83
79
|
description, options = ["No description.", description] if description.is_a?(Hash)
|
84
80
|
options = Pry::Command.default_options(match).merge!(options)
|
85
81
|
|
86
|
-
commands[match] = Pry::BlockCommand.subclass(match, description, options, helper_module, &block)
|
82
|
+
@commands[match] = Pry::BlockCommand.subclass(match, description, options, helper_module, &block)
|
87
83
|
end
|
88
84
|
alias_method :command, :block_command
|
89
85
|
|
@@ -115,9 +111,9 @@ class Pry
|
|
115
111
|
description, options = ["No description.", description] if description.is_a?(Hash)
|
116
112
|
options = Pry::Command.default_options(match).merge!(options)
|
117
113
|
|
118
|
-
commands[match] = Pry::ClassCommand.subclass(match, description, options, helper_module, &block)
|
119
|
-
commands[match].class_eval(&block)
|
120
|
-
commands[match]
|
114
|
+
@commands[match] = Pry::ClassCommand.subclass(match, description, options, helper_module, &block)
|
115
|
+
@commands[match].class_eval(&block)
|
116
|
+
@commands[match]
|
121
117
|
end
|
122
118
|
|
123
119
|
# Execute a block of code before a command is invoked. The block also
|
@@ -126,7 +122,7 @@ class Pry
|
|
126
122
|
# @param [String, Regexp] search The match or listing of the command.
|
127
123
|
# @yield The block to be run before the command.
|
128
124
|
# @example Display parameter before invoking command
|
129
|
-
# Pry.commands.before_command("whereami") do |n|
|
125
|
+
# Pry.config.commands.before_command("whereami") do |n|
|
130
126
|
# output.puts "parameter passed was #{n}"
|
131
127
|
# end
|
132
128
|
def before_command(search, &block)
|
@@ -140,7 +136,7 @@ class Pry
|
|
140
136
|
# @param [String, Regexp] search The match or listing of the command.
|
141
137
|
# @yield The block to be run after the command.
|
142
138
|
# @example Display text 'command complete' after invoking command
|
143
|
-
# Pry.commands.after_command("whereami") do |n|
|
139
|
+
# Pry.config.commands.after_command("whereami") do |n|
|
144
140
|
# output.puts "command complete!"
|
145
141
|
# end
|
146
142
|
def after_command(search, &block)
|
@@ -152,18 +148,12 @@ class Pry
|
|
152
148
|
@commands.each(&block)
|
153
149
|
end
|
154
150
|
|
155
|
-
# Add a given command object to this set.
|
156
|
-
# @param [Command] command The subclass of Pry::Command you wish to add.
|
157
|
-
def add_command(command)
|
158
|
-
commands[command.match] = command
|
159
|
-
end
|
160
|
-
|
161
151
|
# Removes some commands from the set
|
162
152
|
# @param [Array<String>] searches the matches or listings of the commands to remove
|
163
153
|
def delete(*searches)
|
164
154
|
searches.each do |search|
|
165
155
|
cmd = find_command_by_match_or_listing(search)
|
166
|
-
commands.delete cmd.match
|
156
|
+
@commands.delete cmd.match
|
167
157
|
end
|
168
158
|
end
|
169
159
|
|
@@ -173,7 +163,7 @@ class Pry
|
|
173
163
|
# @return [Pry::CommandSet] Returns the reciever (a command set).
|
174
164
|
def import(*sets)
|
175
165
|
sets.each do |set|
|
176
|
-
commands.merge! set.
|
166
|
+
@commands.merge! set.to_hash
|
177
167
|
helper_module.send :include, set.helper_module
|
178
168
|
end
|
179
169
|
self
|
@@ -187,7 +177,7 @@ class Pry
|
|
187
177
|
helper_module.send :include, set.helper_module
|
188
178
|
matches.each do |match|
|
189
179
|
cmd = set.find_command_by_match_or_listing(match)
|
190
|
-
commands[cmd.match] = cmd
|
180
|
+
@commands[cmd.match] = cmd
|
191
181
|
end
|
192
182
|
self
|
193
183
|
end
|
@@ -196,8 +186,8 @@ class Pry
|
|
196
186
|
# of the command to retrieve.
|
197
187
|
# @return [Command] The command object matched.
|
198
188
|
def find_command_by_match_or_listing(match_or_listing)
|
199
|
-
cmd = (commands[match_or_listing] ||
|
200
|
-
Pry::Helpers::BaseHelpers.find_command(match_or_listing, commands))
|
189
|
+
cmd = (@commands[match_or_listing] ||
|
190
|
+
Pry::Helpers::BaseHelpers.find_command(match_or_listing, @commands))
|
201
191
|
cmd or raise ArgumentError, "Cannot find a command: '#{match_or_listing}'!"
|
202
192
|
end
|
203
193
|
|
@@ -256,11 +246,11 @@ class Pry
|
|
256
246
|
:description => cmd.description
|
257
247
|
}.merge!(options)
|
258
248
|
|
259
|
-
commands[new_match] = cmd.dup
|
260
|
-
commands[new_match].match = new_match
|
261
|
-
commands[new_match].description = options.delete(:description)
|
262
|
-
commands[new_match].options.merge!(options)
|
263
|
-
commands.delete(cmd.match)
|
249
|
+
@commands[new_match] = cmd.dup
|
250
|
+
@commands[new_match].match = new_match
|
251
|
+
@commands[new_match].description = options.delete(:description)
|
252
|
+
@commands[new_match].options.merge!(options)
|
253
|
+
@commands.delete(cmd.match)
|
264
254
|
end
|
265
255
|
|
266
256
|
def disabled_command(name_of_disabled_command, message, matcher=name_of_disabled_command)
|
@@ -309,18 +299,71 @@ class Pry
|
|
309
299
|
end
|
310
300
|
|
311
301
|
|
312
|
-
# @return [Array]
|
302
|
+
# @return [Array]
|
303
|
+
# The list of commands provided by the command set.
|
313
304
|
def list_commands
|
314
|
-
commands.keys
|
305
|
+
@commands.keys
|
306
|
+
end
|
307
|
+
alias_method :keys, :list_commands
|
308
|
+
|
309
|
+
def to_hash
|
310
|
+
@commands.dup
|
315
311
|
end
|
312
|
+
alias_method :to_h, :to_hash
|
316
313
|
|
317
314
|
# Find a command that matches the given line
|
318
|
-
# @param [String]
|
315
|
+
# @param [String] pattern The line that might be a command invocation
|
319
316
|
# @return [Pry::Command, nil]
|
320
|
-
def
|
321
|
-
commands.values.select
|
317
|
+
def [](pattern)
|
318
|
+
@commands.values.select do |command|
|
319
|
+
command.matches?(pattern)
|
320
|
+
end.sort_by do |command|
|
321
|
+
command.match_score(pattern)
|
322
|
+
end.last
|
323
|
+
end
|
324
|
+
alias_method :find_command, :[]
|
325
|
+
|
326
|
+
#
|
327
|
+
# Re-assign the command found at _pattern_ with _command_.
|
328
|
+
#
|
329
|
+
# @param [Regexp, String] pattern
|
330
|
+
# The command to add or replace(found at _pattern_).
|
331
|
+
#
|
332
|
+
# @param [Pry::Command] command
|
333
|
+
# The command to add.
|
334
|
+
#
|
335
|
+
# @return [Pry::Command]
|
336
|
+
# Returns the new command (matched with "pattern".)
|
337
|
+
#
|
338
|
+
# @example
|
339
|
+
# Pry.config.commands["help"] = MyHelpCommand
|
340
|
+
#
|
341
|
+
def []=(pattern, command)
|
342
|
+
if command.equal?(nil)
|
343
|
+
return @commands.delete(pattern)
|
344
|
+
end
|
345
|
+
unless Class === command && command < Pry::Command
|
346
|
+
raise TypeError, "command is not a subclass of Pry::Command"
|
347
|
+
end
|
348
|
+
bind_command_to_pattern = pattern != command.match
|
349
|
+
if bind_command_to_pattern
|
350
|
+
command_copy = command.dup
|
351
|
+
command_copy.match = pattern
|
352
|
+
@commands[pattern] = command_copy
|
353
|
+
else
|
354
|
+
@commands[pattern] = command
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
#
|
359
|
+
# Add a command to set.
|
360
|
+
#
|
361
|
+
# @param [Command] command
|
362
|
+
# a subclass of Pry::Command.
|
363
|
+
#
|
364
|
+
def add_command(command)
|
365
|
+
self[command.match] = command
|
322
366
|
end
|
323
|
-
alias_method :[], :find_command
|
324
367
|
|
325
368
|
# Find the command that the user might be trying to refer to.
|
326
369
|
# @param [String] search The user's search.
|
@@ -356,7 +399,7 @@ class Pry
|
|
356
399
|
|
357
400
|
# @private (used for testing)
|
358
401
|
def run_command(context, match, *args)
|
359
|
-
command = commands[match] or raise NoCommandError.new(match, self)
|
402
|
+
command = @commands[match] or raise NoCommandError.new(match, self)
|
360
403
|
command.new(context).call_safely(*args)
|
361
404
|
end
|
362
405
|
|
@@ -368,9 +411,9 @@ class Pry
|
|
368
411
|
if command = find_command(search)
|
369
412
|
command.new(context).complete(search)
|
370
413
|
else
|
371
|
-
commands.keys.select do |
|
372
|
-
String ===
|
373
|
-
end.map{ |
|
414
|
+
@commands.keys.select do |key|
|
415
|
+
String === key && key.start_with?(search)
|
416
|
+
end.map{ |key| key + " " }
|
374
417
|
end
|
375
418
|
end
|
376
419
|
end
|
data/lib/pry/commands.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Pry
|
2
2
|
class Command::AmendLine < Pry::ClassCommand
|
3
|
-
match
|
3
|
+
match(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/)
|
4
4
|
group 'Editing'
|
5
5
|
description 'Amend a line of input in multi-line mode.'
|
6
6
|
command_options :interpolate => false, :listing => 'amend-line'
|
@@ -48,7 +48,7 @@ class Pry
|
|
48
48
|
|
49
49
|
def insert_into_array(array, range)
|
50
50
|
insert_slot = Array(range).first
|
51
|
-
array.insert(insert_slot, arg_string[1..-1]
|
51
|
+
array.insert(insert_slot, arg_string[1..-1] << "\n")
|
52
52
|
end
|
53
53
|
|
54
54
|
def replace_in_array(array, range)
|
data/lib/pry/commands/bang.rb
CHANGED
data/lib/pry/commands/cat.rb
CHANGED
@@ -41,11 +41,20 @@ class Pry
|
|
41
41
|
FileFormatter.new(args.first, _pry_, opts).format
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
_pry_.pager.page output
|
45
45
|
end
|
46
46
|
|
47
47
|
def complete(search)
|
48
|
-
super
|
48
|
+
super | load_path_completions
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_path_completions
|
52
|
+
$LOAD_PATH.flat_map do |path|
|
53
|
+
Dir[path + '/**/*'].map { |f|
|
54
|
+
next if File.directory?(f)
|
55
|
+
f.sub!(path + '/', '')
|
56
|
+
}
|
57
|
+
end
|
49
58
|
end
|
50
59
|
end
|
51
60
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Pry
|
2
2
|
class Command::Cat
|
3
3
|
class ExceptionFormatter < AbstractFormatter
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
attr_reader :ex
|
5
|
+
attr_reader :opts
|
6
|
+
attr_reader :_pry_
|
7
7
|
|
8
8
|
def initialize(exception, _pry_, opts)
|
9
9
|
@ex = exception
|
@@ -23,7 +23,7 @@ class Pry
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def code_window_size
|
26
|
-
|
26
|
+
_pry_.config.default_window_size || 5
|
27
27
|
end
|
28
28
|
|
29
29
|
def backtrace_level
|
@@ -44,8 +44,7 @@ class Pry
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def backtrace_file
|
47
|
-
|
48
|
-
(file && RbxPath.is_core_path?(file)) ? RbxPath.convert_path_to_full(file) : file
|
47
|
+
Array(ex.bt_source_location_for(backtrace_level)).first
|
49
48
|
end
|
50
49
|
|
51
50
|
def backtrace_line
|