pry 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +132 -119
  7. data/lib/pry/basic_object.rb +8 -4
  8. data/lib/pry/block_command.rb +22 -0
  9. data/lib/pry/class_command.rb +194 -0
  10. data/lib/pry/cli.rb +43 -51
  11. data/lib/pry/code.rb +40 -28
  12. data/lib/pry/code/code_file.rb +28 -24
  13. data/lib/pry/code/code_range.rb +4 -2
  14. data/lib/pry/code/loc.rb +15 -8
  15. data/lib/pry/code_object.rb +40 -38
  16. data/lib/pry/color_printer.rb +47 -46
  17. data/lib/pry/command.rb +166 -369
  18. data/lib/pry/command_set.rb +76 -73
  19. data/lib/pry/command_state.rb +31 -0
  20. data/lib/pry/commands/amend_line.rb +86 -81
  21. data/lib/pry/commands/bang.rb +18 -14
  22. data/lib/pry/commands/bang_pry.rb +15 -11
  23. data/lib/pry/commands/cat.rb +61 -54
  24. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  25. data/lib/pry/commands/cat/exception_formatter.rb +71 -60
  26. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  28. data/lib/pry/commands/cd.rb +40 -35
  29. data/lib/pry/commands/change_inspector.rb +29 -22
  30. data/lib/pry/commands/change_prompt.rb +44 -39
  31. data/lib/pry/commands/clear_screen.rb +16 -10
  32. data/lib/pry/commands/code_collector.rb +148 -133
  33. data/lib/pry/commands/disable_pry.rb +23 -19
  34. data/lib/pry/commands/easter_eggs.rb +19 -30
  35. data/lib/pry/commands/edit.rb +184 -161
  36. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  37. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  38. data/lib/pry/commands/exit.rb +39 -35
  39. data/lib/pry/commands/exit_all.rb +24 -20
  40. data/lib/pry/commands/exit_program.rb +20 -16
  41. data/lib/pry/commands/find_method.rb +168 -160
  42. data/lib/pry/commands/fix_indent.rb +16 -12
  43. data/lib/pry/commands/help.rb +140 -133
  44. data/lib/pry/commands/hist.rb +151 -150
  45. data/lib/pry/commands/import_set.rb +20 -16
  46. data/lib/pry/commands/jump_to.rb +25 -21
  47. data/lib/pry/commands/list_inspectors.rb +35 -28
  48. data/lib/pry/commands/ls.rb +124 -102
  49. data/lib/pry/commands/ls/constants.rb +59 -42
  50. data/lib/pry/commands/ls/formatter.rb +50 -46
  51. data/lib/pry/commands/ls/globals.rb +38 -34
  52. data/lib/pry/commands/ls/grep.rb +17 -13
  53. data/lib/pry/commands/ls/instance_vars.rb +29 -27
  54. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  55. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  56. data/lib/pry/commands/ls/local_names.rb +26 -22
  57. data/lib/pry/commands/ls/local_vars.rb +38 -28
  58. data/lib/pry/commands/ls/ls_entity.rb +47 -51
  59. data/lib/pry/commands/ls/methods.rb +44 -43
  60. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  61. data/lib/pry/commands/ls/self_methods.rb +23 -22
  62. data/lib/pry/commands/nesting.rb +21 -17
  63. data/lib/pry/commands/play.rb +93 -82
  64. data/lib/pry/commands/pry_backtrace.rb +22 -17
  65. data/lib/pry/commands/pry_version.rb +15 -11
  66. data/lib/pry/commands/raise_up.rb +27 -22
  67. data/lib/pry/commands/reload_code.rb +60 -48
  68. data/lib/pry/commands/reset.rb +16 -12
  69. data/lib/pry/commands/ri.rb +55 -45
  70. data/lib/pry/commands/save_file.rb +45 -43
  71. data/lib/pry/commands/shell_command.rb +51 -51
  72. data/lib/pry/commands/shell_mode.rb +21 -17
  73. data/lib/pry/commands/show_doc.rb +80 -68
  74. data/lib/pry/commands/show_info.rb +189 -171
  75. data/lib/pry/commands/show_input.rb +16 -11
  76. data/lib/pry/commands/show_source.rb +110 -45
  77. data/lib/pry/commands/stat.rb +35 -31
  78. data/lib/pry/commands/switch_to.rb +21 -15
  79. data/lib/pry/commands/toggle_color.rb +20 -16
  80. data/lib/pry/commands/watch_expression.rb +89 -86
  81. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  82. data/lib/pry/commands/whereami.rb +156 -148
  83. data/lib/pry/commands/wtf.rb +75 -50
  84. data/lib/pry/config.rb +307 -25
  85. data/lib/pry/config/attributable.rb +22 -0
  86. data/lib/pry/config/lazy_value.rb +29 -0
  87. data/lib/pry/config/memoized_value.rb +34 -0
  88. data/lib/pry/config/value.rb +24 -0
  89. data/lib/pry/control_d_handler.rb +28 -0
  90. data/lib/pry/core_extensions.rb +9 -7
  91. data/lib/pry/editor.rb +48 -21
  92. data/lib/pry/env.rb +18 -0
  93. data/lib/pry/exception_handler.rb +43 -0
  94. data/lib/pry/exceptions.rb +13 -16
  95. data/lib/pry/forwardable.rb +5 -1
  96. data/lib/pry/helpers.rb +2 -0
  97. data/lib/pry/helpers/base_helpers.rb +68 -197
  98. data/lib/pry/helpers/command_helpers.rb +50 -61
  99. data/lib/pry/helpers/documentation_helpers.rb +20 -13
  100. data/lib/pry/helpers/options_helpers.rb +14 -7
  101. data/lib/pry/helpers/platform.rb +7 -5
  102. data/lib/pry/helpers/table.rb +33 -26
  103. data/lib/pry/helpers/text.rb +17 -14
  104. data/lib/pry/history.rb +48 -56
  105. data/lib/pry/hooks.rb +21 -12
  106. data/lib/pry/indent.rb +54 -50
  107. data/lib/pry/input_completer.rb +248 -230
  108. data/lib/pry/input_lock.rb +8 -9
  109. data/lib/pry/inspector.rb +36 -24
  110. data/lib/pry/last_exception.rb +45 -45
  111. data/lib/pry/method.rb +141 -94
  112. data/lib/pry/method/disowned.rb +16 -4
  113. data/lib/pry/method/patcher.rb +12 -3
  114. data/lib/pry/method/weird_method_locator.rb +68 -44
  115. data/lib/pry/object_path.rb +33 -25
  116. data/lib/pry/output.rb +121 -35
  117. data/lib/pry/pager.rb +186 -180
  118. data/lib/pry/prompt.rb +123 -54
  119. data/lib/pry/pry_class.rb +61 -103
  120. data/lib/pry/pry_instance.rb +217 -215
  121. data/lib/pry/repl.rb +18 -22
  122. data/lib/pry/repl_file_loader.rb +27 -21
  123. data/lib/pry/ring.rb +11 -6
  124. data/lib/pry/slop.rb +574 -563
  125. data/lib/pry/slop/commands.rb +164 -169
  126. data/lib/pry/slop/option.rb +172 -168
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable.rb +59 -61
  130. data/lib/pry/testable/evalable.rb +21 -12
  131. data/lib/pry/testable/mockable.rb +18 -10
  132. data/lib/pry/testable/pry_tester.rb +71 -56
  133. data/lib/pry/testable/utility.rb +29 -21
  134. data/lib/pry/testable/variables.rb +49 -43
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +27 -0
  137. data/lib/pry/wrapped_module.rb +51 -42
  138. data/lib/pry/wrapped_module/candidate.rb +21 -14
  139. metadata +35 -35
  140. data/lib/pry/commands.rb +0 -6
  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/gem_readme.rb +0 -25
  147. data/lib/pry/commands/gem_search.rb +0 -40
  148. data/lib/pry/commands/gem_stats.rb +0 -83
  149. data/lib/pry/commands/gist.rb +0 -102
  150. data/lib/pry/commands/install_command.rb +0 -54
  151. data/lib/pry/config/behavior.rb +0 -255
  152. data/lib/pry/config/convenience.rb +0 -28
  153. data/lib/pry/config/default.rb +0 -159
  154. data/lib/pry/config/memoization.rb +0 -48
  155. data/lib/pry/platform.rb +0 -91
  156. data/lib/pry/plugins.rb +0 -122
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
data/bin/pry CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # (C) John Mair (banisterfiend)
5
+ # MIT license
6
+
2
7
  $0 = 'pry'
