pry 0.8.0pre7-i386-mswin32 → 0.8.0pre8-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +17 -3
- data/lib/pry/command_base.rb +58 -9
- data/lib/pry/command_base_helpers.rb +110 -0
- data/lib/pry/command_helpers.rb +45 -57
- data/lib/pry/command_processor.rb +27 -2
- data/lib/pry/commands.rb +118 -22
- data/lib/pry/version.rb +1 -1
- data/test/test.rb +2 -1
- metadata +4 -11
data/README.markdown
CHANGED
@@ -3,9 +3,23 @@ Pry
|
|
3
3
|
|
4
4
|
(C) John Mair (banisterfiend) 2011
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
Pry is a
|
6
|
+
_Ruby voyeurism_
|
7
|
+
|
8
|
+
Pry is a powerful alternative to the standard IRB shell for Ruby. It is
|
9
|
+
written from scratch to provide a number of advanced features, some of
|
10
|
+
these include:
|
11
|
+
|
12
|
+
* Runtime invocation
|
13
|
+
* Syntax highlighting
|
14
|
+
* Command shell integration
|
15
|
+
* Source code browsing (including core C source with the pry-doc gem)
|
16
|
+
* Documentation browsing
|
17
|
+
* Exotic object support (BasicObject instances, IClasses, ...)
|
18
|
+
* A Powerful and flexible command system
|
19
|
+
* Gisting ability
|
20
|
+
* Many convenience commands
|
21
|
+
|
22
|
+
Pry is a Ruby REPL (Read-Eval-Print-Loop) that specializes in the interactive
|
9
23
|
manipulation of objects during the running of a program.
|
10
24
|
|
11
25
|
In some sense it is the opposite of IRB in that you bring a REPL
|
data/lib/pry/command_base.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
require "#{direc}/command_base_helpers"
|
3
|
+
|
1
4
|
class Pry
|
2
5
|
|
3
6
|
# Basic command functionality. All user-defined commands must
|
4
7
|
# inherit from this class. It provides the `command` method.
|
5
8
|
class CommandBase
|
6
9
|
class << self
|
10
|
+
include CommandBaseHelpers
|
11
|
+
|
7
12
|
attr_accessor :commands
|
8
13
|
attr_accessor :opts, :output, :target
|
9
14
|
|
@@ -39,17 +44,22 @@ class Pry
|
|
39
44
|
# # Greet somebody
|
40
45
|
def command(names, description="No description.", options={}, &block)
|
41
46
|
options = {
|
42
|
-
:keep_retval => false
|
47
|
+
:keep_retval => false,
|
48
|
+
:requires_gem => nil
|
43
49
|
}.merge!(options)
|
44
50
|
|
45
51
|
@commands ||= {}
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
if command_dependencies_met?(options)
|
54
|
+
Array(names).each do |name|
|
55
|
+
commands[name] = {
|
56
|
+
:description => description,
|
57
|
+
:action => block,
|
58
|
+
:keep_retval => options[:keep_retval]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
else
|
62
|
+
create_command_stub(names, description, options, block)
|
53
63
|
end
|
54
64
|
end
|
55
65
|
|
@@ -133,10 +143,16 @@ class Pry
|
|
133
143
|
command_info = opts[:commands]
|
134
144
|
|
135
145
|
if !cmd
|
136
|
-
output.puts
|
146
|
+
output.puts
|
147
|
+
help_text = heading("Command List:") + "\n"
|
137
148
|
command_info.each do |k, data|
|
138
|
-
|
149
|
+
if !data[:stub_info]
|
150
|
+
help_text << ("#{k}".ljust(18) + data[:description] + "\n") if !data[:description].empty?
|
151
|
+
else
|
152
|
+
help_text << (bold("#{k}".ljust(18) + data[:description] + "\n")) if !data[:description].empty?
|
153
|
+
end
|
139
154
|
end
|
155
|
+
stagger_output(help_text)
|
140
156
|
else
|
141
157
|
if command_info[cmd]
|
142
158
|
output.puts command_info[cmd][:description]
|
@@ -146,6 +162,39 @@ class Pry
|
|
146
162
|
end
|
147
163
|
end
|
148
164
|
|
165
|
+
command "install", "Install a disabled command." do |name|
|
166
|
+
stub_info = commands[name][:stub_info]
|
167
|
+
|
168
|
+
if !stub_info
|
169
|
+
output.puts "Not a command stub. Nothing to do."
|
170
|
+
next
|
171
|
+
end
|
172
|
+
|
173
|
+
output.puts "Attempting to install `#{name}` command..."
|
174
|
+
|
175
|
+
require 'rubygems/dependency_installer'
|
176
|
+
gems_to_install = Array(stub_info[:requires_gem])
|
177
|
+
|
178
|
+
gem_install_failed = false
|
179
|
+
gems_to_install.each do |g|
|
180
|
+
next if gem_installed?(g)
|
181
|
+
output.puts "Installing `#{g}` gem..."
|
182
|
+
|
183
|
+
begin
|
184
|
+
Gem::DependencyInstaller.new.install(g)
|
185
|
+
rescue Gem::GemNotFoundException
|
186
|
+
output.puts "Required Gem: `#{g}` not found. Aborting command installation."
|
187
|
+
gem_install_failed = true
|
188
|
+
next
|
189
|
+
end
|
190
|
+
end
|
191
|
+
next if gem_install_failed
|
192
|
+
|
193
|
+
Gem.refresh
|
194
|
+
load "#{File.dirname(__FILE__)}/commands.rb"
|
195
|
+
output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
|
196
|
+
end
|
197
|
+
|
149
198
|
# Ensures that commands can be inherited
|
150
199
|
def self.inherited(klass)
|
151
200
|
klass.commands = commands.dup
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class Pry
|
2
|
+
class CommandBase
|
3
|
+
module CommandBaseHelpers
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def gem_installed?(gem_name)
|
8
|
+
require 'rubygems'
|
9
|
+
!!Gem.source_index.find_name(gem_name).first
|
10
|
+
end
|
11
|
+
|
12
|
+
def command_dependencies_met?(options)
|
13
|
+
return true if !options[:requires_gem]
|
14
|
+
Array(options[:requires_gem]).all? do |g|
|
15
|
+
gem_installed?(g)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_proc(name, options)
|
20
|
+
gems_needed = Array(options[:requires_gem])
|
21
|
+
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
22
|
+
proc do
|
23
|
+
output.puts "\n`#{name}` requires the following gems to be installed: `#{gems_needed.join(", ")}`"
|
24
|
+
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
25
|
+
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_command_stub(names, description, options, block)
|
30
|
+
Array(names).each do |name|
|
31
|
+
commands[name] = {
|
32
|
+
:description => "Not available. Execute `#{name}` command for more information.",
|
33
|
+
:action => stub_proc(name, options),
|
34
|
+
:stub_info => options
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def bold(text)
|
40
|
+
Pry.color ? "\e[1m#{text}\e[0m" : text
|
41
|
+
end
|
42
|
+
|
43
|
+
# formatting
|
44
|
+
def heading(text)
|
45
|
+
text = "#{text}\n--"
|
46
|
+
Pry.color ? "\e[1m#{text}\e[0m": text
|
47
|
+
end
|
48
|
+
|
49
|
+
def page_size
|
50
|
+
27
|
51
|
+
end
|
52
|
+
|
53
|
+
# a simple pager for systems without `less`. A la windows.
|
54
|
+
def simple_pager(text)
|
55
|
+
text_array = text.lines.to_a
|
56
|
+
text_array.each_slice(page_size) do |chunk|
|
57
|
+
output.puts chunk.join
|
58
|
+
break if chunk.size < page_size
|
59
|
+
if text_array.size > page_size
|
60
|
+
output.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
|
61
|
+
break if $stdin.gets.chomp == "q"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Try to use `less` for paging, if it fails then use simple_pager
|
67
|
+
def stagger_output(text)
|
68
|
+
if text.lines.count < page_size
|
69
|
+
output.puts text
|
70
|
+
return
|
71
|
+
end
|
72
|
+
lesspipe { |less| less.puts text }
|
73
|
+
rescue Exception
|
74
|
+
simple_pager(text)
|
75
|
+
end
|
76
|
+
|
77
|
+
# thanks to epitron for this method
|
78
|
+
def lesspipe(*args)
|
79
|
+
if args.any? and args.last.is_a?(Hash)
|
80
|
+
options = args.pop
|
81
|
+
else
|
82
|
+
options = {}
|
83
|
+
end
|
84
|
+
|
85
|
+
output = args.first if args.any?
|
86
|
+
|
87
|
+
params = []
|
88
|
+
params << "-R" unless options[:color] == false
|
89
|
+
params << "-S" unless options[:wrap] == true
|
90
|
+
params << "-F" unless options[:always] == true
|
91
|
+
if options[:tail] == true
|
92
|
+
params << "+\\>"
|
93
|
+
$stderr.puts "Seeking to end of stream..."
|
94
|
+
end
|
95
|
+
params << "-X"
|
96
|
+
|
97
|
+
IO.popen("less #{params * ' '}", "w") do |less|
|
98
|
+
if output
|
99
|
+
less.puts output
|
100
|
+
else
|
101
|
+
yield less
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
data/lib/pry/command_helpers.rb
CHANGED
@@ -27,30 +27,9 @@ class Pry
|
|
27
27
|
$_file_temp = File.expand_path(file_name)
|
28
28
|
$_dir_temp = File.dirname($_file_temp)
|
29
29
|
target.eval("_file_ = $_file_temp")
|
30
|
-
target.eval("_dir_ = $
|
30
|
+
target.eval("_dir_ = $_dir_temp")
|
31
31
|
end
|
32
|
-
|
33
|
-
# a simple pager for systems without `less`. A la windows.
|
34
|
-
def simple_pager(text)
|
35
|
-
page_size = 22
|
36
|
-
text_array = text.lines.to_a
|
37
|
-
text_array.each_slice(page_size) do |chunk|
|
38
|
-
output.puts chunk.join
|
39
|
-
break if chunk.size < page_size
|
40
|
-
if text_array.size > page_size
|
41
|
-
output.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
|
42
|
-
break if $stdin.gets.chomp == "q"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Try to use `less` for paging, if it fails then use simple_pager
|
48
|
-
def stagger_output(text)
|
49
|
-
lesspipe { |less| less.puts text }
|
50
|
-
rescue Exception
|
51
|
-
simple_pager(text)
|
52
|
-
end
|
53
|
-
|
32
|
+
|
54
33
|
def add_line_numbers(lines, start_line)
|
55
34
|
line_array = lines.each_line.to_a
|
56
35
|
line_array.each_with_index.map do |line, idx|
|
@@ -64,7 +43,6 @@ class Pry
|
|
64
43
|
end.join
|
65
44
|
end
|
66
45
|
|
67
|
-
# only add line numbers if start_line is not false
|
68
46
|
# if start_line is not false then add line numbers starting with start_line
|
69
47
|
def render_output(should_flood, start_line, doc)
|
70
48
|
if start_line
|
@@ -89,6 +67,45 @@ class Pry
|
|
89
67
|
text.split.drop(1).join(' ')
|
90
68
|
end
|
91
69
|
|
70
|
+
# turn off color for duration of block
|
71
|
+
def no_color(&block)
|
72
|
+
old_color_state = Pry.color
|
73
|
+
Pry.color = false
|
74
|
+
yield
|
75
|
+
ensure
|
76
|
+
Pry.color = old_color_state
|
77
|
+
end
|
78
|
+
|
79
|
+
def code_and_code_type_for(meth)
|
80
|
+
case code_type = code_type_for(meth)
|
81
|
+
when nil
|
82
|
+
return nil
|
83
|
+
when :c
|
84
|
+
code = Pry::MethodInfo.info_for(meth).source
|
85
|
+
code = strip_comments_from_c_code(code)
|
86
|
+
when :ruby
|
87
|
+
code = strip_leading_whitespace(meth.source)
|
88
|
+
set_file_and_dir_locals(meth.source_location.first)
|
89
|
+
end
|
90
|
+
|
91
|
+
[code, code_type]
|
92
|
+
end
|
93
|
+
|
94
|
+
def doc_and_code_type_for(meth)
|
95
|
+
case code_type = code_type_for(meth)
|
96
|
+
when nil
|
97
|
+
return nil
|
98
|
+
when :c
|
99
|
+
doc = Pry::MethodInfo.info_for(meth).docstring
|
100
|
+
when :ruby
|
101
|
+
doc = meth.comment
|
102
|
+
doc = strip_leading_hash_and_whitespace_from_ruby_comments(doc)
|
103
|
+
set_file_and_dir_locals(meth.source_location.first)
|
104
|
+
end
|
105
|
+
|
106
|
+
[doc, code_type]
|
107
|
+
end
|
108
|
+
|
92
109
|
def get_method_object(meth_name, target, options)
|
93
110
|
if !meth_name
|
94
111
|
return nil
|
@@ -113,12 +130,12 @@ class Pry
|
|
113
130
|
|
114
131
|
def make_header(meth, code_type, content)
|
115
132
|
file, line = meth.source_location
|
116
|
-
num_lines = "Number of lines: #{content.each_line.count}"
|
133
|
+
num_lines = "Number of lines: #{bold(content.each_line.count.to_s)}"
|
117
134
|
case code_type
|
118
135
|
when :ruby
|
119
|
-
"\
|
136
|
+
"\n#{bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n"
|
120
137
|
else
|
121
|
-
"\
|
138
|
+
"\n#{bold('From:')} Ruby Core (C Method):\n#{num_lines}\n\n"
|
122
139
|
end
|
123
140
|
end
|
124
141
|
|
@@ -156,7 +173,7 @@ class Pry
|
|
156
173
|
{
|
157
174
|
[".c", ".h"] => :c,
|
158
175
|
[".cpp", ".hpp", ".cc", ".h", "cxx"] => :cpp,
|
159
|
-
[".rb", "Rakefile"] => :ruby,
|
176
|
+
[".rb", "Rakefile", ".irbrc", ".gemspec", ".pryrc"] => :ruby,
|
160
177
|
".py" => :python,
|
161
178
|
".diff" => :diff,
|
162
179
|
".css" => :css,
|
@@ -257,35 +274,6 @@ class Pry
|
|
257
274
|
code.sub /\A\s*\/\*.*?\*\/\s*/m, ''
|
258
275
|
end
|
259
276
|
|
260
|
-
# thanks to epitron for this method
|
261
|
-
def lesspipe(*args)
|
262
|
-
if args.any? and args.last.is_a?(Hash)
|
263
|
-
options = args.pop
|
264
|
-
else
|
265
|
-
options = {}
|
266
|
-
end
|
267
|
-
|
268
|
-
output = args.first if args.any?
|
269
|
-
|
270
|
-
params = []
|
271
|
-
params << "-R" unless options[:color] == false
|
272
|
-
params << "-S" unless options[:wrap] == true
|
273
|
-
params << "-F" unless options[:always] == true
|
274
|
-
if options[:tail] == true
|
275
|
-
params << "+\\>"
|
276
|
-
$stderr.puts "Seeking to end of stream..."
|
277
|
-
end
|
278
|
-
params << "-X"
|
279
|
-
|
280
|
-
IO.popen("less #{params * ' '}", "w") do |less|
|
281
|
-
if output
|
282
|
-
less.puts output
|
283
|
-
else
|
284
|
-
yield less
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
277
|
end
|
290
278
|
end
|
291
279
|
end
|
@@ -15,24 +15,47 @@ class Pry
|
|
15
15
|
|
16
16
|
def_delegators :@pry_instance, :commands, :nesting, :output
|
17
17
|
|
18
|
+
# Is the string a command valid?
|
19
|
+
# @param [String] val The string passed in from the Pry prompt.
|
20
|
+
# @return [Boolean] Whether the string is a valid command.
|
18
21
|
def valid_command?(val)
|
19
22
|
system_command?(val) || pry_command?(val)
|
20
23
|
end
|
21
24
|
|
25
|
+
# Is the string a valid system command?
|
26
|
+
# @param [String] val The string passed in from the Pry prompt.
|
27
|
+
# @return [Boolean] Whether the string is a valid system command.
|
22
28
|
def system_command?(val)
|
23
29
|
!!(SYSTEM_COMMAND_REGEX =~ val)
|
24
30
|
end
|
25
31
|
|
32
|
+
# Is the string a valid pry command?
|
33
|
+
# A Pry command is a command that is not a system command.
|
34
|
+
# @param [String] val The string passed in from the Pry prompt.
|
35
|
+
# @return [Boolean] Whether the string is a valid Pry command.
|
26
36
|
def pry_command?(val)
|
27
37
|
!!command_matched(val).first
|
28
38
|
end
|
29
39
|
|
40
|
+
# Revaluate the string (str) and perform interpolation.
|
41
|
+
# @param [String] str The string to reevaluate with interpolation.
|
42
|
+
# @param [Binding] target The context where the string should be
|
43
|
+
# reevaluated in.
|
44
|
+
# @return [String] The reevaluated string with interpolations
|
45
|
+
# applied (if any).
|
30
46
|
def interpolate_string(str, target)
|
31
47
|
dumped_str = str.dump
|
32
48
|
dumped_str.gsub!(/\\\#\{/, '#{')
|
33
49
|
target.eval(dumped_str)
|
34
50
|
end
|
35
|
-
|
51
|
+
|
52
|
+
# Execute a given system command.
|
53
|
+
# The commands first have interpolation applied against the
|
54
|
+
# `target` context.
|
55
|
+
# All system command are forwarded to a shell. Note that the `cd`
|
56
|
+
# command is special-cased and is converted internallly to a `Dir.chdir`
|
57
|
+
# @param [String] val The system command to execute.
|
58
|
+
# @param [Binding] target The context in which to perform string interpolation.
|
36
59
|
def execute_system_command(val, target)
|
37
60
|
SYSTEM_COMMAND_REGEX =~ val
|
38
61
|
cmd = interpolate_string($1, target)
|
@@ -47,7 +70,8 @@ class Pry
|
|
47
70
|
system(cmd)
|
48
71
|
end
|
49
72
|
|
50
|
-
|
73
|
+
# Tick, tock, im getting rid of this shit soon.
|
74
|
+
val.replace("")
|
51
75
|
end
|
52
76
|
|
53
77
|
# Determine whether a Pry command was matched and return command data
|
@@ -131,6 +155,7 @@ class Pry
|
|
131
155
|
ret_val = commands.instance_exec(*args_with_corrected_arity, &action)
|
132
156
|
end
|
133
157
|
|
158
|
+
# Tick, tock, im getting rid of this shit soon.
|
134
159
|
options[:val].clear
|
135
160
|
|
136
161
|
ret_val
|
data/lib/pry/commands.rb
CHANGED
@@ -23,6 +23,9 @@ class Pry
|
|
23
23
|
Pry.start(target)
|
24
24
|
end
|
25
25
|
|
26
|
+
command ".<shell command>", "All text following a '.' is forwarded to the shell." do
|
27
|
+
end
|
28
|
+
|
26
29
|
command "exit-program", "End the current program. Aliases: quit-program, !!!" do
|
27
30
|
exit
|
28
31
|
end
|
@@ -30,6 +33,114 @@ class Pry
|
|
30
33
|
alias_command "quit-program", "exit-program", ""
|
31
34
|
alias_command "!!!", "exit-program", ""
|
32
35
|
|
36
|
+
command "ri", "View ri documentation. e.g `ri Array#each`" do |*args|
|
37
|
+
run target, ".ri", *args
|
38
|
+
end
|
39
|
+
|
40
|
+
command "stat", "View method information and set _file_ and _dir_ locals" do |*args|
|
41
|
+
options = {}
|
42
|
+
target = target()
|
43
|
+
meth_name = nil
|
44
|
+
|
45
|
+
OptionParser.new do |opts|
|
46
|
+
opts.banner = %{Usage: stat [OPTIONS] [METH]
|
47
|
+
Show method information for method METH and set _file_ and _dir_ locals.
|
48
|
+
e.g: stat hello_method
|
49
|
+
--
|
50
|
+
}
|
51
|
+
opts.on("-M", "--instance-methods", "Operate on instance methods.") do
|
52
|
+
options[:M] = true
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("-m", "--methods", "Operate on methods.") do
|
56
|
+
options[:m] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("-c", "--context CONTEXT", "Select object context to run under.") do |context|
|
60
|
+
target = Pry.binding_for(target.eval(context))
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on_tail("-h", "--help", "This message.") do
|
64
|
+
output.puts opts
|
65
|
+
options[:h] = true
|
66
|
+
end
|
67
|
+
end.order(args) do |v|
|
68
|
+
meth_name = v
|
69
|
+
end
|
70
|
+
|
71
|
+
next if options[:h]
|
72
|
+
|
73
|
+
meth_name = meth_name_from_binding(target) if !meth_name
|
74
|
+
|
75
|
+
if (meth = get_method_object(meth_name, target, options)).nil?
|
76
|
+
output.puts "Invalid method name: #{meth_name}. Type `stat --help` for help"
|
77
|
+
next
|
78
|
+
end
|
79
|
+
|
80
|
+
code, code_type = code_and_code_type_for(meth)
|
81
|
+
next if !code
|
82
|
+
doc, code_type = doc_and_code_type_for(meth)
|
83
|
+
|
84
|
+
output.puts make_header(meth, code_type, code)
|
85
|
+
output.puts bold("Method Name: ") + meth_name
|
86
|
+
output.puts bold("Method Language: ") + code_type.to_s.capitalize
|
87
|
+
output.puts bold("Method Type: ") + (meth.is_a?(Method) ? "Bound" : "Unbound")
|
88
|
+
output.puts bold("Method Arity: ") + meth.arity.to_s
|
89
|
+
output.puts bold("Comment length: ") + (doc.empty? ? 'No comment.' : (doc.lines.count.to_s + ' lines.'))
|
90
|
+
end
|
91
|
+
|
92
|
+
command "gist-method", "Gist a method to github.", :requires_gem => "gist" do |*args|
|
93
|
+
options = {}
|
94
|
+
meth_name = nil
|
95
|
+
|
96
|
+
OptionParser.new do |opts|
|
97
|
+
opts.banner = %{Usage: gist-method [OPTIONS] [METH]
|
98
|
+
Gist the method (doc or source) to github.
|
99
|
+
e.g: gist -m my_method
|
100
|
+
e.g: gist -d my_method
|
101
|
+
--
|
102
|
+
}
|
103
|
+
opts.on("-m", "--method", "Gist a method's source.") do |line|
|
104
|
+
options[:m] = true
|
105
|
+
end
|
106
|
+
|
107
|
+
opts.on("-d", "--doc", "Gist a method's documentation.") do
|
108
|
+
options[:d] = true
|
109
|
+
end
|
110
|
+
|
111
|
+
opts.on_tail("-h", "--help", "This message.") do
|
112
|
+
output.puts opts
|
113
|
+
options[:h] = true
|
114
|
+
end
|
115
|
+
end.order(args) do |v|
|
116
|
+
meth_name = v
|
117
|
+
end
|
118
|
+
|
119
|
+
next if options[:h]
|
120
|
+
|
121
|
+
meth_name = meth_name_from_binding(target) if !meth_name
|
122
|
+
|
123
|
+
if (meth = get_method_object(meth_name, target, options)).nil?
|
124
|
+
output.puts "Invalid method name: #{meth_name}. Type `gist-method --help` for help"
|
125
|
+
next
|
126
|
+
end
|
127
|
+
|
128
|
+
type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
|
129
|
+
if !options[:d]
|
130
|
+
content, code_type = code_and_code_type_for(meth)
|
131
|
+
else
|
132
|
+
content, code_type = doc_and_code_type_for(meth)
|
133
|
+
no_color do
|
134
|
+
content = process_comment_markup(content, code_type)
|
135
|
+
end
|
136
|
+
code_type = :plain
|
137
|
+
end
|
138
|
+
|
139
|
+
IO.popen("gist -p -t #{type_map[code_type]} -", "w") do |gist|
|
140
|
+
gist.puts content
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
33
144
|
command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
|
34
145
|
require 'rubygems'
|
35
146
|
gem_spec = Gem.source_index.find_name(gem_name).first
|
@@ -116,7 +227,7 @@ class Pry
|
|
116
227
|
end
|
117
228
|
|
118
229
|
set_file_and_dir_locals(file)
|
119
|
-
output.puts "\
|
230
|
+
output.puts "\n#{bold('From:')} #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n"
|
120
231
|
|
121
232
|
# This method inspired by http://rubygems.org/gems/ir_b
|
122
233
|
File.open(file).each_with_index do |line, index|
|
@@ -491,16 +602,8 @@ e.g show-doc hello_method
|
|
491
602
|
next
|
492
603
|
end
|
493
604
|
|
494
|
-
|
495
|
-
|
496
|
-
next
|
497
|
-
when :c
|
498
|
-
doc = Pry::MethodInfo.info_for(meth).docstring
|
499
|
-
when :ruby
|
500
|
-
doc = meth.comment
|
501
|
-
doc = strip_leading_hash_and_whitespace_from_ruby_comments(doc)
|
502
|
-
set_file_and_dir_locals(meth.source_location.first)
|
503
|
-
end
|
605
|
+
doc, code_type = doc_and_code_type_for(meth)
|
606
|
+
next if !doc
|
504
607
|
|
505
608
|
next output.puts("No documentation found.") if doc.empty?
|
506
609
|
|
@@ -514,7 +617,7 @@ e.g show-doc hello_method
|
|
514
617
|
|
515
618
|
alias_command "?", "show-doc", ""
|
516
619
|
|
517
|
-
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: show-source" do |*args|
|
620
|
+
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args|
|
518
621
|
options = {}
|
519
622
|
target = target()
|
520
623
|
meth_name = nil
|
@@ -562,16 +665,8 @@ e.g: show-method hello_method
|
|
562
665
|
next
|
563
666
|
end
|
564
667
|
|
565
|
-
|
566
|
-
|
567
|
-
next
|
568
|
-
when :c
|
569
|
-
code = Pry::MethodInfo.info_for(meth).source
|
570
|
-
code = strip_comments_from_c_code(code)
|
571
|
-
when :ruby
|
572
|
-
code = strip_leading_whitespace(meth.source)
|
573
|
-
set_file_and_dir_locals(meth.source_location.first)
|
574
|
-
end
|
668
|
+
code, code_type = code_and_code_type_for(meth)
|
669
|
+
next if !code
|
575
670
|
|
576
671
|
output.puts make_header(meth, code_type, code)
|
577
672
|
if Pry.color
|
@@ -588,6 +683,7 @@ e.g: show-method hello_method
|
|
588
683
|
end
|
589
684
|
|
590
685
|
alias_command "show-source", "show-method", ""
|
686
|
+
alias_command "$", "show-method", ""
|
591
687
|
|
592
688
|
command "show-command", "Show the source for CMD. Type `show-command --help` for more info." do |*args|
|
593
689
|
options = {}
|
data/lib/pry/version.rb
CHANGED
data/test/test.rb
CHANGED
@@ -434,8 +434,9 @@ describe Pry do
|
|
434
434
|
end
|
435
435
|
end
|
436
436
|
|
437
|
-
Command2.commands.keys.size.should ==
|
437
|
+
Command2.commands.keys.size.should == 3
|
438
438
|
Command2.commands.keys.include?("help").should == true
|
439
|
+
Command2.commands.keys.include?("install").should == true
|
439
440
|
Command2.commands.keys.include?("h").should == true
|
440
441
|
|
441
442
|
Object.remove_const(:Command2)
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -766259880
|
5
4
|
prerelease: true
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
8
|
+
- 0pre8
|
9
|
+
version: 0.8.0pre8
|
11
10
|
platform: i386-mswin32
|
12
11
|
authors:
|
13
12
|
- John Mair (banisterfiend)
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-04-
|
17
|
+
date: 2011-04-13 00:00:00 +12:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
28
|
segments:
|
31
29
|
- 2
|
32
30
|
- 0
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 53
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
- 9
|
@@ -58,7 +55,6 @@ dependencies:
|
|
58
55
|
requirements:
|
59
56
|
- - ">="
|
60
57
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 19
|
62
58
|
segments:
|
63
59
|
- 1
|
64
60
|
- 1
|
@@ -74,7 +70,6 @@ dependencies:
|
|
74
70
|
requirements:
|
75
71
|
- - ">="
|
76
72
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 15
|
78
73
|
segments:
|
79
74
|
- 0
|
80
75
|
- 4
|
@@ -90,7 +85,6 @@ dependencies:
|
|
90
85
|
requirements:
|
91
86
|
- - ">="
|
92
87
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 27
|
94
88
|
segments:
|
95
89
|
- 1
|
96
90
|
- 3
|
@@ -120,6 +114,7 @@ files:
|
|
120
114
|
- lib/pry/completion.rb
|
121
115
|
- lib/pry/print.rb
|
122
116
|
- lib/pry/pry_class.rb
|
117
|
+
- lib/pry/command_base_helpers.rb
|
123
118
|
- lib/pry/pry_instance.rb
|
124
119
|
- lib/pry.rb
|
125
120
|
- examples/example_commands.rb
|
@@ -155,7 +150,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
150
|
requirements:
|
156
151
|
- - ">="
|
157
152
|
- !ruby/object:Gem::Version
|
158
|
-
hash: 3
|
159
153
|
segments:
|
160
154
|
- 0
|
161
155
|
version: "0"
|
@@ -164,7 +158,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
158
|
requirements:
|
165
159
|
- - ">"
|
166
160
|
- !ruby/object:Gem::Version
|
167
|
-
hash: 25
|
168
161
|
segments:
|
169
162
|
- 1
|
170
163
|
- 3
|