pry 0.9.8.2-java → 0.9.8.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.markdown +20 -13
- data/Rakefile +1 -1
- data/lib/pry.rb +1 -2
- data/lib/pry/command.rb +88 -2
- data/lib/pry/command_set.rb +15 -85
- data/lib/pry/commands.rb +12 -8
- data/lib/pry/default_commands/cd.rb +58 -0
- data/lib/pry/default_commands/commands.rb +62 -0
- data/lib/pry/default_commands/context.rb +48 -165
- data/lib/pry/default_commands/editing.rb +385 -0
- data/lib/pry/default_commands/help.rb +127 -0
- data/lib/pry/default_commands/hist.rb +116 -0
- data/lib/pry/default_commands/{shell.rb → input_and_output.rb} +137 -15
- data/lib/pry/default_commands/introspection.rb +79 -232
- data/lib/pry/default_commands/ls.rb +4 -2
- data/lib/pry/default_commands/{basic.rb → misc.rb} +1 -14
- data/lib/pry/default_commands/navigating_pry.rb +114 -0
- data/lib/pry/helpers/base_helpers.rb +15 -3
- data/lib/pry/helpers/command_helpers.rb +16 -0
- data/lib/pry/history.rb +12 -4
- data/lib/pry/method.rb +2 -2
- data/lib/pry/pry_class.rb +7 -1
- data/lib/pry/pry_instance.rb +6 -0
- data/lib/pry/rbx_path.rb +6 -18
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +8 -8
- data/test/helper.rb +8 -0
- data/test/test_command.rb +256 -2
- data/test/test_command_integration.rb +2 -13
- data/test/test_command_set.rb +13 -23
- data/test/test_default_commands/test_help.rb +57 -0
- data/test/test_default_commands/test_introspection.rb +23 -0
- data/test/test_pry.rb +11 -0
- metadata +13 -9
- data/lib/pry/default_commands/documentation.rb +0 -209
- data/lib/pry/default_commands/input.rb +0 -247
- data/test/test_default_commands.rb +0 -58
@@ -1,247 +0,0 @@
|
|
1
|
-
class Pry
|
2
|
-
module DefaultCommands
|
3
|
-
|
4
|
-
Input = Pry::CommandSet.new do
|
5
|
-
|
6
|
-
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
|
7
|
-
def process
|
8
|
-
output.puts "Input buffer cleared!"
|
9
|
-
eval_string.replace("")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
create_command "show-input", "Show the contents of the input buffer for the current multi-line expression." do
|
14
|
-
def process
|
15
|
-
output.puts Code.new(eval_string).with_line_numbers
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
create_command(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/) do
|
20
|
-
description "Amend a line of input in multi-line mode. Type `amend-line --help` for more information."
|
21
|
-
command_options :interpolate => false, :listing => "amend-line"
|
22
|
-
|
23
|
-
banner <<-'BANNER'
|
24
|
-
Amend a line of input in multi-line mode. `amend-line N`, where the N in `amend-line N` represents line to replace.
|
25
|
-
|
26
|
-
Can also specify a range of lines using `amend-line N..M` syntax. Passing '!' as replacement content deletes the line(s) instead.
|
27
|
-
e.g amend-line 1 puts 'hello world! # replace line 1'
|
28
|
-
e.g amend-line 1..4 ! # delete lines 1..4
|
29
|
-
e.g amend-line 3 >puts 'goodbye' # insert before line 3
|
30
|
-
e.g amend-line puts 'hello again' # no line number modifies immediately preceding line
|
31
|
-
BANNER
|
32
|
-
|
33
|
-
def process
|
34
|
-
start_line_number, end_line_number, replacement_line = *args
|
35
|
-
|
36
|
-
if eval_string.empty?
|
37
|
-
raise CommandError, "No input to amend."
|
38
|
-
end
|
39
|
-
|
40
|
-
replacement_line = "" if !replacement_line
|
41
|
-
input_array = eval_string.each_line.to_a
|
42
|
-
|
43
|
-
end_line_number = start_line_number.to_i if !end_line_number
|
44
|
-
line_range = start_line_number ? (one_index_number(start_line_number.to_i)..one_index_number(end_line_number.to_i)) : input_array.size - 1
|
45
|
-
|
46
|
-
# delete selected lines if replacement line is '!'
|
47
|
-
if arg_string == "!"
|
48
|
-
input_array.slice!(line_range)
|
49
|
-
elsif arg_string.start_with?(">")
|
50
|
-
insert_slot = Array(line_range).first
|
51
|
-
input_array.insert(insert_slot, arg_string[1..-1] + "\n")
|
52
|
-
else
|
53
|
-
input_array[line_range] = arg_string + "\n"
|
54
|
-
end
|
55
|
-
eval_string.replace input_array.join
|
56
|
-
run "show-input"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
create_command "play" do
|
61
|
-
description "Play back a string variable or a method or a file as input. Type `play --help` for more information."
|
62
|
-
|
63
|
-
banner <<-BANNER
|
64
|
-
Usage: play [OPTIONS] [--help]
|
65
|
-
|
66
|
-
The play command enables you to replay code from files and methods as
|
67
|
-
if they were entered directly in the Pry REPL. Default action (no
|
68
|
-
options) is to play the provided string variable
|
69
|
-
|
70
|
-
e.g: `play -i 20 --lines 1..3`
|
71
|
-
e.g: `play -m Pry#repl --lines 1..-1`
|
72
|
-
e.g: `play -f Rakefile --lines 5`
|
73
|
-
|
74
|
-
https://github.com/pry/pry/wiki/User-Input#wiki-Play
|
75
|
-
BANNER
|
76
|
-
|
77
|
-
attr_accessor :content
|
78
|
-
|
79
|
-
def setup
|
80
|
-
self.content = ""
|
81
|
-
end
|
82
|
-
|
83
|
-
def options(opt)
|
84
|
-
opt.on :m, :method, "Play a method's source.", true do |meth_name|
|
85
|
-
meth = get_method_or_raise(meth_name, target, {})
|
86
|
-
self.content << meth.source
|
87
|
-
end
|
88
|
-
opt.on :d, :doc, "Play a method's documentation.", true do |meth_name|
|
89
|
-
meth = get_method_or_raise(meth_name, target, {})
|
90
|
-
text.no_color do
|
91
|
-
self.content << process_comment_markup(meth.doc, :ruby)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
opt.on :c, :command, "Play a command's source.", true do |command_name|
|
95
|
-
command = find_command(command_name)
|
96
|
-
block = Pry::Method.new(find_command(command_name).block)
|
97
|
-
self.content << block.source
|
98
|
-
end
|
99
|
-
opt.on :f, :file, "Play a file.", true do |file|
|
100
|
-
self.content << File.read(File.expand_path(file))
|
101
|
-
end
|
102
|
-
opt.on :l, :lines, "Only play a subset of lines.", :optional => true, :as => Range, :default => 1..-1
|
103
|
-
opt.on :i, :in, "Play entries from Pry's input expression history. Takes an index or range.", :optional => true,
|
104
|
-
:as => Range, :default => -5..-1 do |range|
|
105
|
-
input_expressions = _pry_.input_array[range] || []
|
106
|
-
Array(input_expressions).each { |v| self.content << v }
|
107
|
-
end
|
108
|
-
opt.on :o, "open", 'When used with the -m switch, it plays the entire method except the last line, leaving the method definition "open". `amend-line` can then be used to modify the method.'
|
109
|
-
end
|
110
|
-
|
111
|
-
def process
|
112
|
-
perform_play
|
113
|
-
run "show-input" unless _pry_.complete_expression?(eval_string)
|
114
|
-
end
|
115
|
-
|
116
|
-
def process_non_opt
|
117
|
-
args.each do |arg|
|
118
|
-
begin
|
119
|
-
self.content << target.eval(arg)
|
120
|
-
rescue Pry::RescuableException
|
121
|
-
raise CommandError, "Prblem when evaling #{arg}."
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def perform_play
|
127
|
-
process_non_opt
|
128
|
-
|
129
|
-
if opts.present?(:lines)
|
130
|
-
self.content = restrict_to_lines(self.content, opts[:l])
|
131
|
-
end
|
132
|
-
|
133
|
-
if opts.present?(:open)
|
134
|
-
self.content = restrict_to_lines(self.content, 1..-2)
|
135
|
-
end
|
136
|
-
|
137
|
-
eval_string << self.content
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
create_command "hist", "Show and replay Readline history. Aliases: history" do
|
142
|
-
banner <<-USAGE
|
143
|
-
Usage: hist
|
144
|
-
hist --head N
|
145
|
-
hist --tail N
|
146
|
-
hist --show START..END
|
147
|
-
hist --grep PATTERN
|
148
|
-
hist --clear
|
149
|
-
hist --replay START..END
|
150
|
-
hist --save [START..END] FILE
|
151
|
-
USAGE
|
152
|
-
|
153
|
-
def options(opt)
|
154
|
-
opt.on :H, :head, "Display the first N items.", :optional => true, :as => Integer
|
155
|
-
opt.on :T, :tail, "Display the last N items.", :optional => true, :as => Integer
|
156
|
-
opt.on :s, :show, "Show the given range of lines.", :optional => true, :as => Range
|
157
|
-
opt.on :G, :grep, "Show lines matching the given pattern.", true, :as => String
|
158
|
-
opt.on :c, :clear, "Clear the current session's history."
|
159
|
-
opt.on :r, :replay, "Replay a line or range of lines.", true, :as => Range
|
160
|
-
opt.on :save, "Save history to a file.", true, :as => Range
|
161
|
-
|
162
|
-
opt.on :e, :'exclude-pry', "Exclude Pry commands from the history."
|
163
|
-
opt.on :n, :'no-numbers', "Omit line numbers."
|
164
|
-
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
165
|
-
end
|
166
|
-
|
167
|
-
def process
|
168
|
-
@history = Pry::Code(Pry.history.to_a)
|
169
|
-
|
170
|
-
@history = case
|
171
|
-
when opts.present?(:head)
|
172
|
-
@history.between(1, opts[:head] || 10)
|
173
|
-
when opts.present?(:tail)
|
174
|
-
@history.between(-(opts[:tail] || 10), -1)
|
175
|
-
when opts.present?(:show)
|
176
|
-
@history.between(opts[:show])
|
177
|
-
else
|
178
|
-
@history
|
179
|
-
end
|
180
|
-
|
181
|
-
if opts.present?(:grep)
|
182
|
-
@history = @history.grep(opts[:grep])
|
183
|
-
end
|
184
|
-
|
185
|
-
if opts.present?(:'exclude-pry')
|
186
|
-
@history = @history.select { |l, ln| !command_set.valid_command?(l) }
|
187
|
-
end
|
188
|
-
|
189
|
-
if opts.present?(:save)
|
190
|
-
process_save
|
191
|
-
elsif opts.present?(:clear)
|
192
|
-
process_clear
|
193
|
-
elsif opts.present?(:replay)
|
194
|
-
process_replay
|
195
|
-
else
|
196
|
-
process_display
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def process_display
|
201
|
-
unless opts.present?(:'no-numbers')
|
202
|
-
@history = @history.with_line_numbers
|
203
|
-
end
|
204
|
-
|
205
|
-
render_output(@history, opts)
|
206
|
-
end
|
207
|
-
|
208
|
-
def process_save
|
209
|
-
case opts[:save]
|
210
|
-
when Range
|
211
|
-
@history = @history.between(opts[:save])
|
212
|
-
|
213
|
-
unless args.first
|
214
|
-
raise CommandError, "Must provide a file name."
|
215
|
-
end
|
216
|
-
|
217
|
-
file_name = File.expand_path(args.first)
|
218
|
-
when String
|
219
|
-
file_name = File.expand_path(opts[:save])
|
220
|
-
end
|
221
|
-
|
222
|
-
output.puts "Saving history in #{file_name}..."
|
223
|
-
|
224
|
-
File.open(file_name, 'w') { |f| f.write(@history.to_s) }
|
225
|
-
|
226
|
-
output.puts "History saved."
|
227
|
-
end
|
228
|
-
|
229
|
-
def process_clear
|
230
|
-
Pry.history.clear
|
231
|
-
output.puts "History cleared."
|
232
|
-
end
|
233
|
-
|
234
|
-
def process_replay
|
235
|
-
@history = @history.between(opts[:r])
|
236
|
-
|
237
|
-
_pry_.input_stack.push _pry_.input
|
238
|
-
_pry_.input = StringIO.new(@history.raw)
|
239
|
-
# eval_string << "#{@history.raw}\n"
|
240
|
-
# run "show-input" unless _pry_.complete_expression?(eval_string)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
alias_command "history", "hist"
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry::Commands" do
|
4
|
-
describe "help" do
|
5
|
-
it 'should display help for a specific command' do
|
6
|
-
str_output = StringIO.new
|
7
|
-
redirect_pry_io(InputTester.new("help ls", "exit-all"), str_output) do
|
8
|
-
pry
|
9
|
-
end
|
10
|
-
str_output.string.should =~ /Usage: ls/
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should display help for a regex command with a "listing"' do
|
14
|
-
set = Pry::CommandSet.new do
|
15
|
-
command /bar(.*)/, "Test listing", :listing => "foo" do
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
str_output = StringIO.new
|
20
|
-
redirect_pry_io(InputTester.new("help foo"), str_output) do
|
21
|
-
Pry.new(:commands => set).rep
|
22
|
-
end
|
23
|
-
str_output.string.each_line.count.should == 1
|
24
|
-
str_output.string.should =~ /Test listing/
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should display help for a command with a spaces in its name' do
|
28
|
-
set = Pry::CommandSet.new do
|
29
|
-
command "command with spaces", "description of a command with spaces" do
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
str_output = StringIO.new
|
34
|
-
redirect_pry_io(InputTester.new("help \"command with spaces\""), str_output) do
|
35
|
-
Pry.new(:commands => set).rep
|
36
|
-
end
|
37
|
-
str_output.string.each_line.count.should == 1
|
38
|
-
str_output.string.should =~ /description of a command with spaces/
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should display help for all commands with a description' do
|
42
|
-
set = Pry::CommandSet.new do
|
43
|
-
command /bar(.*)/, "Test listing", :listing => "foo" do; end
|
44
|
-
command "b", "description for b", :listing => "foo" do; end
|
45
|
-
command "c" do;end
|
46
|
-
command "d", "" do;end
|
47
|
-
end
|
48
|
-
|
49
|
-
str_output = StringIO.new
|
50
|
-
redirect_pry_io(InputTester.new("help"), str_output) do
|
51
|
-
Pry.new(:commands => set).rep
|
52
|
-
end
|
53
|
-
str_output.string.should =~ /Test listing/
|
54
|
-
str_output.string.should =~ /description for b/
|
55
|
-
str_output.string.should =~ /No description/
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|