3
8
 
4
9
  require 'pry'
data/lib/pry.rb CHANGED
@@ -1,132 +1,145 @@
1
- require 'pp'
2
- require 'pry/forwardable'
3
- require 'pry/input_lock'
4
- require 'pry/exceptions'
5
- require 'pry/platform'
6
- require 'pry/helpers/base_helpers'
7
- require 'pry/hooks'
1
+ # frozen_string_literal: true
8
2
 
9
- class Pry
10
- # The default hooks - display messages when beginning and ending Pry sessions.
11
- DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
12
- next if _pry_.quiet?
13
-
14
- _pry_.run_command("whereami --quiet")
15
- end
16
-
17
- # The default print
18
- DEFAULT_PRINT = proc do |output, value, _pry_|
19
- _pry_.pager.open do |pager|
20
- pager.print _pry_.config.output_prefix
21
- Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
22
- end
23
- end
24
-
25
- # may be convenient when working with enormous objects and
26
- # pretty_print is too slow
27
- SIMPLE_PRINT = proc do |output, value|
28
- begin
29
- output.puts value.inspect
30
- rescue RescuableException
31
- output.puts "unknown"
32
- end
33
- end
34
-
35
- # useful when playing with truly enormous objects
36
- CLIPPED_PRINT = proc do |output, value|
37
- output.puts Pry.view_clip(value, id: true)
38
- end
39
-
40
- # Will only show the first line of the backtrace
41
- DEFAULT_EXCEPTION_HANDLER = proc do |output, exception, _|
42
- if UserError === exception && SyntaxError === exception
43
- output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
44
- else
45
- output.puts "#{exception.class}: #{exception.message}"
46
- output.puts "from #{exception.backtrace.first}"
47
-
48
- if exception.respond_to? :cause
49
- cause = exception.cause
50
- while cause
51
- output.puts "Caused by #{cause.class}: #{cause}\n"
52
- output.puts "from #{cause.backtrace.first}"
53
- cause = cause.cause
54
- end
55
- end
56
- end
57
- end
58
-
59
- # Deal with the ^D key being pressed. Different behaviour in different cases:
60
- # 1. In an expression behave like `!` command.
61
- # 2. At top-level session behave like `exit` command.
62
- # 3. In a nested session behave like `cd ..`.
63
- DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
64
- if !eval_string.empty?
65
- eval_string.replace('') # Clear input buffer.
66
- elsif _pry_.binding_stack.one?
67
- _pry_.binding_stack.clear
68
- throw(:breakout)
69
- else
70
- # Otherwise, saves current binding stack as old stack and pops last
71
- # binding out of binding stack (the old stack still has that binding).
72
- _pry_.command_state["cd"] ||= Pry::Config.from_hash({}) # FIXME
73
- _pry_.command_state['cd'].old_stack = _pry_.binding_stack.dup
74
- _pry_.binding_stack.pop
75
- end
76
- end
77
-
78
- DEFAULT_SYSTEM = proc do |output, cmd, _|
79
- if !system(cmd)
80
- output.puts "Error: there was a problem executing system command: #{cmd}"
81
- end
82
- end
83
-
84
- # This is to keep from breaking under Rails 3.2 for people who are doing that
85
- # IRB = Pry thing.
86
- module ExtendCommandBundle; end
87
- end
88
-
89
- require 'method_source'
90
- require 'shellwords'
91
- require 'stringio'
92
- require 'strscan'
93
- require 'coderay'
94
- require 'pry/slop'
95
- require 'rbconfig'
96
- require 'tempfile'
97
- require 'pathname'
3
+ # (C) John Mair (banisterfiend) 2016
4
+ # MIT License
98
5
 
