pry 0.10.2-i386-mingw32 → 1.0.0.pre1-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
data/TODO ADDED
@@ -0,0 +1,117 @@
1
+ 0.9.5
2
+ * include method visiblity in show-doc and stat output
3
+ * tempfile should end in .rb (for edit -t)
4
+ * ls output should not be in array format
5
+ * exceptions should allow access to previous items in the backtrace
6
+ * input should allow multiple objects which are switched to automatically when EOF is reached on the preceding one
7
+ * pry -r should happen in pry
8
+ * more plugin-related commands in pry - see installed ones, see activated ones, see available on rubygems
9
+ * should also allow plugins be explicitly activated as a command line option
10
+ * should not raise if plugin activation fails (should show warning instead)
11
+ * more documentation on CommandContext, etc and also command helpers
12
+ * fix history saving (should not save all of Readline::HISTORY, but only what changed)
13
+ * prevent blank lines going to Readline::HISTORY
14
+ * ensure that cat --ex emulates the `whereami` format - includes line numbers and formatted the same, etc
15
+ * rename inp and out to _inp_ and _out_ otherwise than can overwrite locals by those names when debugging (not good)
16
+ * add source file to stat command
17
+ * make plugins use hash instead of array
18
+ * ensure edit -t has 'edit' alias (no parameters) and dumps eval_string into buffer
19
+ * whitelist exceptions
20
+ * hooks system
21
+ * jruby shell command support
22
+
23
+ 0.9.3
24
+ * hist command now excludes last line of input (the command invocation itself)
25
+ * hist now has `history` alias
26
+ * `pry -r` requires now happen after plugin loading (so as not to interfere with
27
+ * new Pry.config.disable_auto_reload option, for turning off auto reloading by edit-method and related
28
+ * add better error messages for `cd` command
29
+ * add command_prefix
30
+ * change some command names to include hyphen, e.g version => pry-version, install => install-command
31
+ * do cat --ex and edit --ex
32
+ * add reload-method
33
+ * fixed exotic object regression - BasicObject.new etc now return "=> unknown"
34
+ * converted: import => import-set, version => pry-version, install => install-command
35
+ * fix show-doc bug for ruby 1.8 and Kernel.fork
36
+ * edit -t (opens a temporary file and evals it in current context when closed)
37
+
38
+ 0.9.0
39
+ Major features
40
+ --------------
41
+ * Restructure command system and helpers (almost complete)
42
+ * Delete unnecessary commands, add a couple of new ones (e.g amend-line)
43
+ * Readline history
44
+ * Plugin support
45
+ * Support Rubinius core methods
46
+ * in[] and out[] arrays
47
+ * Improve test coverage (test some commands, etc)
48
+
49
+ Minor changes
50
+ -------------
51
+ * improve edit-method support for various editors
52
+ * ensure all commands have appropriate error handing and informative error messages
53
+ * show-doc should include signature of method
54
+
55
+ Optional
56
+ --------
57
+ * multi-line readline support
58
+
59
+
60
+ 0.8.0
61
+ * allow #{} interpolation of all commands
62
+ * update documentation! new commands and features and change in behaviour of `run`
63
+ * add ; at end of line to suppress return value output
64
+ * Remove message spam (before/after hooks)
65
+ * stop commands returning a value
66
+ * use `redo` in the r() method when encounter a command
67
+ * shell functionality should just use system(), but redirect in and
68
+ out to Pry.input and Pry.output by reassining $stdin and $stdout
69
+ for duration of block.
70
+ * basicobject and no to_s/inspect support
71
+ * fix documentation, support rdoc and yard properly
72
+ * only load Ripper if 1.9 AND MRI (support jruby 1.9, using
73
+ RubyParser)
74
+ * shell commands invokable file .<command>
75
+ * supercharge cat-file so it can syntax highlight sourcecode files
76
+
77
+
78
+ 0.7.0
79
+ * add pry-doc support with syntax highlighting for docs
80
+ * add 'mj' option to ls (restrict to singleton methods)
81
+ * add _ex_ local to hold last exception raised in an exception
82
+
83
+ 0.6.8
84
+ * add whereami command, a la the `ir_b` gem
85
+ * make .pryrc be loaded by run-time pry sessions
86
+
87
+ 0.6.7
88
+ * color support
89
+ * --simple-prompt for pry commandline
90
+ * -I mode for pry commandline
91
+ * --color mode for pry commandline
92
+ * clean up requires (put them all in one place)
93
+ * simple-prompt command and toggle-color commandd.
94
+
95
+ 0.6.1
96
+ * !@ command alias for exit_all
97
+ * `cd /` for breaking out to pry top level (jump-to 0)
98
+ * made `-e` option work in a more effective way for `pry` command line invocation
99
+ * exit and exit-all commands now accept a parameter, this parameter becomes the return value of repl()
100
+ * `command` method from CommandBase now accepts a :keep_retval arg that determines if command value is returned to pry session or just `nil` (`nil` was old behaviour)
101
+ * tests for new :keep_retval and exit-all/exit behaviour; :keep_retval will remain undocumented.
102
+
103
+ 0.5.0 release:
104
+ * !!!! UPDATE DOCUMENTATION !!!!
105
+ * Use clipped version of Pry.view() for large objects
106
+ * Exit Pry session on ^d
107
+ * Use Shellwords for breaking up parameters to pry commands
108
+ * Use OptionParser to parse options for default pry commands
109
+ * Add version command
110
+ * Refactor 'status' command: add current method info
111
+ * Add meth_name_from_binding utility lambda to commands.rb
112
+ * Add -M, -m, -v(erbose), -a(ll), -s(uper), -l(ocals), -i(ivars), -k(klass vars) options to ls
113
+ * add -i(nstance) option to show-method
114
+ * add --help option to most commands
115
+ * Get rid of ls_method and ls_imethods (subsumed by more powerful ls)
116
+ * Get rid of show_idoc and show_imethod
117
+ * Add special eval-file command that evals target file in current context
data/lib/pry.rb CHANGED
@@ -1,13 +1,10 @@
1
- # (C) John Mair (banisterfiend) 2013
1
+ # (C) John Mair (banisterfiend) 2011
2
2
  # MIT License
3
3
  #
4
- require 'pp'
5
4
 
6
- require 'pry/input_lock'
7
- require 'pry/exceptions'
5
+ require 'pp'
8
6
  require 'pry/helpers/base_helpers'
9
7
  require 'pry/hooks'
10
- require 'forwardable'
11
8
 
12
9
  class Pry
13
10
  # The default hooks - display messages when beginning and ending Pry sessions.
@@ -17,11 +14,42 @@ class Pry
17
14
  end
18
15
 
19
16
  # The default print
20
- DEFAULT_PRINT = proc do |output, value, _pry_|
21
- _pry_.pager.open do |pager|
22
- pager.print _pry_.config.output_prefix
23
- Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
17
+ DEFAULT_PRINT = proc do |output, value|
18
+ output_with_default_format(output, value, :hashrocket => true)
19
+ end
20
+
21
+ def self.output_with_default_format(output, value, options = {})
22
+ stringified = begin
23
+ value.pretty_inspect
24
+ rescue RescuableException
25
+ nil
26
+ end
27
+
28
+ unless String === stringified
29
+ # Read the class name off of the singleton class to provide a default
30
+ # inspect.
31
+ eig = class << value; self; end
32
+ klass = Pry::Method.safe_send(eig, :ancestors).first
33
+ id = value.__id__.to_s(16) rescue 0
34
+ stringified = "#<#{klass}:0x#{id}>"
24
35
  end
36
+
37
+ nonce = rand(0x100000000).to_s(16) # whatever
38
+
39
+ stringified.gsub!(/#</, "%<#{nonce}")
40
+ # Don't recolorize output with color (for cucumber, looksee, etc.) [Issue #751]
41
+ colorized = if stringified =~ /\e\[/
42
+ stringified
43
+ else
44
+ Helpers::BaseHelpers.colorize_code(stringified)
45
+ end
46
+
47
+ # avoid colour-leak from CodeRay and any of the users' previous output
48
+ colorized = colorized.sub(/(\n*)\z/, "\e[0m\\1") if Pry.color
49
+
50
+ result = colorized.gsub(/%<(.*?)#{nonce}/, '#<\1')
51
+ result = "=> #{result}"if options[:hashrocket]
52
+ Helpers::BaseHelpers.stagger_output(result, output)
25
53
  end
26
54
 
27
55
  # may be convenient when working with enormous objects and
@@ -36,7 +64,7 @@ class Pry
36
64
 
37
65
  # useful when playing with truly enormous objects
38
66
  CLIPPED_PRINT = proc do |output, value|
39
- output.puts Pry.view_clip(value, id: true)
67
+ output.puts Pry.view_clip(value)
40
68
  end
41
69
 
42
70
  # Will only show the first line of the backtrace
@@ -54,36 +82,32 @@ class Pry
54
82
  # The default prompt; includes the target and nesting level
55
83
  DEFAULT_PROMPT = [
56
84
  proc { |target_self, nest_level, pry|
57
- "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
85
+ "[#{pry.input_array.size}] #{Pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
58
86
  },
59
87
 
60
88
  proc { |target_self, nest_level, pry|
61
- "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
89
+ "[#{pry.input_array.size}] #{Pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
62
90
  }
63
91
  ]
64
92
 
65
- DEFAULT_PROMPT_SAFE_OBJECTS = [String, Numeric, Symbol, nil, true, false]
66
-
67
93
  # A simple prompt - doesn't display target or nesting level
68
94
  SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
69
95
 
70
- NO_PROMPT = [proc { '' }, proc { '' }]
71
-
72
96
  SHELL_PROMPT = [
73
- proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
74
- proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
97
+ proc { |target_self, _, _| "#{Pry.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
98
+ proc { |target_self, _, _| "#{Pry.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
75
99
  ]
76
100
 
77
101
  # A prompt that includes the full object path as well as
78
102
  # input/output (_in_ and _out_) information. Good for navigation.
79
103
  NAV_PROMPT = [
80
- proc do |_, _, _pry_|
81
- tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
82
- "[#{_pry_.input_array.count}] (#{_pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}> "
104
+ proc do |conf|
105
+ tree = conf.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
106
+ "[#{conf.expr_number}] (#{Pry.config.prompt_name}) #{tree}: #{conf.nesting_level}> "
83
107
  end,
84
- proc do |_, _, _pry_|
85
- tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
86
- "[#{_pry_.input_array.count}] (#{ _pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}* "
108
+ proc do |conf|
109
+ tree = conf.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
110
+ "[#{conf.expr_number}] (#{ Pry.config.prompt_name}) #{tree}: #{conf.nesting_level}* "
87
111
  end,
88
112
  ]
89
113
 
@@ -100,7 +124,7 @@ class Pry
100
124
  else
101
125
  # Otherwise, saves current binding stack as old stack and pops last
102
126
  # binding out of binding stack (the old stack still has that binding).
103
- _pry_.command_state["cd"] ||= Pry::Config.from_hash({}) # FIXME
127
+ _pry_.command_state["cd"] ||= OpenStruct.new # FIXME
104
128
  _pry_.command_state['cd'].old_stack = _pry_.binding_stack.dup
105
129
  _pry_.binding_stack.pop
106
130
  end
@@ -116,9 +140,70 @@ class Pry
116
140
  # your process has changed directory since boot. [Issue #675]
117
141
  INITIAL_PWD = Dir.pwd
118
142
 
143
+ # As a REPL, we often want to catch any unexpected exceptions that may have
144
+ # been raised; however we don't want to go overboard and prevent the user
145
+ # from exiting Pry when they want to.
146
+ module RescuableException
147
+ def self.===(exception)
148
+ case exception
149
+ # Catch when the user hits ^C (Interrupt < SignalException), and assume
150
+ # that they just wanted to stop the in-progress command (just like bash etc.)
151
+ when Interrupt
152
+ true
153
+ # Don't catch signals (particularly not SIGTERM) as these are unlikely to be
154
+ # intended for pry itself. We should also make sure that Kernel#exit works.
155
+ when *Pry.config.exception_whitelist
156
+ false
157
+ # All other exceptions will be caught.
158
+ else
159
+ true
160
+ end
161
+ end
162
+ end
163
+
164
+ # An Exception Tag (cf. Exceptional Ruby) that instructs Pry to show the error in
165
+ # a more user-friendly manner. This should be used when the exception happens within
166
+ # Pry itself as a direct consequence of the user typing something wrong.
167
+ #
168
+ # This allows us to distinguish between the user typing:
169
+ #
170
+ # pry(main)> def )
171
+ # SyntaxError: unexpected )
172
+ #
173
+ # pry(main)> method_that_evals("def )")
174
+ # SyntaxError: (eval):1: syntax error, unexpected ')'
175
+ # from ./a.rb:2 in `eval'
176
+ module UserError; end
177
+
178
+ # Catches SecurityErrors if $SAFE is set
179
+ module TooSafeException
180
+ def self.===(exception)
181
+ $SAFE > 0 && SecurityError === exception
182
+ end
183
+ end
184
+
185
+ # Don't catch these exceptions
186
+ DEFAULT_EXCEPTION_WHITELIST = [SystemExit, SignalException, Pry::TooSafeException]
187
+
188
+ # CommandErrors are caught by the REPL loop and displayed to the user. They
189
+ # indicate an exceptional condition that's fatal to the current command.
190
+ class CommandError < StandardError; end
191
+ class MethodNotFound < CommandError; end
192
+
193
+ # indicates obsolete API
194
+ class ObsoleteError < StandardError; end
195
+
119
196
  # This is to keep from breaking under Rails 3.2 for people who are doing that
120
197
  # IRB = Pry thing.
121
- module ExtendCommandBundle; end
198
+ module ExtendCommandBundle
199
+ end
200
+ end
201
+
202
+ if Pry::Helpers::BaseHelpers.mri_18?
203
+ begin
204
+ require 'ruby18_source_location'
205
+ rescue LoadError
206
+ end
122
207
  end
123
208
 
124
209
  require 'method_source'
@@ -130,8 +215,41 @@ require 'rbconfig'
130
215
  require 'tempfile'
131
216
  require 'pathname'
132
217
 
218
+ begin
219
+ require 'readline'
220
+ rescue LoadError
221
+ warn "You're running a version of ruby with no Readline support"
222
+ warn "Please `gem install rb-readline` or recompile ruby --with-readline."
223
+ exit!
224
+ end
225
+
226
+ if Pry::Helpers::BaseHelpers.jruby?
227
+ begin
228
+ require 'ffi'
229
+ rescue LoadError
230
+ warn "Need to `gem install ffi`"
231
+ end
232
+ end
233
+
234
+ if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi?
235
+ begin
236
+ require 'win32console'
237
+ # The mswin and mingw versions of pry require win32console, so this should
238
+ # only fail on jruby (where win32console doesn't work).
239
+ # Instead we'll recommend ansicon, which does.
240
+ rescue LoadError
241
+ warn "For a better pry experience, please use ansicon: http://adoxa.3eeweb.com/ansicon/"
242
+ end
243
+ end
244
+
245
+ begin
246
+ require 'bond'
247
+ rescue LoadError
248
+ end
249
+
133
250
  require 'pry/version'
134
251
  require 'pry/repl'
252
+ require 'pry/rbx_method'
135
253
  require 'pry/rbx_path'
136
254
  require 'pry/code'
137
255
  require 'pry/history_array'
@@ -143,19 +261,14 @@ require 'pry/history'
143
261
  require 'pry/command'
144
262
  require 'pry/command_set'
145
263
  require 'pry/commands'
264
+ require 'pry/custom_completions'
265
+ require 'pry/completion'
146
266
  require 'pry/plugins'
147
267
  require 'pry/core_extensions'
148
268
  require 'pry/pry_class'
149
269
  require 'pry/pry_instance'
150
270
  require 'pry/cli'
151
- require 'pry/color_printer'
152
271
  require 'pry/pager'
153
272
  require 'pry/terminal'
154
273
  require 'pry/editor'
155
274
  require 'pry/rubygem'
156
- require "pry/indent"
157
- require "pry/last_exception"
158
- require "pry/prompt"
159
- require "pry/inspector"
160
- require 'pry/object_path'
161
- require 'pry/output'
@@ -1,3 +1,4 @@
1
+
1
2
  class Pry
2
3
 
3
4
  # Manage the processing of command line options
@@ -10,9 +11,7 @@ class Pry
10
11
  # @return [Proc] The Proc defining the valid command line options.
11
12
  attr_accessor :options
12
13
 
13
- # @return [Array] The Procs that process the parsed options. Plugins can
14
- # utilize this facility in order to add and process their own Pry
15
- # options.
14
+ # @return [Array] The Procs that process the parsed options.
16
15
  attr_accessor :option_processors
17
16
 
18
17
  # @return [Array<String>] The input array of strings to process
@@ -44,7 +43,7 @@ class Pry
44
43
  end
45
44
 
46
45
  # Add a block responsible for processing parsed options.
47
- def add_option_processor(&block)
46
+ def process_options(&block)
48
47
  self.option_processors ||= []
49
48
  option_processors << block
50
49
 
@@ -57,26 +56,14 @@ class Pry
57
56
  self.option_processors = nil
58
57
  end
59
58
 
60
- def parse_options(args=ARGV)
59
+ def parse_options(args=ARGV.dup)
61
60
  unless options
62
61
  raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options."
63
62
  end
64
63
 
65
64
  self.input_args = args
66
65
 
67
- begin
68
- opts = Slop.parse!(
69
- args,
70
- :help => true,
71
- :multiple_switches => false,
72
- :strict => true,
73
- &options
74
- )
75
- rescue Slop::InvalidOptionError
76
- # Display help message on unknown switches and exit.
77
- puts Slop.new(&options)
78
- exit
79
- end
66
+ opts = Slop.parse!(args, :help => true, :multiple_switches => false, &options)
80
67
 
81
68
  # Option processors are optional.
82
69
  if option_processors
@@ -104,19 +91,19 @@ Slop.new do
104
91
  end.parse(ARGV.dup)
105
92
 
106
93
  if Pry.config.should_load_plugins
107
- Pry::CLI.add_plugin_options
94
+ Pry::CLI.add_plugin_options
108
95
  end
109
96
 
110
97
  # The default Pry command line options (before plugin options are included)
111
98
  Pry::CLI.add_options do
112
99
  banner %{Usage: pry [OPTIONS]
113
100
  Start a Pry session.
114
- See http://pryrepl.org/ for more information.
101
+ See: `https://github.com/pry` for more information.
115
102
  Copyright (c) 2013 John Mair (banisterfiend)
116
103
  --
117
104
  }
118
105
  on :e, :exec=, "A line of code to execute in context before the session starts" do |input|
119
- exec_string << input << "\n"
106
+ exec_string << input + "\n"
120
107
  end
121
108
 
122
109
  on "no-pager", "Disable pager for long output" do
@@ -128,7 +115,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
128
115
  end
129
116
 
130
117
  on "no-color", "Disable syntax highlighting for session" do
131
- Pry.config.color = false
118
+ Pry.color = false
132
119
  end
133
120
 
134
121
  on :f, "Suppress loading of ~/.pryrc and ./.pryrc" do
@@ -149,11 +136,11 @@ Copyright (c) 2013 John Mair (banisterfiend)
149
136
  Pry.config.should_load_plugins = false
150
137
  end
151
138
 
152
- on "plugins", "List installed plugins." do
139
+ on "installed-plugins", "List installed plugins." do
153
140
  puts "Installed Plugins:"
154
141
  puts "--"
155
142
  Pry.locate_plugins.each do |plugin|
156
- puts "#{plugin.name}".ljust(18) << plugin.spec.summary
143
+ puts "#{plugin.name}".ljust(18) + plugin.spec.summary
157
144
  end
158
145
  exit
159
146
  end
@@ -162,10 +149,6 @@ Copyright (c) 2013 John Mair (banisterfiend)
162
149
  Pry.config.prompt = Pry::SIMPLE_PROMPT
163
150
  end
164
151
 
165
- on "noprompt", "No prompt mode" do
166
- Pry.config.prompt = Pry::NO_PROMPT
167
- end
168
-
169
152
  on :r, :require=, "`require` a Ruby script at startup" do |file|
170
153
  Pry.config.requires << file
171
154
  end
@@ -194,7 +177,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
194
177
  "Start the session in the specified context. Equivalent to `context.pry` in a session.",
195
178
  :default => "Pry.toplevel_binding"
196
179
  )
197
- end.add_option_processor do |opts|
180
+ end.process_options do |opts|
198
181
 
199
182
  exit if opts.help?
200
183
 
@@ -202,12 +185,7 @@ end.add_option_processor do |opts|
202
185
  Pry.cli = true
203
186
 
204
187
  # create the actual context
205
- if opts[:context]
206
- Pry.initial_session_setup
207
- context = Pry.binding_for(eval(opts[:context]))
208
- else
209
- context = Pry.toplevel_binding
210
- end
188
+ context = Pry.binding_for(eval(opts[:context]))
211
189
 
212
190
  if Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
213
191
  full_name = File.expand_path(Pry::CLI.input_args.first)