pry 0.10.3 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +439 -16
  3. data/LICENSE +1 -1
  4. data/README.md +362 -302
  5. data/bin/pry +4 -7
  6. data/lib/pry/basic_object.rb +10 -0
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +84 -97
  10. data/lib/pry/code/code_file.rb +37 -26
  11. data/lib/pry/code/code_range.rb +7 -5
  12. data/lib/pry/code/loc.rb +26 -13
  13. data/lib/pry/code.rb +42 -31
  14. data/lib/pry/code_object.rb +53 -28
  15. data/lib/pry/color_printer.rb +46 -35
  16. data/lib/pry/command.rb +197 -369
  17. data/lib/pry/command_set.rb +89 -114
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +85 -72
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -46
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +62 -54
  27. data/lib/pry/commands/cd.rb +40 -35
  28. data/lib/pry/commands/change_inspector.rb +29 -22
  29. data/lib/pry/commands/change_prompt.rb +48 -23
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -131
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +23 -34
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  36. data/lib/pry/commands/edit.rb +185 -157
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -16
  40. data/lib/pry/commands/find_method.rb +168 -162
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +151 -149
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +35 -28
  47. data/lib/pry/commands/ls/constants.rb +59 -31
  48. data/lib/pry/commands/ls/formatter.rb +42 -36
  49. data/lib/pry/commands/ls/globals.rb +38 -36
  50. data/lib/pry/commands/ls/grep.rb +17 -15
  51. data/lib/pry/commands/ls/instance_vars.rb +29 -28
  52. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  53. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  54. data/lib/pry/commands/ls/local_names.rb +26 -24
  55. data/lib/pry/commands/ls/local_vars.rb +38 -30
  56. data/lib/pry/commands/ls/ls_entity.rb +47 -52
  57. data/lib/pry/commands/ls/methods.rb +49 -51
  58. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  59. data/lib/pry/commands/ls/self_methods.rb +23 -21
  60. data/lib/pry/commands/ls.rb +124 -103
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +92 -82
  63. data/lib/pry/commands/pry_backtrace.rb +22 -17
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +60 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -42
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +56 -29
  71. data/lib/pry/commands/shell_mode.rb +22 -18
  72. data/lib/pry/commands/show_doc.rb +80 -70
  73. data/lib/pry/commands/show_info.rb +194 -155
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +110 -42
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +20 -16
  79. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  80. data/lib/pry/commands/watch_expression.rb +89 -84
  81. data/lib/pry/commands/whereami.rb +156 -141
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +310 -20
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +22 -9
  90. data/lib/pry/editor.rb +56 -34
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +13 -18
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +20 -62
  96. data/lib/pry/helpers/command_helpers.rb +52 -62
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -12
  98. data/lib/pry/helpers/options_helpers.rb +15 -8
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +96 -85
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +81 -55
  104. data/lib/pry/hooks.rb +60 -110
  105. data/lib/pry/indent.rb +74 -68
  106. data/lib/pry/input_completer.rb +199 -158
  107. data/lib/pry/input_lock.rb +7 -10
  108. data/lib/pry/inspector.rb +36 -24
  109. data/lib/pry/last_exception.rb +45 -45
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/method/patcher.rb +14 -8
  112. data/lib/pry/method/weird_method_locator.rb +79 -45
  113. data/lib/pry/method.rb +178 -124
  114. data/lib/pry/object_path.rb +37 -28
  115. data/lib/pry/output.rb +102 -16
  116. data/lib/pry/pager.rb +187 -174
  117. data/lib/pry/prompt.rb +213 -25
  118. data/lib/pry/pry_class.rb +119 -98
  119. data/lib/pry/pry_instance.rb +261 -224
  120. data/lib/pry/repl.rb +83 -29
  121. data/lib/pry/repl_file_loader.rb +27 -22
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/LICENSE +20 -0
  124. data/lib/pry/slop/commands.rb +190 -0
  125. data/lib/pry/slop/option.rb +210 -0
  126. data/lib/pry/slop.rb +672 -0
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable/evalable.rb +24 -0
  130. data/lib/pry/testable/mockable.rb +22 -0
  131. data/lib/pry/testable/pry_tester.rb +88 -0
  132. data/lib/pry/testable/utility.rb +34 -0
  133. data/lib/pry/testable/variables.rb +52 -0
  134. data/lib/pry/testable.rb +68 -0
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +20 -0
  137. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
  138. data/lib/pry/wrapped_module.rb +68 -63
  139. data/lib/pry.rb +133 -149
  140. metadata +58 -69
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gist.rb +0 -101
  147. data/lib/pry/commands/install_command.rb +0 -53
  148. data/lib/pry/commands/list_prompts.rb +0 -35
  149. data/lib/pry/commands/simple_prompt.rb +0 -22
  150. data/lib/pry/commands.rb +0 -6
  151. data/lib/pry/config/behavior.rb +0 -139
  152. data/lib/pry/config/convenience.rb +0 -25
  153. data/lib/pry/config/default.rb +0 -161
  154. data/lib/pry/history_array.rb +0 -121
  155. data/lib/pry/plugins.rb +0 -103
  156. data/lib/pry/rbx_path.rb +0 -22
  157. data/lib/pry/rubygem.rb +0 -82
  158. data/lib/pry/terminal.rb +0 -79
  159. data/lib/pry/test/helper.rb +0 -170