99
6
  require 'pry/version'
100
- require 'pry/repl'
101
- require 'pry/code'
102
- require 'pry/ring'
7
+ require 'pry/last_exception'
8
+ require 'pry/forwardable'
9
+
10
+ require 'pry/helpers/base_helpers'
11
+ require 'pry/helpers/documentation_helpers'
103
12
  require 'pry/helpers'
13
+
14
+ require 'pry/basic_object'
15
+ require 'pry/prompt'
104
16
  require 'pry/code_object'
105
- require 'pry/method'
106
- require 'pry/wrapped_module'
107
- require 'pry/history'
17
+ require 'pry/exceptions'
18
+ require 'pry/hooks'
19
+ require 'pry/input_completer'
108
20
  require 'pry/command'
21
+ require 'pry/class_command'
22
+ require 'pry/block_command'
109
23
  require 'pry/command_set'
110
- require 'pry/commands'
111
- require 'pry/plugins'
112
- require 'pry/core_extensions'
113
- require 'pry/basic_object'
114
- require 'pry/config/behavior'
115
- require 'pry/config/memoization'
116
- require 'pry/config/default'
117
- require 'pry/config/convenience'
24
+ require 'pry/syntax_highlighter'
25
+ require 'pry/editor'
26
+ require 'pry/history'
27
+ require 'pry/color_printer'
28
+ require 'pry/exception_handler'
29
+ require 'pry/system_command_handler'
30
+ require 'pry/control_d_handler'
31
+ require 'pry/command_state'
32
+ require 'pry/warning'
33
+ require 'pry/env'
34
+
35
+ Pry::Commands = Pry::CommandSet.new unless defined?(Pry::Commands)
36
+
37
+ require 'pry/commands/ls/jruby_hacks'
38
+ require 'pry/commands/ls/methods_helper'
39
+ require 'pry/commands/ls/interrogatable'
40
+ require 'pry/commands/ls/grep'
41
+ require 'pry/commands/ls/formatter'
42
+ require 'pry/commands/ls/globals'
43
+ require 'pry/commands/ls/constants'
44
+ require 'pry/commands/ls/methods'
45
+ require 'pry/commands/ls/self_methods'
46
+ require 'pry/commands/ls/instance_vars'
47
+ require 'pry/commands/ls/local_names'
48
+ require 'pry/commands/ls/local_vars'
49
+ require 'pry/commands/ls/interrogatable'
50
+ require 'pry/commands/ls/ls_entity'
51
+ require 'pry/commands/ls/methods_helper'
52
+ require 'pry/commands/ls'
53
+
54
+ require 'pry/config/attributable'
55
+ require 'pry/config/value'
56
+ require 'pry/config/memoized_value'
57
+ require 'pry/config/lazy_value'
118
58
  require 'pry/config'
