pry 0.10.pre.1-i386-mswin32 → 0.10.0.pre3-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +122 -183
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -1,169 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
- FindMethod = Pry::CommandSet.new do
4
-
5
- create_command "find-method" do
6
- extend Helpers::BaseHelpers
7
-
8
- group "Context"
9
-
10
- options :requires_gem => "ruby18_source_location" if mri_18?
11
-
12
- description "Recursively search for a method within a Class/Module or the current namespace. find-method [-n | -c] METHOD [NAMESPACE]"
13
-
14
- banner <<-BANNER
15
- Usage: find-method [-n | -c] METHOD [NAMESPACE]
16
-
17
- Recursively search for a method within a Class/Module or the current namespace.
18
- Use the `-n` switch (the default) to search for methods whose name matches the given regex.
19
- Use the `-c` switch to search for methods that contain the given code.
20
-
21
- e.g find-method re Pry # find all methods whose name match /re/ inside the Pry namespace. Matches Pry#repl, etc.
22
- e.g find-method -c 'output.puts' Pry # find all methods that contain the code: output.puts inside the Pry namepsace.
23
- BANNER
24
-
25
- def setup
26
- require 'ruby18_source_location' if mri_18?
27
- end
28
-
29
- def options(opti)
30
- opti.on :n, :name, "Search for a method by name"
31
- opti.on :c, :content, "Search for a method based on content in Regex form"
32
- end
33
-
34
- def process
35
- return if args.size < 1
36
- pattern = ::Regexp.new args[0]
37
- if args[1]
38
- klass = target.eval(args[1])
39
- if !klass.is_a?(Module)
40
- klass = klass.class
41
- end
42
- else
43
- klass = (target_self.is_a?(Module)) ? target_self : target_self.class
44
- end
45
-
46
- matches = if opts.content?
47
- content_search(pattern, klass)
48
- else
49
- name_search(pattern, klass)
50
- end
51
-
52
- if matches.empty?
53
- output.puts text.bold("No Methods Matched")
54
- else
55
- print_matches(matches, pattern)
56
- end
57
-
58
- end
59
-
60
- private
61
-
62
- # pretty-print a list of matching methods.
63
- #
64
- # @param Array[Method]
65
- def print_matches(matches, pattern)
66
- grouped = matches.group_by(&:owner)
67
- order = grouped.keys.sort_by{ |x| x.name || x.to_s }
68
-
69
- order.each do |klass|
70
- output.puts text.bold(klass.name)
71
- grouped[klass].each do |method|
72
- header = method.name_with_owner
73
-
74
- extra = if opts.content?
75
- header += ": "
76
- colorize_code((method.source.split(/\n/).select {|x| x =~ pattern }).join("\n#{' ' * header.length}"))
77
- else
78
- ""
79
- end
80
-
81
- output.puts header + extra
82
- end
83
- end
84
- end
85
-
86
- # Run the given block against every constant in the provided namespace.
87
- #
88
- # @param Module The namespace in which to start the search.
89
- # @param Hash[Module,Boolean] The namespaces we've already visited (private)
90
- # @yieldparam klazz Each class/module in the namespace.
91
- #
92
- def recurse_namespace(klass, done={}, &block)
93
- return if !(Module === klass) || done[klass]
94
-
95
- done[klass] = true
96
-
97
- yield klass
98
-
99
- klass.constants.each do |name|
100
- next if klass.autoload?(name)
101
- begin
102
- const = klass.const_get(name)
103
- rescue RescuableException
104
- # constant loading is an inexact science at the best of times,
105
- # this often happens when a constant was .autoload? but someone
106
- # tried to load it. It's now not .autoload? but will still raise
107
- # a NameError when you access it.
108
- else
109
- recurse_namespace(const, done, &block)
110
- end
111
- end
112
- end
113
-
114
- # Gather all the methods in a namespace that pass the given block.
115
- #
116
- # @param Module The namespace in which to search.
117
- # @yieldparam Method The method to test
118
- # @yieldreturn Boolean
119
- # @return Array[Method]
120
- #
121
- def search_all_methods(namespace)
122
- done = Hash.new{ |h,k| h[k] = {} }
123
- matches = []
124
-
125
- recurse_namespace(namespace) do |klass|
126
- (Pry::Method.all_from_class(klass) + Pry::Method.all_from_obj(klass)).each do |method|
127
- next if done[method.owner][method.name]
128
- done[method.owner][method.name] = true
129
-
130
- matches << method if yield method
131
- end
132
- end
133
-
134
- matches
135
- end
136
-
137
- # Search for all methods with a name that matches the given regex
138
- # within a namespace.
139
- #
140
- # @param Regex The regex to search for
141
- # @param Module The namespace to search
142
- # @return Array[Method]
143
- #
144
- def name_search(regex, namespace)
145
- search_all_methods(namespace) do |meth|
146
- meth.name =~ regex
147
- end
148
- end
149
-
150
- # Search for all methods who's implementation matches the given regex
151
- # within a namespace.
152
- #
153
- # @param Regex The regex to search for
154
- # @param Module The namespace to search
155
- # @return Array[Method]
156
- #
157
- def content_search(regex, namespace)
158
- search_all_methods(namespace) do |meth|
159
- begin
160
- meth.source =~ regex
161
- rescue RescuableException
162
- false
163
- end
164
- end
165
- end
166
- end
167
- end
168
- end
169
- end
@@ -1,84 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
-
4
- Gems = Pry::CommandSet.new do
5
-
6
- create_command "gem-install", "Install a gem and refresh the gem cache.", :argument_required => true do |gem|
7
-
8
- banner <<-BANNER
9
- Usage: gem-install GEM_NAME
10
-
11
- Installs the given gem and refreshes the gem cache so that you can immediately 'require GEM_FILE'
12
- BANNER
13
-
14
- def setup
15
- require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
16
- end
17
-
18
- def process(gem)
19
- begin
20
- destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir
21
- installer = Gem::DependencyInstaller.new :install_dir => destination
22
- installer.install gem
23
- rescue Errno::EACCES
24
- raise CommandError, "Insufficient permissions to install `#{text.green gem}`."
25
- rescue Gem::GemNotFoundException
26
- raise CommandError, "Gem `#{text.green gem}` not found."
27
- else
28
- Gem.refresh
29
- output.puts "Gem `#{text.green gem}` installed."
30
- end
31
- end
32
- end
33
-
34
- create_command "gem-cd", "Change working directory to specified gem's directory.", :argument_required => true do |gem|
35
- banner <<-BANNER
36
- Usage: gem-cd GEM_NAME
37
-
38
- Change the current working directory to that in which the given gem is installed.
39
- BANNER
40
-
41
- def process(gem)
42
- specs = Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem) : Gem.source_index.find_name(gem)
43
- spec = specs.sort { |a,b| Gem::Version.new(b.version) <=> Gem::Version.new(a.version) }.first
44
- if spec
45
- Dir.chdir(spec.full_gem_path)
46
- output.puts(Dir.pwd)
47
- else
48
- raise CommandError, "Gem `#{gem}` not found."
49
- end
50
- end
51
- end
52
-
53
- create_command "gem-list", "List and search installed gems." do |pattern|
54
- banner <<-BANNER
55
- Usage: gem-list [REGEX]
56
-
57
- List all installed gems, when a regex is provided, limit the output to those that
58
- match the regex.
59
- BANNER
60
-
61
- def process(pattern=nil)
62
- pattern = Regexp.compile(pattern || '')
63
- gems = if Gem::Specification.respond_to?(:each)
64
- Gem::Specification.select{|spec| spec.name =~ pattern }.group_by(&:name)
65
- else
66
- Gem.source_index.gems.values.group_by(&:name).select { |gemname, specs| gemname =~ pattern }
67
- end
68
-
69
- gems.each do |gem, specs|
70
- specs.sort! do |a,b|
71
- Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
72
- end
73
-
74
- versions = specs.each_with_index.map do |spec, index|
75
- index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
76
- end
77
-
78
- output.puts "#{text.default gem} (#{versions.join ', '})"
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,187 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
- Gist = Pry::CommandSet.new do
4
- create_command "gist", "Gist a method or expression history to GitHub.", :requires_gem => "jist" do
5
- include Pry::Helpers::DocumentationHelpers
6
-
7
- banner <<-USAGE
8
- Usage: gist [OPTIONS] [METH]
9
- Gist method (doc or source) or input expression to GitHub.
10
-
11
- If you'd like to permanently associate your gists with your GitHub account run `gist --login`.
12
-
13
- e.g: gist -m my_method # gist the method my_method
14
- e.g: gist -d my_method # gist the documentation for my_method
15
- e.g: gist -i 1..10 # gist the input expressions from 1 to 10
16
- e.g: gist -k show-method # gist the command show-method
17
- e.g: gist -c Pry # gist the Pry class
18
- e.g: gist -m hello_world --lines 2..-2 # gist from lines 2 to the second-last of the hello_world method
19
- e.g: gist -m my_method --clip # Copy my_method source to clipboard, do not gist it.
20
- USAGE
21
-
22
- command_options :shellwords => false
23
-
24
- attr_accessor :content
25
- attr_accessor :filename
26
-
27
- def setup
28
- require 'jist'
29
- self.content = ""
30
- self.filename = "a.rb"
31
- end
32
-
33
- def options(opt)
34
- opt.on :login, "Authenticate the jist gem with GitHub"
35
- opt.on :m, :method, "Gist a method's source.", :argument => true do |meth_name|
36
- meth = get_method_or_raise(meth_name, target, {})
37
- self.content << meth.source << "\n"
38
- self.filename = meth.source_file
39
- end
40
- opt.on :d, :doc, "Gist a method's documentation.", :argument => true do |meth_name|
41
- meth = get_method_or_raise(meth_name, target, {})
42
- text.no_color do
43
- self.content << process_comment_markup(meth.doc, self.code_type) << "\n"
44
- end
45
- self.filename = meth.source_file + ".doc"
46
- end
47
- opt.on :k, :command, "Gist a command's source.", :argument => true do |command_name|
48
- command = find_command(command_name)
49
- block = Pry::Method.new(command.block)
50
- self.content << block.source << "\n"
51
- self.filename = block.source_file
52
- end
53
- opt.on :c, :class, "Gist a class or module's source.", :argument => true do |class_name|
54
- mod = Pry::WrappedModule.from_str(class_name, target)
55
- self.content << mod.source << "\n"
56
- self.filename = mod.source_file
57
- end
58
- opt.on :var, "Gist a variable's content.", :argument => true do |variable_name|
59
- begin
60
- obj = target.eval(variable_name)
61
- rescue Pry::RescuableException
62
- raise CommandError, "Gist failed: Invalid variable name: #{variable_name}"
63
- end
64
-
65
- self.content << Pry.config.gist.inspecter.call(obj) << "\n"
66
- end
67
- opt.on :hist, "Gist a range of Readline history lines.", :optional_argument => true, :as => Range, :default => -20..-1 do |range|
68
- h = Pry.history.to_a
69
- self.content << h[one_index_range(convert_to_range(range))].join("\n") << "\n"
70
- end
71
-
72
- opt.on :f, :file, "Gist a file.", :argument => true do |file|
73
- self.content << File.read(File.expand_path(file)) << "\n"
74
- self.filename = file
75
- end
76
- opt.on :o, :out, "Gist entries from Pry's output result history. Takes an index or range.", :optional_argument => true,
77
- :as => Range, :default => -1 do |range|
78
- range = convert_to_range(range)
79
-
80
- range.each do |v|
81
- self.content << Pry.config.gist.inspecter.call(_pry_.output_array[v])
82
- end
83
-
84
- self.content << "\n"
85
- end
86
- opt.on :clip, "Copy the selected content to clipboard instead, do NOT gist it.", :default => false
87
- opt.on :p, :public, "Create a public gist (default: false)", :default => false
88
- opt.on :l, :lines, "Only gist a subset of lines from the gistable content.", :optional_argument => true, :as => Range, :default => 1..-1
89
- opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional_argument => true,
90
- :as => Range, :default => -1 do |range|
91
- range = convert_to_range(range)
92
- input_expressions = _pry_.input_array[range] || []
93
- Array(input_expressions).each_with_index do |code, index|
94
- corrected_index = index + range.first
95
- if code && code != ""
96
- self.content << code
97
- if code !~ /;\Z/
98
- self.content << "#{comment_expression_result_for_gist(Pry.config.gist.inspecter.call(_pry_.output_array[corrected_index]))}"
99
- end
100
- end
101
- end
102
- end
103
- end
104
-
105
- def process
106
- return Jist.login! if opts.present?(:login)
107
-
108
- if self.content =~ /\A\s*\z/
109
- raise CommandError, "Found no code to gist."
110
- end
111
-
112
- if opts.present?(:clip)
113
- perform_clipboard
114
- else
115
- perform_gist
116
- end
117
- end
118
-
119
- # copy content to clipboard instead (only used with --clip flag)
120
- def perform_clipboard
121
- copy(self.content)
122
- output.puts "Copied content to clipboard!"
123
- end
124
-
125
- def perform_gist
126
- if opts.present?(:lines)
127
- self.content = restrict_to_lines(content, opts[:l])
128
- end
129
-
130
- response = Jist.gist(content, :filename => File.basename(filename),
131
- :public => !!opts[:p])
132
-
133
- if response
134
- copy(response['html_url'])
135
- output.puts "Gist created at #{response['html_url']} and added to clipboard."
136
- end
137
- end
138
-
139
- def convert_to_range(n)
140
- if !n.is_a?(Range)
141
- (n..n)
142
- else
143
- n
144
- end
145
- end
146
-
147
- def comment_expression_result_for_gist(result)
148
- content = ""
149
- result.lines.each_with_index do |line, index|
150
- if index == 0
151
- content << "# => #{line}"
152
- else
153
- content << "# #{line}"
154
- end
155
- end
156
- content
157
- end
158
-
159
- # Copy a string to the clipboard.
160
- #
161
- # @param [String] content
162
- #
163
- # @copyright Copyright (c) 2008 Chris Wanstrath (MIT)
164
- # @see https://github.com/defunkt/gist/blob/master/lib/gist.rb#L178
165
- def copy(content)
166
- cmd = case true
167
- when system("type pbcopy > /dev/null 2>&1")
168
- :pbcopy
169
- when system("type xclip > /dev/null 2>&1")
170
- :xclip
171
- when system("type putclip > /dev/null 2>&1")
172
- :putclip
173
- end
174
-
175
- if cmd
176
- IO.popen(cmd.to_s, 'r+') { |clip| clip.print content }
177
- end
178
-
179
- content
180
- end
181
- end
182
-
183
- alias_command "clipit", "gist --clip"
184
- alias_command "jist", "gist"
185
- end
186
- end
187
- end
@@ -1,127 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
- Help = Pry::CommandSet.new do
4
- create_command "help" do |cmd|
5
- description "Show a list of commands. Type `help <foo>` for information about <foo>."
6
-
7
- banner <<-BANNER
8
- Usage: help [ COMMAND ]
9
-
10
- With no arguments, help lists all the available commands in the current
11
- command-set along with their description.
12
-
13
- When given a command name as an argument, shows the help for that command.
14
- BANNER
15
-
16
- # We only want to show commands that have descriptions, so that the
17
- # easter eggs don't show up.
18
- def visible_commands
19
- visible = {}
20
- commands.each do |key, command|
21
- visible[key] = command if command.description && !command.description.empty?
22
- end
23
- visible
24
- end
25
-
26
- # Get a hash of available commands grouped by the "group" name.
27
- def command_groups
28
- visible_commands.values.group_by(&:group)
29
- end
30
-
31
- def process
32
- if args.empty?
33
- display_index(command_groups)
34
- else
35
- display_search(args.first)
36
- end
37
- end
38
-
39
- # Display the index view, with headings and short descriptions per command.
40
- #
41
- # @param Hash[String => Array[Commands]]
42
- def display_index(groups)
43
- help_text = []
44
-
45
- groups.keys.sort_by(&method(:group_sort_key)).each do |key|
46
- commands = groups[key].sort_by{ |command| command.options[:listing].to_s }
47
-
48
- unless commands.empty?
49
- help_text << "#{text.bold(key)}\n" + commands.map do |command|
50
- " #{command.options[:listing].to_s.ljust(18)} #{command.description}"
51
- end.join("\n")
52
- end
53
- end
54
-
55
- stagger_output(help_text.join("\n\n"))
56
- end
57
-
58
- # Display help for an individual command or group.
59
- #
60
- # @param String The string to search for.
61
- def display_search(search)
62
- if command = command_set.find_command_for_help(search)
63
- display_command(command)
64
- else
65
- groups = search_hash(search, command_groups)
66
-
67
- if groups.size > 0
68
- display_index(groups)
69
- return
70
- end
71
-
72
- filtered = search_hash(search, visible_commands)
73
- raise CommandError, "No help found for '#{args.first}'" if filtered.empty?
74
-
75
- if filtered.size == 1
76
- display_command(filtered.values.first)
77
- else
78
- display_index({"'#{search}' commands" => filtered.values})
79
- end
80
- end
81
- end
82
-
83
- # Display help for an individual command.
84
- #
85
- # @param [Pry::Command]
86
- def display_command(command)
87
- stagger_output command.new.help
88
- end
89
-
90
- # Find a subset of a hash that matches the user's search term.
91
- #
92
- # If there's an exact match a Hash of one element will be returned,
93
- # otherwise a sub-Hash with every key that matches the search will
94
- # be returned.
95
- #
96
- # @param [String] the search term
97
- # @param [Hash] the hash to search
98
- def search_hash(search, hash)
99
- matching = {}
100
-
101
- hash.each_pair do |key, value|
102
- next unless key.is_a?(String)
103
- if normalize(key) == normalize(search)
104
- return {key => value}
105
- elsif normalize(key).start_with?(normalize(search))
106
- matching[key] = value
107
- end
108
- end
109
-
110
- matching
111
- end
112
-
113
- # Clean search terms to make it easier to search group names
114
- #
115
- # @param String
116
- # @return String
117
- def normalize(key)
118
- key.downcase.gsub(/pry\W+/, '')
119
- end
120
-
121
- def group_sort_key(group_name)
122
- [%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name]
123
- end
124
- end
125
- end
126
- end
127
- end