@@ -1,26 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat
3
- class AbstractFormatter
4
- include Pry::Helpers::CommandHelpers
5
- include Pry::Helpers::BaseHelpers
4
+ class Command
5
+ class Cat
6
+ class AbstractFormatter
7
+ include Pry::Helpers::CommandHelpers
8
+ include Pry::Helpers::BaseHelpers
6
9
 
7
- private
8
- def decorate(content)
9
- content.code_type = code_type
10
- content.between(*between_lines).
11
- with_line_numbers(use_line_numbers?).highlighted
12
- end
10
+ private
13
11
 
14
- def code_type
15
- opts[:type] || :ruby
16
- end
12
+ def decorate(content)
13
+ content.code_type = code_type
14
+ content.between(*between_lines)
15
+ .with_line_numbers(use_line_numbers?).highlighted
16
+ end
17
17
 
18
- def use_line_numbers?
19
- opts.present?(:'line-numbers') || opts.present?(:ex)
20
- end
18
+ def code_type
19
+ opts[:type] || :ruby
20
+ end
21
+
22
+ def use_line_numbers?
23
+ opts.present?(:'line-numbers') || opts.present?(:ex)
24
+ end
21
25
 
22
- def between_lines
23
- [opts[:start] || 1, opts[:end] || -1]
26
+ def between_lines
27
+ [opts[:start] || 1, opts[:end] || -1]
28
+ end
24
29
  end
25
30
  end
26
31
  end
@@ -1,77 +1,90 @@
1
- class Pry
2
- class Command::Cat
3
- class ExceptionFormatter < AbstractFormatter
4
- attr_reader :ex
5
- attr_reader :opts
6
- attr_reader :_pry_
7
-
8
- def initialize(exception, _pry_, opts)
9
- @ex = exception
10
- @opts = opts
11
- @_pry_ = _pry_
12
- end
13
-
14
- def format
15
- check_for_errors
16
- set_file_and_dir_locals(backtrace_file, _pry_, _pry_.current_context)
17
- code = decorate(Pry::Code.from_file(backtrace_file).
18
- between(*start_and_end_line_for_code_window).
19
- with_marker(backtrace_line))
20
- "#{header}#{code}"
21
- end
22
-
23
- private
24
-
25
- def code_window_size
26
- _pry_.config.default_window_size || 5
27
- end
28
-
29
- def backtrace_level
30
- return @backtrace_level if @backtrace_level
31
-
32
- bl = if opts[:ex].nil?
33
- ex.bt_index
34
- else
35
- ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
36
- end
37
-
38
- increment_backtrace_level
39
- @backtrace_level = bl
40
- end
41
-
42
- def increment_backtrace_level
43
- ex.inc_bt_index
44
- end
45
-
46
- def backtrace_file
47
- Array(ex.bt_source_location_for(backtrace_level)).first
48
- end
49
-
50
- def backtrace_line
51
- Array(ex.bt_source_location_for(backtrace_level)).last
52
- end
53
-
54
- def check_for_errors
55
- raise CommandError, "No exception found." unless ex
56
- raise CommandError, "The given backtrace level is out of bounds." unless backtrace_file
57
- end
1
+ # frozen_string_literal: true
58
2
 