59
+
119
60
  require 'pry/pry_class'
120
61
  require 'pry/pry_instance'
121
- require 'pry/cli'
122
- require 'pry/color_printer'
62
+ require 'pry/inspector'
123
63
  require 'pry/pager'
124
- require 'pry/terminal'
125
- require 'pry/editor'
126
- require 'pry/rubygem'
127
- require "pry/indent"
128
- require "pry/last_exception"
129
- require "pry/prompt"
130
- require "pry/inspector"
64
+ require 'pry/indent'
131
65
  require 'pry/object_path'
132
66
  require 'pry/output'
67
+ require 'pry/input_lock'
68
+ require 'pry/repl'
69
+ require 'pry/code'
70
+ require 'pry/ring'
71
+ require 'pry/method'
72
+
73
+ require 'pry/wrapped_module'
74
+ require 'pry/wrapped_module/candidate'
75
+
76
+ require 'pry/slop'
77
+ require 'pry/cli'
78
+ require 'pry/core_extensions'
79
+ require 'pry/repl_file_loader'
80
+
81
+ require 'pry/code/loc'
82
+ require 'pry/code/code_range'
83
+ require 'pry/code/code_file'
84
+
85
+ require 'pry/method/weird_method_locator'
86
+ require 'pry/method/disowned'
87
+ require 'pry/method/patcher'
88
+
89
+ require 'pry/commands/amend_line'
90
+ require 'pry/commands/bang'
91
+ require 'pry/commands/bang_pry'
92
+
93
+ require 'pry/commands/cat'
94
+ require 'pry/commands/cat/abstract_formatter.rb'
95
+ require 'pry/commands/cat/input_expression_formatter.rb'
96
+ require 'pry/commands/cat/exception_formatter.rb'
97
+ require 'pry/commands/cat/file_formatter.rb'
98
+
99
+ require 'pry/commands/cd'
100
+ require 'pry/commands/change_inspector'
101
+ require 'pry/commands/change_prompt'
102
+ require 'pry/commands/clear_screen'
103
+ require 'pry/commands/code_collector'
104
+ require 'pry/commands/disable_pry'
105
+ require 'pry/commands/easter_eggs'
106
+
107
+ require 'pry/commands/edit'
108
+ require 'pry/commands/edit/exception_patcher'
109
+ require 'pry/commands/edit/file_and_line_locator'
110
+
111
+ require 'pry/commands/exit'
112
+ require 'pry/commands/exit_all'
113
+ require 'pry/commands/exit_program'
114
+ require 'pry/commands/find_method'
115
+ require 'pry/commands/fix_indent'
116
+ require 'pry/commands/help'
117
+ require 'pry/commands/hist'
118
+ require 'pry/commands/import_set'
119
+ require 'pry/commands/jump_to'
120
+ require 'pry/commands/list_inspectors'
121
+
122
+ require 'pry/commands/nesting'
123
+ require 'pry/commands/play'
124
+ require 'pry/commands/pry_backtrace'
125
+ require 'pry/commands/pry_version'
126
+ require 'pry/commands/raise_up'
127
+ require 'pry/commands/reload_code'
128
+ require 'pry/commands/reset'
129
+ require 'pry/commands/ri'
130
+ require 'pry/commands/save_file'
131
+ require 'pry/commands/shell_command'
132
+ require 'pry/commands/shell_mode'
133
+ require 'pry/commands/show_info'
134
+ require 'pry/commands/show_doc'
135
+ require 'pry/commands/show_input'
136
+ require 'pry/commands/show_source'
137
+ require 'pry/commands/stat'
138
+ require 'pry/commands/switch_to'
139
+ require 'pry/commands/toggle_color'
140
+
141
+ require 'pry/commands/watch_expression'
142
+ require 'pry/commands/watch_expression/expression.rb'
143
+
144
+ require 'pry/commands/whereami'
145
+ require 'pry/commands/wtf'
@@ -1,6 +1,10 @@
1
- class Pry::BasicObject < BasicObject
2
- [:Kernel, :Pry].each do |constant|
3
- const_set constant, ::Object.const_get(constant)
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class BasicObject < BasicObject
5
+ [:Kernel, :File, :Dir, :LoadError, :ENV, :Pry].each do |constant|
6
+ const_set constant, ::Object.const_get(constant)
7
+ end
8
+ include Kernel
4
9
  end
