pry 0.12.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +162 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry.rb +132 -119
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +43 -51
- data/lib/pry/code.rb +40 -28
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit.rb +184 -161
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/exit.rb +39 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +80 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -45
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression.rb +89 -86
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config.rb +307 -25
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +20 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +17 -14
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method.rb +141 -94
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +186 -180
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -103
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- metadata +35 -35
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/plugins.rb +0 -122
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
data/lib/pry/commands/reset.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class Reset < Pry::ClassCommand
|
6
|
+
match 'reset'
|
7
|
+
group 'Context'
|
8
|
+
description 'Reset the REPL to a clean state.'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Reset the REPL to a clean state.
|
12
|
+
BANNER
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
def process
|
15
|
+
output.puts 'Pry reset.'
|
16
|
+
exec 'pry'
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
20
|
+
Pry::Commands.add_command(Pry::Command::Reset)
|
21
|
+
end
|
18
22
|
end
|
data/lib/pry/commands/ri.rb
CHANGED
@@ -1,65 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
1
5
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
class Command
|
7
|
+
class Ri < Pry::ClassCommand
|
8
|
+
match 'ri'
|
9
|
+
group 'Introspection'
|
10
|
+
description 'View ri documentation.'
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
banner <<-'BANNER'
|
13
|
+
Usage: ri [spec]
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
View ri documentation. Relies on the "rdoc" gem being installed.
|
16
|
+
See also "show-doc" command.
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
ri Array#each
|
19
|
+
BANNER
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
def process(spec)
|
22
|
+
unless spec
|
23
|
+
return output.puts(
|
24
|
+
"Please provide a class, module, or method name (e.g: ri Array#push)"
|
25
|
+
)
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
|
28
|
+
# Lazily load RI
|
29
|
+
require 'rdoc/ri/driver'
|
23
30
|
|
24
|
-
|
31
|
+
unless defined? RDoc::RI::PryDriver
|
25
32
|
|
26
|
-
|
27
|
-
|
33
|
+
# Subclass RI so that it formats its output nicely, and uses `lesspipe`.
|
34
|
+
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
28
35
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
subclass.class_eval do
|
37
|
+
def initialize(pager, opts)
|
38
|
+
@pager = pager
|
39
|
+
super opts
|
40
|
+
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
def page
|
43
|
+
paging_text = StringIO.new
|
44
|
+
yield paging_text
|
45
|
+
@pager.page(paging_text.string)
|
46
|
+
end
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
def formatter(_io)
|
49
|
+
if @formatter_klass
|
50
|
+
@formatter_klass.new
|
51
|
+
else
|
52
|
+
RDoc::Markup::ToAnsi.new
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
|
-
end
|
49
56
|
|
50
|
-
|
51
|
-
|
57
|
+
RDoc::RI.const_set :PryDriver, subclass # hook it up!
|
58
|
+
end
|
52
59
|
|
53
|
-
|
54
|
-
|
60
|
+
# Spin-up an RI insance.
|
61
|
+
ri = RDoc::RI::PryDriver.new(
|
62
|
+
pry_instance.pager, use_stdout: true, interactive: false
|
63
|
+
)
|
55
64
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
65
|
+
begin
|
66
|
+
ri.display_names [spec] # Get the documentation (finally!)
|
67
|
+
rescue RDoc::RI::Driver::NotFoundError => e
|
68
|
+
output.puts "error: '#{e.name}' not found"
|
69
|
+
end
|
60
70
|
end
|
61
71
|
end
|
62
|
-
end
|
63
72
|
|
64
|
-
|
73
|
+
Pry::Commands.add_command(Pry::Command::Ri)
|
74
|
+
end
|
65
75
|
end
|
@@ -1,61 +1,63 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Pry
|
4
|
-
class Command
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Command
|
5
|
+
class SaveFile < Pry::ClassCommand
|
6
|
+
match 'save-file'
|
7
|
+
group 'Input and Output'
|
8
|
+
description 'Export to a file using content from the REPL.'
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: save-file [OPTIONS] --to [FILE]
|
11
12
|
|
12
|
-
|
13
|
+
Export to a file using content from the REPL.
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
save-file my_method --to hello.rb
|
16
|
+
save-file -i 1..10 --to hello.rb --append
|
17
|
+
save-file show-method --to my_command.rb
|
18
|
+
save-file sample_file.rb --lines 2..10 --to output_file.rb
|
19
|
+
BANNER
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def options(opt)
|
22
|
+
CodeCollector.inject_options(opt)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
opt.on :to=, "Specify the output file path"
|
25
|
+
opt.on :a, :append, "Append output to file"
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def process
|
29
|
+
@cc = CodeCollector.new(args, opts, pry_instance)
|
30
|
+
raise CommandError, "Found no code to save." if @cc.content.empty?
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if !file_name
|
33
|
+
display_content
|
34
|
+
else
|
35
|
+
save_file
|
36
|
+
end
|
35
37
|
end
|
36
|
-
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def file_name
|
40
|
+
opts[:to] || nil
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def save_file
|
44
|
+
File.open(file_name, mode) do |f|
|
45
|
+
f.puts @cc.content
|
46
|
+
end
|
47
|
+
output.puts "#{file_name} successfully saved"
|
45
48
|
end
|
46
|
-
output.puts "#{file_name} successfully saved"
|
47
|
-
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def display_content
|
51
|
+
output.puts @cc.content
|
52
|
+
output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
|
53
|
+
output.puts "No file saved!\n--"
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
def mode
|
57
|
+
opts.present?(:append) ? "a" : "w"
|
58
|
+
end
|
57
59
|
end
|
58
|
-
end
|
59
60
|
|
60
|
-
|
61
|
+
Pry::Commands.add_command(Pry::Command::SaveFile)
|
62
|
+
end
|
61
63
|
end
|
@@ -1,75 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
pass_block(cmd)
|
23
|
-
if command_block
|
24
|
-
command_block.call `#{cmd}`
|
4
|
+
class Command
|
5
|
+
class ShellCommand < Pry::ClassCommand
|
6
|
+
match(/\.(.*)/)
|
7
|
+
group 'Input and Output'
|
8
|
+
description "All text following a '.' is forwarded to the shell."
|
9
|
+
command_options listing: '.<shell command>', use_prefix: false,
|
10
|
+
takes_block: true
|
11
|
+
|
12
|
+
banner <<-'BANNER'
|
13
|
+
Usage: .COMMAND_NAME
|
14
|
+
|
15
|
+
All text following a "." is forwarded to the shell.
|
16
|
+
|
17
|
+
.ls -aF
|
18
|
+
.uname
|
19
|
+
BANNER
|
20
|
+
|
21
|
+
def process(cmd)
|
22
|
+
if cmd =~ /^cd\s*(.*)/i
|
23
|
+
process_cd parse_destination(Regexp.last_match(1))
|
25
24
|
else
|
26
|
-
|
25
|
+
pass_block(cmd)
|
26
|
+
if command_block
|
27
|
+
command_block.call `#{cmd}`
|
28
|
+
else
|
29
|
+
pry_instance.config.system.call(output, cmd, pry_instance)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
|
-
end
|
30
33
|
|
31
|
-
|
34
|
+
private
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
def parse_destination(dest)
|
37
|
+
return "~" if dest.empty?
|
38
|
+
return dest unless dest == "-"
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
state.old_pwd || raise(CommandError, "No prior directory available")
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
begin
|
43
|
+
def process_cd(dest)
|
42
44
|
state.old_pwd = Dir.pwd
|
43
45
|
Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest))
|
44
46
|
rescue Errno::ENOENT
|
45
47
|
raise CommandError, "No such directory: #{dest}"
|
46
48
|
end
|
47
|
-
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def cd_path_env
|
51
|
+
Pry::Env['CDPATH']
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def cd_path_exists?
|
55
|
+
cd_path_env && cd_path_env.length.nonzero?
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
def path_from_cd_path(dest)
|
59
|
+
return if !(dest && cd_path_exists?) || special_case_path?(dest)
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
return path
|
61
|
+
cd_path_env.split(File::PATH_SEPARATOR).each do |path|
|
62
|
+
return path if File.directory?(path) && path.split(File::SEPARATOR).last == dest
|
63
63
|
end
|
64
|
+
|
65
|
+
nil
|
64
66
|
end
|
65
67
|
|
66
|
-
|
68
|
+
def special_case_path?(dest)
|
69
|
+
['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
|
-
|
70
|
-
['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
|
71
|
-
end
|
73
|
+
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
72
74
|
end
|
73
|
-
|
74
|
-
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
75
75
|
end
|
@@ -1,25 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class ShellMode < Pry::ClassCommand
|
6
|
+
match 'shell-mode'
|
7
|
+
group 'Input and Output'
|
8
|
+
description 'Toggle shell mode. Bring in pwd prompt and file completion.'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Toggle shell mode. Bring in pwd prompt and file completion.
|
12
|
+
BANNER
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
def process
|
15
|
+
state.disabled ^= true
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
if state.disabled
|
18
|
+
state.prev_prompt = pry_instance.prompt
|
19
|
+
pry_instance.prompt = Pry::Prompt[:shell]
|
20
|
+
else
|
21
|
+
pry_instance.prompt = state.prev_prompt
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
|
-
end
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
Pry::Commands.add_command(Pry::Command::ShellMode)
|
27
|
+
Pry::Commands.alias_command 'file-mode', 'shell-mode'
|
28
|
+
end
|
25
29
|
end
|
@@ -1,81 +1,93 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Pry
|
4
|
-
class Command
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
4
|
+
class Command
|
5
|
+
class ShowDoc < Command::ShowInfo
|
6
|
+
include Pry::Helpers::DocumentationHelpers
|
7
|
+
|
8
|
+
match 'show-doc'
|
9
|
+
group 'Introspection'
|
10
|
+
description 'Show the documentation for a method or class.'
|
11
|
+
|
12
|
+
banner <<-BANNER
|
13
|
+
Usage: show-doc [OPTIONS] [METH]
|
14
|
+
Aliases: ?
|
15
|
+
|
16
|
+
Show the documentation for a method or class. Tries instance methods first and
|
17
|
+
then methods by default.
|
18
|
+
|
19
|
+
show-doc hi_method # docs for hi_method
|
20
|
+
show-doc Pry # for Pry class
|
21
|
+
show-doc Pry -a # for all definitions of Pry class (all monkey patches)
|
22
|
+
BANNER
|
23
|
+
|
24
|
+
def process
|
25
|
+
super
|
26
|
+
|
27
|
+
output.puts(
|
28
|
+
"\nWARNING: the show-doc command is deprecated. It will be removed " \
|
29
|
+
"from future Pry versions.\nPlease use 'show-source' with the -d " \
|
30
|
+
"(or --doc) switch instead\nExample: show-source #{obj_name} -d"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
# The docs for code_object prepared for display.
|
35
|
+
def content_for(code_object)
|
36
|
+
Code.new(
|
37
|
+
render_doc_markup_for(code_object),
|
38
|
+
start_line_for(code_object),
|
39
|
+
:text
|
40
|
+
).with_line_numbers(use_line_numbers?).to_s
|
41
|
+
end
|
29
42
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
# process the markup (if necessary) and apply colors
|
44
|
+
def render_doc_markup_for(code_object)
|
45
|
+
docs = docs_for(code_object)
|
46
|
+
|
47
|
+
if code_object.command?
|
48
|
+
# command '--help' shouldn't use markup highlighting
|
49
|
+
docs
|
50
|
+
else
|
51
|
+
if docs.empty?
|
52
|
+
raise CommandError, "No docs found for: #{obj_name || 'current context'}"
|
53
|
+
end
|
54
|
+
|
55
|
+
process_comment_markup(docs)
|
42
56
|
end
|
43
|
-
process_comment_markup(docs)
|
44
57
|
end
|
45
|
-
end
|
46
58
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
# Return docs for the code_object, adjusting for whether the code_object
|
60
|
+
# has yard docs available, in which case it returns those.
|
61
|
+
# (note we only have to check yard docs for modules since they can
|
62
|
+
# have multiple docs, but methods can only be doc'd once so we
|
63
|
+
# dont need to check them)
|
64
|
+
def docs_for(code_object)
|
65
|
+
if code_object.module_with_yard_docs?
|
66
|
+
# yard docs
|
67
|
+
code_object.yard_doc
|
68
|
+
else
|
69
|
+
# normal docs (i.e comments above method/module/command)
|
70
|
+
code_object.doc
|
71
|
+
end
|
59
72
|
end
|
60
|
-
end
|
61
73
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
74
|
+
# Which sections to include in the 'header', can toggle: :owner,
|
75
|
+
# :signature and visibility.
|
76
|
+
def header_options
|
77
|
+
super.merge signature: true
|
78
|
+
end
|
67
79
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
80
|
+
# figure out start line of docs by back-calculating based on
|
81
|
+
# number of lines in the comment and the start line of the code_object
|
82
|
+
# @return [Fixnum] start line of docs
|
83
|
+
def start_line_for(code_object)
|
84
|
+
return 1 if code_object.command? || opts.present?(:'base-one')
|
85
|
+
return 1 unless code_object.source_line
|
74
86
|
|
75
|
-
|
87
|
+
code_object.source_line - code_object.doc.lines.count
|
88
|
+
end
|
76
89
|
end
|
77
|
-
end
|
78
90
|
|
79
|
-
|
80
|
-
|
91
|
+
Pry::Commands.add_command(Pry::Command::ShowDoc)
|
92
|
+
end
|
81
93
|
end
|