59
- def start_and_end_line_for_code_window
60
- start_line = backtrace_line - code_window_size
61
- start_line = 1 if start_line < 1
62
-
63
- [start_line, backtrace_line + code_window_size]
64
- end
65
-
66
- def header
67
- unindent %{
68
- #{Helpers::Text.bold 'Exception:'} #{ex.class}: #{ex.message}
69
- --
70
- #{Helpers::Text.bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{Helpers::Text.bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
71
-
72
- }
3
+ class Pry
4
+ class Command
5
+ class Cat
6
+ class ExceptionFormatter < AbstractFormatter
7
+ attr_reader :ex
8
+ attr_reader :opts
9
+ attr_reader :pry_instance
10
+ include Pry::Helpers::Text
11
+
12
+ def initialize(exception, pry_instance, opts)
13
+ @ex = exception
14
+ @opts = opts
15
+ @pry_instance = pry_instance
16
+ end
17
+
18
+ def format
19
+ check_for_errors
20
+ set_file_and_dir_locals(
21
+ backtrace_file, pry_instance, pry_instance.current_context
22
+ )
23
+ code = decorate(
24
+ Pry::Code.from_file(backtrace_file)
25
+ .between(*start_and_end_line_for_code_window)
26
+ .with_marker(backtrace_line)
27
+ )
28
+ "#{header}#{code}"
29
+ end
30
+
31
+ private
32
+
33
+ def code_window_size
34
+ pry_instance.config.default_window_size || 5
35
+ end
36
+
37
+ def backtrace_level
38
+ @backtrace_level ||=
39
+ begin
40
+ bl =
41
+ if opts[:ex].nil?
42
+ ex.bt_index
43
+ else
44
+ ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
45
+ end
46
+
47
+ increment_backtrace_level
48
+ bl
49
+ end
50
+ end
51
+
52
+ def increment_backtrace_level
53
+ ex.inc_bt_index
54
+ end
55
+
56
+ def backtrace_file
57
+ Array(ex.bt_source_location_for(backtrace_level)).first
58
+ end
59
+
60
+ def backtrace_line
61
+ Array(ex.bt_source_location_for(backtrace_level)).last
62
+ end
63
+
64
+ def check_for_errors
65
+ raise CommandError, "No exception found." unless ex
66
+ return if backtrace_file
67
+
68
+ raise CommandError, "The given backtrace level is out of bounds."
69
+ end
70
+
71
+ def start_and_end_line_for_code_window
72
+ start_line = backtrace_line - code_window_size
73
+ start_line = 1 if start_line < 1
74
+
75
+ [start_line, backtrace_line + code_window_size]
76
+ end
77
+
78
+ def header
79
+ unindent(
80
+ "#{bold 'Exception:'} #{ex.class}: #{ex.message}\n" \
81
+ "--\n" \
82
+ "#{bold('From:')} #{backtrace_file}:#{backtrace_line} @ " \
83
+ "#{bold("level: #{backtrace_level}")} of backtrace " \
84
+ "(of #{ex.backtrace.size - 1}).\n\n"
85
+ )
86
+ end
73
87
  end
74
-
75
88
  end
76
89
  end
77
90
  end