5
- include Kernel
6
10
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # A super-class for Commands that are created with a single block.
5
+ #
6
+ # This class ensures that the block is called with the correct number of
7
+ # arguments and the right context.
8
+ #
9
+ # Create subclasses using {Pry::CommandSet#command}.
10
+ class BlockCommand < Command
11
+ # Call the block that was registered with this command.
12
+ # @param [Array<String>] args The arguments passed
13
+ # @return [Object] The return value of the block
14
+ def call(*args)
15
+ instance_exec(*normalize_method_args(block, args), &block)
16
+ end
17
+
18
+ def help
19
+ "#{command_options[:listing].to_s.ljust(18)} #{description}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # A super-class of Commands with structure.
5
+ #
6
+ # This class implements the bare-minimum functionality that a command should
7
+ # have, namely a --help switch, and then delegates actual processing to its
8
+ # subclasses.
9
+ #
10
+ # Create subclasses using {Pry::CommandSet#create_command}, and override the
11
+ # `options(opt)` method to set up an instance of Pry::Slop, and the `process`
12
+ # method to actually run the command. If necessary, you can also override
13
+ # `setup` which will be called before `options`, for example to require any
14
+ # gems your command needs to run, or to set up state.
15
+ class ClassCommand < Command
16
+ class << self
17
+ # Ensure that subclasses inherit the options, description and
18
+ # match from a ClassCommand super class.
19
+ def inherited(klass)
20
+ klass.match match
21
+ klass.description description
22
+ klass.command_options options
23
+ end
24
+
25
+ def source
26
+ source_object.source
27
+ end
28
+
29
+ def doc
30
+ new.help
31
+ end
32
+
33
+ def source_location
34
+ source_object.source_location
35
+ end
36
+
37
+ def source_file
38
+ source_object.source_file
39
+ end
40
+ alias file source_file
41
+
42
+ def source_line
43
+ source_object.source_line
44
+ end
45
+ alias line source_line
46
+
47
+ private
48
+
49
+ # The object used to extract the source for the command.
50
+ #
51
+ # This should be a `Pry::Method(block)` for a command made with `create_command`
52
+ # and a `Pry::WrappedModule(self)` for a command that's a standard class.
53
+ # @return [Pry::WrappedModule, Pry::Method]
54
+ def source_object
55
+ @source_object ||= if name =~ /^[A-Z]/
56
+ Pry::WrappedModule(self)
57
+ else
58
+ Pry::Method(block)
59
+ end
60
+ end
61
+ end
62
+
63
+ attr_accessor :opts
64
+ attr_accessor :args
65
+
66
+ # Set up `opts` and `args`, and then call `process`.
67
+ #
68
+ # This method will display help if necessary.
69
+ #
70
+ # @param [Array<String>] args The arguments passed
71
+ # @return [Object] The return value of `process` or VOID_VALUE
72
+ def call(*args)
73
+ setup
74
+
75
+ self.opts = slop
76
+ self.args = opts.parse!(args)
77
+
78
+ if opts.present?(:help)
79
+ output.puts slop.help
80
+ void
81
+ else
82
+ process(*normalize_method_args(method(:process), args))
83
+ end
84
+ end
85
+
86
+ # Return the help generated by Pry::Slop for this command.
87
+ def help
88
+ slop.help
89
+ end
90
+
91
+ # Return an instance of Pry::Slop that can parse either subcommands or the
92
+ # options that this command accepts.
93
+ def slop
94
+ Pry::Slop.new do |opt|
95
+ opt.banner(unindent(self.class.banner))
96
+ subcommands(opt)
97
+ options(opt)
98
+ opt.on :h, :help, 'Show this message.'
99
+ end
100
+ end
101
+
102
+ # Generate shell completions
103
+ # @param [String] search The line typed so far
104
+ # @return [Array<String>] the words to complete
105
+ def complete(search)
106
+ slop.flat_map do |opt|
107
+ [opt.long && "--#{opt.long} " || opt.short && "-#{opt.short}"]
108
+ end.compact + super
109
+ end
110
+
111
+ # A method called just before `options(opt)` as part of `call`.
112
+ #
113
+ # This method can be used to set up any context your command needs to run,
114
+ # for example requiring gems, or setting default values for options.
115
+ #
116
+ # @example
117
+ # def setup
118
+ # require 'gist'
119
+ # @action = :method
120
+ # end
121
+ def setup; end
122
+
123
+ # A method to setup Pry::Slop commands so it can parse the subcommands your
124
+ # command expects. If you need to set up default values, use `setup`
125
+ # instead.
126
+ #
127
+ # @example A minimal example
128
+ # def subcommands(cmd)
129
+ # cmd.command :download do |opt|
130
+ # description 'Downloads a content from a server'
131
+ #
132
+ # opt.on :verbose, 'Use verbose output'
133
+ #
134
+ # run do |options, arguments|
135
+ # ContentDownloader.download(options, arguments)
136
+ # end
137
+ # end
138
+ # end
139
+ #
140
+ # @example Define the invokation block anywhere you want
141
+ # def subcommands(cmd)
142
+ # cmd.command :download do |opt|
143
+ # description 'Downloads a content from a server'
144
+ #
145
+ # opt.on :verbose, 'Use verbose output'
146
+ # end
147
+ # end
148
+ #
149
+ # def process
150
+ # # Perform calculations...
151
+ # opts.fetch_command(:download).run do |options, arguments|
152
+ # ContentDownloader.download(options, arguments)
153
+ # end
154
+ # # More calculations...
155
+ # end
156
+ def subcommands(cmd); end
157
+
158
+ # A method to setup Pry::Slop so it can parse the options your command expects.
159
+ #
160
+ # @note Please don't do anything side-effecty in the main part of this
161
+ # method, as it may be called by Pry at any time for introspection reasons.
162
+ # If you need to set up default values, use `setup` instead.
163
+ #
164
+ # @example
165
+ # def options(opt)
166
+ # opt.banner "Gists methods or classes"
167
+ # opt.on(:c, :class, "gist a class") do
168
+ # @action = :class
169
+ # end
170
+ # end
171
+ def options(opt); end
172
+
173
+ # The actual body of your command should go here.
174
+ #
175
+ # The `opts` mehod can be called to get the options that Pry::Slop has passed,
176
+ # and `args` gives the remaining, unparsed arguments.
177
+ #
178
+ # The return value of this method is discarded unless the command was
179
+ # created with `:keep_retval => true`, in which case it is returned to the
180
+ # repl.
181
+ #
182
+ # @example
183
+ # def process
184
+ # if opts.present?(:class)
185
+ # gist_class
186
+ # else
187
+ # gist_method
188
+ # end
189
+ # end
190
+ def process
191
+ raise CommandError, "command '#{command_name}' not implemented"
192
+ end
193
+ end
194
+ end