@@ -1,65 +1,75 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat
3
- class FileFormatter < AbstractFormatter
4
- attr_reader :file_with_embedded_line
5
- attr_reader :opts
6
- attr_reader :_pry_
4
+ class Command
5
+ class Cat
6
+ class FileFormatter < AbstractFormatter
7
+ attr_reader :file_with_embedded_line
8
+ attr_reader :opts
9
+ attr_reader :pry_instance
7
10
 
8
- def initialize(file_with_embedded_line, _pry_, opts)
9
- @file_with_embedded_line = file_with_embedded_line
10
- @opts = opts
11
- @_pry_ = _pry_
12
- @code_from_file = Pry::Code.from_file(file_name)
13
- end
11
+ def initialize(file_with_embedded_line, pry_instance, opts)
12
+ unless file_with_embedded_line
13
+ raise CommandError, "Must provide a filename, --in, or --ex."
14
+ end
14
15
 
15
- def format
16
- raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
16
+ @file_with_embedded_line = file_with_embedded_line
17
+ @opts = opts
18
+ @pry_instance = pry_instance
19
+ @code_from_file = Pry::Code.from_file(file_name)
20
+ end
17
21
 
18
- set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
19
- decorate(@code_from_file)
20
- end
22
+ def format
23
+ set_file_and_dir_locals(file_name, pry_instance, pry_instance.current_context)
24
+ decorate(@code_from_file)
25
+ end
21
26
 
22
- def file_and_line
23
- file_name, line_num = file_with_embedded_line.split(/:(?!\/|\\)/)
27
+ def file_and_line
28
+ file_name, line_num = file_with_embedded_line.split(%r{:(?!/|\\)})
24
29
 
25
- [file_name, line_num ? line_num.to_i : nil]
26
- end
30
+ [file_name, line_num ? line_num.to_i : nil]
31
+ end
27
32
 
28
- private
33
+ private
29
34
 
30
- def file_name
31
- file_and_line.first
32
- end
35
+ def file_name
36
+ file_and_line.first
37
+ end
33
38
 
34
- def line_number
35
- file_and_line.last
36
- end
39
+ def line_number
40
+ file_and_line.last
41
+ end
37
42
 
38
- def code_window_size
39
- _pry_.config.default_window_size || 7
40
- end
43
+ def code_window_size
44
+ pry_instance.config.default_window_size || 7
45
+ end
41
46
 
42
- def decorate(content)
43
- line_number ? super.around(line_number, code_window_size) : super
44
- end
47
+ def decorate(content)
48
+ if line_number
49
+ super(content.around(line_number, code_window_size))
50
+ else
51
+ super
52
+ end
53
+ end
45
54
 
46
- def code_type
47
- opts[:type] || detect_code_type_from_file(file_name)
48
- end
55
+ def code_type
56
+ opts[:type] || detect_code_type_from_file(file_name)
57
+ end
49
58
 
50
- def detect_code_type_from_file(file_name)
51
- code_type = @code_from_file.code_type
59
+ def detect_code_type_from_file(file_name)
60
+ code_type = @code_from_file.code_type
52
61
 
53
- if code_type == :unknown
54
- name = File.basename(file_name).split('.', 2).first
55
- case name
56
- when "Rakefile", "Gemfile"
57
- :ruby
62
+ if code_type == :unknown
63
+ name = File.basename(file_name).split('.', 2).first
64
+ case name
65
+ when "Rakefile", "Gemfile"
66
+ :ruby
67
+ else
68
+ :text
69
+ end
58
70
  else
59
- :text
71
+ code_type
60
72
  end
61
- else
62
- code_type
63
73
  end
64
74
  end
65
75
  end
@@ -1,42 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat
3
- class InputExpressionFormatter < AbstractFormatter
4
- attr_accessor :input_expressions
5
- attr_accessor :opts
6
-
7
- def initialize(input_expressions, opts)
8
- @input_expressions = input_expressions
9
- @opts = opts
10
- end
4
+ class Command
5
+ class Cat
6
+ class InputExpressionFormatter < AbstractFormatter
7
+ attr_accessor :input_expressions
8
+ attr_accessor :opts
9
+
10
+ def initialize(input_expressions, opts)
11
+ @input_expressions = input_expressions
12
+ @opts = opts
13
+ end
11
14
 
12
- def format
13
- raise CommandError, "No input expressions!" if numbered_input_items.length < 1
15
+ def format
16
+ raise CommandError, "No input expressions!" if numbered_input_items.empty?
14
17
 
15
- if numbered_input_items.length > 1
16
- content = ""
17
- numbered_input_items.each do |i, s|
18
- content << "#{Helpers::Text.bold(i.to_s)}:\n" << decorate(Pry::Code(s).with_indentation(2)).to_s
19
- end
18
+ if numbered_input_items.length > 1
19
+ content = ''
20
+ numbered_input_items.each do |i, s|
21
+ content += "#{Helpers::Text.bold(i.to_s)}:\n"
22
+ content += decorate(Pry::Code(s).with_indentation(2)).to_s
23
+ end
20
24
 
21
- content
22
- else
23
- decorate(Pry::Code(selected_input_items.first))
25
+ content
26
+ else
27
+ decorate(Pry::Code(selected_input_items.first))
28
+ end
24
29
  end
25
- end
26
30
 
27
- private
31
+ private
28
32
 
29
- def selected_input_items
30
- input_expressions[normalized_expression_range] || []
31
- end
33
+ def selected_input_items
34
+ input_expressions[normalized_expression_range] || []
35
+ end
32
36
 
33
- def numbered_input_items
34
- @numbered_input_items ||= normalized_expression_range.zip(selected_input_items).
35
- reject { |_, s| s.nil? || s == "" }
36
- end
37
+ def numbered_input_items
38
+ @numbered_input_items ||= normalized_expression_range.zip(selected_input_items)
39
+ .reject { |_, s| s.nil? || s == "" }
40
+ end
37
41
 
38
- def normalized_expression_range
39
- absolute_index_range(opts[:i], input_expressions.length)
42
+ def normalized_expression_range
43
+ absolute_index_range(opts[:i], input_expressions.count)
44
+ end
40
45
  end
41
46
  end
42
47
  end
@@ -1,62 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Cat < Pry::ClassCommand
3
- require 'pry/commands/cat/abstract_formatter.rb'
4
- require 'pry/commands/cat/input_expression_formatter.rb'
5
- require 'pry/commands/cat/exception_formatter.rb'
6
- require 'pry/commands/cat/file_formatter.rb'
7
-
8
- match 'cat'
9
- group 'Input and Output'
10
- description "Show code from a file, Pry's input buffer, or the last exception."
11
-
12
- banner <<-'BANNER'
13
- Usage: cat FILE
14
- cat --ex [STACK_INDEX]
15
- cat --in [INPUT_INDEX_OR_RANGE]
16
-
17
- `cat` is capable of showing part or all of a source file, the context of the
18
- last exception, or an expression from Pry's input history.
19
-
20
- `cat --ex` defaults to showing the lines surrounding the location of the last
21
- exception. Invoking it more than once travels up the exception's backtrace, and
22
- providing a number shows the context of the given index of the backtrace.
23
- BANNER
24
-
25
- def options(opt)
26
- opt.on :ex, "Show the context of the last exception", :optional_argument => true, :as => Integer
27
- opt.on :i, :in, "Show one or more entries from Pry's expression history", :optional_argument => true, :as => Range, :default => -5..-1
28
- opt.on :s, :start, "Starting line (defaults to the first line)", :optional_argument => true, :as => Integer
29
- opt.on :e, :end, "Ending line (defaults to the last line)", :optional_argument => true, :as => Integer
30
- opt.on :l, :'line-numbers', "Show line numbers"
31
- opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", :argument => true, :as => Symbol
32
- end
4
+ class Command
5
+ class Cat < Pry::ClassCommand
6
+ match 'cat'
7
+ group 'Input and Output'
8
+ description "Show code from a file, Pry's input buffer, or the last exception."
33
9
 
34
- def process
35
- output = case
36
- when opts.present?(:ex)
37
- ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format
38
- when opts.present?(:in)
39
- InputExpressionFormatter.new(_pry_.input_array, opts).format
40
- else
41
- FileFormatter.new(args.first, _pry_, opts).format
42
- end
43
-
44
- _pry_.pager.page output
45
- end
10
+ banner <<-'BANNER'
11
+ Usage: cat FILE
12
+ cat --ex [STACK_INDEX]
13
+ cat --in [INPUT_INDEX_OR_RANGE]
46
14
 
47
- def complete(search)
48
- super | load_path_completions
49
- end
15
+ `cat` is capable of showing part or all of a source file, the context of the
16
+ last exception, or an expression from Pry's input history.
17
+
18
+ `cat --ex` defaults to showing the lines surrounding the location of the last
19
+ exception. Invoking it more than once travels up the exception's backtrace, and
20
+ providing a number shows the context of the given index of the backtrace.
21
+ BANNER
22
+
23
+ def options(opt)
24
+ opt.on :ex, "Show the context of the last exception",
25
+ optional_argument: true, as: Integer
26
+ opt.on :i, :in, "Show one or more entries from Pry's expression history",
27
+ optional_argument: true, as: Range, default: -5..-1
28
+ opt.on :s, :start, "Starting line (defaults to the first line)",
29
+ optional_argument: true, as: Integer
30
+ opt.on :e, :end, "Ending line (defaults to the last line)",
31
+ optional_argument: true, as: Integer
32
+ opt.on :l, :'line-numbers', "Show line numbers"
33
+ opt.on :t, :type, "The file type for syntax highlighting " \
34
+ "(e.g., 'ruby' or 'python')",
35
+ argument: true, as: Symbol
36
+ end
37
+
38
+ def process
39
+ output =
40
+ if opts.present?(:ex)
41
+ ExceptionFormatter.new(
42
+ pry_instance.last_exception, pry_instance, opts
43
+ ).format
44
+ elsif opts.present?(:in)
45
+ InputExpressionFormatter.new(pry_instance.input_ring, opts).format
46
+ else
47
+ FileFormatter.new(args.first, pry_instance, opts).format
48
+ end
50
49
 
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
- }
50
+ pry_instance.pager.page output
51
+ end
52
+
53
+ def complete(search)
54
+ super | load_path_completions
55
+ end
56
+
57
+ def load_path_completions
58
+ $LOAD_PATH.flat_map do |path|
59
+ Dir[path + '/**/*'].map do |f|
60
+ next if File.directory?(f)
61
+
62
+ f.sub!(path + '/', '')
63
+ end
64
+ end
57
65
  end
58
66
  end
59
- end
60
67
 
61
- Pry::Commands.add_command(Pry::Command::Cat)
68
+ Pry::Commands.add_command(Pry::Command::Cat)
69
+ end
62
70
  end
@@ -1,41 +1,46 @@
1
- class Pry
2
- class Command::Cd < Pry::ClassCommand
3
- match 'cd'
4
- group 'Context'
5
- description 'Move into a new context (object or scope).'
6
-
7
- banner <<-'BANNER'
8
- Usage: cd [OPTIONS] [--help]
9
-
10
- Move into new context (object or scope). As in UNIX shells use `cd ..` to go
11
- back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
12
- scopes. Complex syntax (e.g `cd ../@x/@y`) also supported.
13
-
14
- cd @x
15
- cd ..
16
- cd /
17
- cd -
18
-
19
- https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
20
- BANNER
21
-
22
- def process
23
- state.old_stack ||= []
1
+ # frozen_string_literal: true
24
2
 
25
- if arg_string.strip == "-"
26
- unless state.old_stack.empty?
27
- _pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack
28
- end
29
- else
30
- stack = ObjectPath.new(arg_string, _pry_.binding_stack).resolve
31
-
32
- if stack && stack != _pry_.binding_stack
33
- state.old_stack = _pry_.binding_stack
34
- _pry_.binding_stack = stack
3
+ class Pry
4
+ class Command
5
+ class Cd < Pry::ClassCommand
6
+ match 'cd'
7
+ group 'Context'
8
+ description 'Move into a new context (object or scope).'
9
+
10
+ banner <<-'BANNER'
11
+ Usage: cd [OPTIONS] [--help]
12
+
13
+ Move into new context (object or scope). As in UNIX shells use `cd ..` to go
14
+ back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
15
+ scopes. Complex syntax (e.g `cd ../@x/@y`) also supported.
16
+
17
+ cd @x
18
+ cd ..
19
+ cd /
20
+ cd -
21
+
22
+ https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
23
+ BANNER
24
+
25
+ def process
26
+ state.old_stack ||= []
27
+
28
+ if arg_string.strip == "-"
29
+ unless state.old_stack.empty?
30
+ pry_instance.binding_stack, state.old_stack =
31
+ state.old_stack, pry_instance.binding_stack
32
+ end
33
+ else
34
+ stack = ObjectPath.new(arg_string, pry_instance.binding_stack).resolve
35
+
36
+ if stack && stack != pry_instance.binding_stack
37
+ state.old_stack = pry_instance.binding_stack
38
+ pry_instance.binding_stack = stack
39
+ end
35
40
  end
36
41
  end
37
42
  end
38
- end
39
43
 
40
- Pry::Commands.add_command(Pry::Command::Cd)
44
+ Pry::Commands.add_command(Pry::Command::Cd)
45
+ end
41
46
  end
@@ -1,27 +1,34 @@
1
- class Pry::Command::ChangeInspector < Pry::ClassCommand
2
- match 'change-inspector'
3
- group 'Input and Output'
4
- description 'Change the current inspector proc.'
5
- command_options argument_required: true
6
- banner <<-BANNER
7
- Usage: change-inspector NAME
1
+ # frozen_string_literal: true
8
2
 
9
- Change the proc used to print return values. See list-inspectors for a list
10
- of available procs and a short description of what each one does.
11
- BANNER
3
+ class Pry
4
+ class Command
5
+ class ChangeInspector < Pry::ClassCommand
6
+ match 'change-inspector'
7
+ group 'Input and Output'
8
+ description 'Change the current inspector proc.'
9
+ command_options argument_required: true
10
+ banner <<-BANNER
11
+ Usage: change-inspector NAME
12
12
 
13
- def process(inspector)
14
- if inspector_map.key?(inspector)
15
- _pry_.print = inspector_map[inspector][:value]
16
- output.puts "Switched to the '#{inspector}' inspector!"
17
- else
18
- raise Pry::CommandError, "'#{inspector}' isn't a known inspector!"
19
- end
20
- end
13
+ Change the proc used to print return values. See list-inspectors for a list
14
+ of available procs and a short description of what each one does.
15
+ BANNER
16
+
17
+ def process(inspector)
18
+ unless inspector_map.key?(inspector)
19
+ raise Pry::CommandError, "'#{inspector}' isn't a known inspector!"
20
+ end
21
21
 
22
- private
23
- def inspector_map
24
- Pry::Inspector::MAP
22
+ pry_instance.print = inspector_map[inspector][:value]
23
+ output.puts "Switched to the '#{inspector}' inspector!"
24
+ end
25
+
26
+ private
27
+
28
+ def inspector_map
29
+ Pry::Inspector::MAP
30
+ end
31
+ Pry::Commands.add_command(self)
32
+ end
25
33
  end
26
- Pry::Commands.add_command(self)
27
34
  end