pry 0.9.7.4-i386-mingw32 → 0.9.8-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +2 -3
  2. data/CHANGELOG +43 -0
  3. data/README.markdown +3 -1
  4. data/Rakefile +51 -32
  5. data/bin/pry +2 -80
  6. data/lib/pry.rb +33 -26
  7. data/lib/pry/cli.rb +152 -0
  8. data/lib/pry/code.rb +351 -0
  9. data/lib/pry/command.rb +422 -0
  10. data/lib/pry/command_set.rb +259 -129
  11. data/lib/pry/commands.rb +0 -1
  12. data/lib/pry/config.rb +43 -9
  13. data/lib/pry/default_commands/context.rb +109 -92
  14. data/lib/pry/default_commands/documentation.rb +174 -63
  15. data/lib/pry/default_commands/easter_eggs.rb +26 -2
  16. data/lib/pry/default_commands/gems.rb +65 -37
  17. data/lib/pry/default_commands/input.rb +175 -243
  18. data/lib/pry/default_commands/introspection.rb +173 -112
  19. data/lib/pry/default_commands/ls.rb +96 -114
  20. data/lib/pry/default_commands/shell.rb +175 -70
  21. data/lib/pry/helpers/base_helpers.rb +7 -2
  22. data/lib/pry/helpers/command_helpers.rb +71 -77
  23. data/lib/pry/helpers/options_helpers.rb +10 -41
  24. data/lib/pry/helpers/text.rb +24 -4
  25. data/lib/pry/history.rb +55 -17
  26. data/lib/pry/history_array.rb +2 -0
  27. data/lib/pry/hooks.rb +252 -0
  28. data/lib/pry/indent.rb +9 -5
  29. data/lib/pry/method.rb +149 -50
  30. data/lib/pry/plugins.rb +12 -4
  31. data/lib/pry/pry_class.rb +69 -26
  32. data/lib/pry/pry_instance.rb +187 -115
  33. data/lib/pry/version.rb +1 -1
  34. data/lib/pry/wrapped_module.rb +73 -0
  35. data/man/pry.1 +195 -0
  36. data/man/pry.1.html +204 -0
  37. data/man/pry.1.ronn +141 -0
  38. data/pry.gemspec +29 -32
  39. data/test/helper.rb +32 -36
  40. data/test/test_cli.rb +78 -0
  41. data/test/test_code.rb +201 -0
  42. data/test/test_command.rb +327 -0
  43. data/test/test_command_integration.rb +512 -0
  44. data/test/test_command_set.rb +338 -12
  45. data/test/test_completion.rb +1 -1
  46. data/test/test_default_commands.rb +1 -2
  47. data/test/test_default_commands/test_context.rb +27 -5
  48. data/test/test_default_commands/test_documentation.rb +20 -8
  49. data/test/test_default_commands/test_input.rb +84 -45
  50. data/test/test_default_commands/test_introspection.rb +74 -17
  51. data/test/test_default_commands/test_ls.rb +9 -36
  52. data/test/test_default_commands/test_shell.rb +240 -13
  53. data/test/test_hooks.rb +490 -0
  54. data/test/test_indent.rb +2 -0
  55. data/test/test_method.rb +60 -0
  56. data/test/test_pry.rb +29 -904
  57. data/test/test_pry_defaults.rb +380 -0
  58. data/test/test_pry_history.rb +24 -24
  59. data/test/test_syntax_checking.rb +63 -0
  60. data/test/test_wrapped_module.rb +71 -0
  61. metadata +50 -39
  62. data/lib/pry/command_context.rb +0 -53
  63. data/lib/pry/command_processor.rb +0 -181
  64. data/lib/pry/extended_commands/user_command_api.rb +0 -65
  65. data/test/test_command_processor.rb +0 -176
data/.gitignore CHANGED
@@ -9,8 +9,7 @@ coverage/
9
9
  .yardoc/
10
10
  /tags
11
11
  *.gem
12
-
13
- # Not sure if Pry devs use RVM or want the Gemfile.lock in the repo, thus I'm
14
- # ignoring them for now.
12
+ .rbx/
15
13
  .rvmrc
16
14
  Gemfile.lock
15
+ *.swp
data/CHANGELOG CHANGED
@@ -1,3 +1,46 @@
1
+ X/X/2012 version 0.9.8
2
+
3
+ MAJOR NEW FEATURES
4
+ - upgraded command api, https://github.com/pry/pry/wiki/Custom-commands
5
+ - added a system of hooks for customizing pry behaviour
6
+ - changed syntax checking to use eval() for improved accuracy
7
+ - added save-file command
8
+ - added gist command (removed gist-method, new gist command is more general)
9
+
10
+
11
+ complete CHANGELOG:
12
+ * CommandError's no longer cause the current input to be disgarded
13
+ * Better syntax highlighting for rbx code code
14
+ * added cat --in to show pry input history
15
+ * prefixed temporary file names with 'pry'
16
+ * show-doc now supports -l and -b options (line numbers)
17
+ * play now supports -i and -d options
18
+ * moved UserCommandAPI command-set to pry-developer_tools plugin
19
+ * added :when_started event for hooks, called in Pry.start
20
+ * added a man page
21
+ * added rename method to Pry::CommandSet (commands can be renamed)
22
+ * added CommandSet#{before_command,after_command} for enhancing builtin commands
23
+ * added checking for namespace collisions with pry commands, set Pry.config.collision_warning
24
+ * work around namespace collisions by ensuring lines starting with a space are executed as
25
+ * ruby.work around namespace collisions by prensuring lines starting with a space are executed as ruby
26
+ * added handlers for Ctrl+C (SIGINT) on jruby, these are now caught as in other ruby versions
27
+ * removed dependency on ruby_parser
28
+ * prevented colours leaking across the pry prompt
29
+ * fixed edge cases in Pry::Method, for methods with crazy names and methods that have been 'undef'd
30
+ * refactored history handling code for clarity and correctness
31
+ * added Pry::WrappedModule as a counterpart to Pry::Method
32
+ * made a trailing , cause pry to wait for further input
33
+ * removed gist-method command, added gist command
34
+ * added pry-backtrace command to show history of current session
35
+ * fixed whereami within 'super' methods
36
+ * replaced inline version guards by Pry::Helpers::BaseHelpers.{rbx?,jruby?,windows?} etc.
37
+ * removed the CommandProcessor, its functionality is part of the new Command class
38
+ * changed cd .. at the top level so it doesn't quit pry.
39
+ * changed edit-command to no-longer need a command set argument
40
+ * fixed empty lines so that they don't replace _ by nil
41
+ * fixed SyntaxErrors at the REPL level so they don't replace _ex_.
42
+ <TODO: everything that happened after f3262e32700709a6998579a9f71cdc6b8f4a695e>
43
+
1
44
  5/11/2011 version 0.9.7.4 hotfix
2
45
  * ls -M now works in modules (bugfix)
3
46
  * added exception msg for bad cd object/path
@@ -9,7 +9,9 @@
9
9
 
10
10
  **Sponsors**
11
11
 
12
- [Atomic Object](http://www.atomicobject.com/)
12
+ [Atomic Object](http://www.atomicobject.com/)<br/>
13
+ [Bendyworks](http://bendyworks.com/)<br/>
14
+ [Intridea](http://intridea.com/)<br/>
13
15
 
14
16
  **Other Resources**
15
17
 
data/Rakefile CHANGED
@@ -1,32 +1,41 @@
1
1
  require 'rake/clean'
2
- require 'rake/gempackagetask'
2
+ require 'rubygems/package_task'
3
3
 
4
4
  $:.unshift 'lib'
5
5
  require 'pry/version'
6
6
 
7
- CLOBBER.include("**/*~", "**/*#*", "**/*.log")
8
- CLEAN.include("**/*#*", "**/*#*.*", "**/*_flymake*.*", "**/*_flymake",
9
- "**/*.rbc", "**/.#*.*")
7
+ CLOBBER.include('**/*~', '**/*#*', '**/*.log')
8
+ CLEAN.include('**/*#*', '**/*#*.*', '**/*_flymake*.*', '**/*_flymake', '**/*.rbc', '**/.#*.*')
10
9
 
11
10
  def apply_spec_defaults(s)
12
- s.name = "pry"
11
+ s.name = 'pry'
13
12
  s.summary = "An IRB alternative and runtime developer console"
14
13
  s.version = Pry::VERSION
15
14
  s.date = Time.now.strftime '%Y-%m-%d'
16
15
  s.author = "John Mair (banisterfiend)"
17
16
  s.email = 'jrmair@gmail.com'
18
17
  s.description = s.summary
19
- s.homepage = "http://pry.github.com"
20
- s.executables = ["pry"]
18
+ s.homepage = 'http://pry.github.com'
19
+ s.executables = ['pry']
21
20
  s.files = `git ls-files`.split("\n")
22
21
  s.test_files = `git ls-files -- test/*`.split("\n")
23
- s.add_dependency("ruby_parser",">= 2.3.1")
24
- s.add_dependency("coderay","~>0.9.8")
25
- s.add_dependency("slop","~>2.1.0")
26
- s.add_dependency("method_source","~>0.6.7")
27
- s.add_development_dependency("bacon","~>1.1.0")
28
- s.add_development_dependency("open4", "~>1.0.1")
29
- s.add_development_dependency("rake", "~>0.9")
22
+ s.add_dependency('coderay', '~> 1.0.5')
23
+ s.add_dependency('slop', ['>= 2.4.3', '< 3'])
24
+ s.add_dependency('method_source','~> 0.7')
25
+ s.add_development_dependency('bacon', '~> 1.1')
26
+ s.add_development_dependency('open4', '~> 1.3')
27
+ s.add_development_dependency('rake', '~> 0.9')
28
+ end
29
+
30
+ def check_dependencies
31
+ require 'bundler'
32
+ Bundler.definition.missing_specs
33
+
34
+ eval('nil', TOPLEVEL_BINDING, '<main>') # workaround for issue #395
35
+ rescue LoadError
36
+ # if Bundler isn't installed, we'll just assume your setup is ok.
37
+ rescue Bundler::GemNotFound
38
+ raise RuntimeError, "You're missing one or more required gems. Run `bundle install` first."
30
39
  end
31
40
 
32
41
  desc "Set up and run tests"
@@ -34,38 +43,42 @@ task :default => [:test]
34
43
 
35
44
  desc "Run tests"
36
45
  task :test do
46
+ check_dependencies unless ENV['SKIP_DEP_CHECK']
37
47
  sh "bacon -Itest -rubygems -a -q"
38
48
  end
39
49
 
40
- desc "profile pry's startup time"
41
- task :profile do
42
- require 'profile'
43
- require 'pry'
44
- Pry.start(TOPLEVEL_BINDING, :input => StringIO.new('exit'))
45
- end
46
-
47
- desc "run pry"
50
+ desc "Run pry"
48
51
  task :pry do
52
+ check_dependencies unless ENV['SKIP_DEP_CHECK']
49
53
  load 'bin/pry'
50
54
  end
51
55
 
52
- desc "show pry version"
56
+ desc "Show pry version"
53
57
  task :version do
54
58
  puts "Pry version: #{Pry::VERSION}"
55
59
  end
56
60
 
61
+ desc "Profile pry's startup time"
62
+ task :profile do
63
+ require 'profile'
64
+ require 'pry'
65
+ Pry.start(TOPLEVEL_BINDING, :input => StringIO.new('exit'))
66
+ end
67
+
68
+ desc "Build the gemspec file"
69
+ task :gemspec => "ruby:gemspec"
70
+
57
71
  namespace :ruby do
58
72
  spec = Gem::Specification.new do |s|
59
73
  apply_spec_defaults(s)
60
74
  s.platform = Gem::Platform::RUBY
61
75
  end
62
76
 
63
- Rake::GemPackageTask.new(spec) do |pkg|
77
+ Gem::PackageTask.new(spec) do |pkg|
64
78
  pkg.need_zip = false
65
79
  pkg.need_tar = false
66
80
  end
67
81
 
68
- desc "Generate gemspec file"
69
82
  task :gemspec do
70
83
  File.open("#{spec.name}.gemspec", "w") do |f|
71
84
  f << spec.to_ruby
@@ -76,11 +89,11 @@ end
76
89
  namespace :jruby do
77
90
  spec = Gem::Specification.new do |s|
78
91
  apply_spec_defaults(s)
79
- s.add_dependency("spoon", "~>0.0.1")
80
- s.platform = "java"
92
+ s.add_dependency('spoon', '~> 0.0')
93
+ s.platform = 'java'
81
94
  end
82
95
 
83
- Rake::GemPackageTask.new(spec) do |pkg|
96
+ Gem::PackageTask.new(spec) do |pkg|
84
97
  pkg.need_zip = false
85
98
  pkg.need_tar = false
86
99
  end
@@ -91,11 +104,11 @@ end
91
104
  namespace v do
92
105
  spec = Gem::Specification.new do |s|
93
106
  apply_spec_defaults(s)
94
- s.add_dependency("win32console", "~>1.3.0")
107
+ s.add_dependency('win32console', '~> 1.3')
95
108
  s.platform = "i386-#{v}"
96
109
  end
97
110
 
98
- Rake::GemPackageTask.new(spec) do |pkg|
111
+ Gem::PackageTask.new(spec) do |pkg|
99
112
  pkg.need_zip = false
100
113
  pkg.need_tar = false
101
114
  end
@@ -103,10 +116,16 @@ end
103
116
  end
104
117
 
105
118
  desc "build all platform gems at once"
106
- task :gems => [:clean, :rmgems, "ruby:gem", "mswin32:gem", "mingw32:gem", "jruby:gem"]
119
+ task :gems => [:clean, :rmgems, 'ruby:gem', 'mswin32:gem', 'mingw32:gem', 'jruby:gem']
107
120
 
108
121
  desc "remove all platform gems"
109
- task :rmgems => ["ruby:clobber_package"]
122
+ task :rmgems => ['ruby:clobber_package']
123
+
124
+ desc "reinstall gem"
125
+ task :reinstall => :gems do
126
+ sh "gem uninstall pry" rescue nil
127
+ sh "gem install #{File.dirname(__FILE__)}/pkg/pry-#{Pry::VERSION}.gem"
128
+ end
110
129
 
111
130
  desc "build and push latest gems"
112
131
  task :pushgems => :gems do
data/bin/pry CHANGED
@@ -12,83 +12,5 @@ rescue LoadError
12
12
  require 'pry'
13
13
  end
14
14
 
15
- opts = Slop.parse(:help => true, :multiple_switches => false) do
16
- banner %{Usage: pry [OPTIONS]
17
- Start a Pry session.
18
- See: `https://github.com/pry` for more information.
19
- Copyright (c) 2011 John Mair (banisterfiend)
20
- --
21
- }
22
-
23
- on :e, :exec, "A line of code to execute in context before the session starts", true
24
-
25
- on "no-pager", "Disable pager for long output" do
26
- Pry.config.pager = false
27
- end
28
-
29
- on "no-history", "Disable history loading" do
30
- Pry.config.history.should_load = false
31
- end
32
-
33
- on "no-color", "Disable syntax highlighting for session" do
34
- Pry.color = false
35
- end
36
-
37
- on :f, "Suppress loading of ~/.pryrc" do
38
- # load ~/.pryrc, if not suppressed with -f option
39
- Pry.config.should_load_rc = false
40
- end
41
-
42
- on "no-plugins", "Suppress loading of plugins." do
43
- # suppress plugins if given --no-plugins optino
44
- Pry.config.plugins.enabled = false
45
- end
46
-
47
- on "installed-plugins", "List installed plugins." do
48
- puts "Installed Plugins:"
49
- puts "--"
50
- Pry.locate_plugins.each do |plugin|
51
- puts "#{plugin.name}".ljust(18) + plugin.spec.summary
52
- end
53
- exit
54
- end
55
-
56
- on "simple-prompt", "Enable simple prompt mode" do
57
- Pry.prompt = Pry::SIMPLE_PROMPT
58
- end
59
-
60
- on :r, :require, "`require` a Ruby script at startup", true do |file|
61
- Pry.config.requires << file
62
- end
63
-
64
- on :I, "Add a path to the $LOAD_PATH", true do |path|
65
- $LOAD_PATH << path
66
- end
67
-
68
- on :v, :version, "Display the Pry version" do
69
- puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
70
- exit
71
- end
72
-
73
- on(:c, :context,
74
- "Start the session in the specified context. Equivalent to `context.pry` in a session.",
75
- true,
76
- :default => "TOPLEVEL_BINDING"
77
- )
78
- end
79
-
80
- # invoked via cli
81
- Pry.cli = true
82
-
83
- # create the actual context
84
- context = Pry.binding_for(eval(opts[:context]))
85
-
86
- if opts[:exec]
87
- exec_string = opts[:exec] + "\n"
88
- else
89
- exec_string = ""
90
- end
91
-
92
- # Start the session (running any code passed with -e, if there is any)
93
- Pry.start(context, :input => StringIO.new(exec_string))
94
-
15
+ # Process command line options and run Pry
16
+ Pry::CLI.parse_options
data/lib/pry.rb CHANGED
@@ -4,19 +4,19 @@
4
4
 
5
5
  require 'pp'
6
6
  require 'pry/helpers/base_helpers'
7
+ require 'pry/hooks'
8
+
7
9
  class Pry
8
10
  # The default hooks - display messages when beginning and ending Pry sessions.
9
- DEFAULT_HOOKS = {
10
- :before_session => proc do |out, target, _pry_|
11
- # ensure we're actually in a method
12
- file = target.eval('__FILE__')
13
-
14
- # /unknown/ for rbx
15
- if file == Pry.eval_path || (file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != "" && file != "-e")
16
- _pry_.process_line("whereami 5", "", target)
17
- end
11
+ DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
12
+ # ensure we're actually in a method
13
+ file = target.eval('__FILE__')
14
+
15
+ # /unknown/ for rbx
16
+ if file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != "" && file != "-e" || file == Pry.eval_path
17
+ _pry_.run_command("whereami 5", "", target)
18
18
  end
19
- }
19
+ end
20
20
 
21
21
  # The default print
22
22
  DEFAULT_PRINT = proc do |output, value|
@@ -36,6 +36,9 @@ class Pry
36
36
 
37
37
  colorized = Helpers::BaseHelpers.colorize_code(stringified.gsub(/#</, "%<#{nonce}"))
38
38
 
39
+ # avoid colour-leak from CodeRay and any of the users' previous output
40
+ colorized = colorized.sub(/(\n*)$/, "\e[0m\\1") if Pry.color
41
+
39
42
  Helpers::BaseHelpers.stagger_output("=> #{colorized.gsub(/%<(.*?)#{nonce}/, '#<\1')}", output)
40
43
  end
41
44
 
@@ -66,19 +69,11 @@ class Pry
66
69
  # The default prompt; includes the target and nesting level
67
70
  DEFAULT_PROMPT = [
68
71
  proc { |target_self, nest_level, pry|
69
- if nest_level == 0
70
- "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})> "
71
- else
72
- "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)}):#{nest_level}> "
73
- end
72
+ "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
74
73
  },
75
74
 
76
75
  proc { |target_self, nest_level, pry|
77
- if nest_level == 0
78
- "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})* "
79
- else
80
- "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)}):#{nest_level}* "
81
- end
76
+ "[#{pry.input_array.size}] pry(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
82
77
  }
83
78
  ]
84
79
 
@@ -151,7 +146,15 @@ class Pry
151
146
 
152
147
  # CommandErrors are caught by the REPL loop and displayed to the user. They
153
148
  # indicate an exceptional condition that's fatal to the current command.
154
- class CommandError < StandardError
149
+ class CommandError < StandardError; end
150
+ class NonMethodContextError < CommandError; end
151
+
152
+ # indicates obsolete API
153
+ class ObsoleteError < StandardError; end
154
+
155
+ # This is to keep from breaking under Rails 3.2 for people who are doing that
156
+ # IRB = Pry thing.
157
+ module ExtendCommandBundle
155
158
  end
156
159
  end
157
160
 
@@ -162,20 +165,21 @@ require "stringio"
162
165
  require "coderay"
163
166
  require "optparse"
164
167
  require "slop"
168
+ require "rbconfig"
165
169
 
166
- if RUBY_PLATFORM =~ /jruby/
170
+ if Pry::Helpers::BaseHelpers.jruby?
167
171
  begin
168
172
  require 'ffi'
169
173
  rescue LoadError
170
- $stderr.puts "Need to `gem install ffi`"
174
+ warn "Need to `gem install ffi`"
171
175
  end
172
176
  end
173
177
 
174
- if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
178
+ if Pry::Helpers::BaseHelpers.windows?
175
179
  begin
176
180
  require 'win32console'
177
181
  rescue LoadError
178
- $stderr.puts "Need to `gem install win32console`"
182
+ warn "Need to `gem install win32console`"
179
183
  exit 1
180
184
  end
181
185
  end
@@ -183,16 +187,19 @@ end
183
187
  require "pry/version"
184
188
  require "pry/rbx_method"
185
189
  require "pry/rbx_path"
190
+ require "pry/code"
186
191
  require "pry/method"
192
+ require "pry/wrapped_module"
187
193
  require "pry/history_array"
188
194
  require "pry/helpers"
189
195
  require "pry/history"
196
+ require "pry/command"
190
197
  require "pry/command_set"
191
198
  require "pry/commands"
192
- require "pry/command_context"
193
199
  require "pry/custom_completions"
194
200
  require "pry/completion"
195
201
  require "pry/plugins"
196
202
  require "pry/core_extensions"
197
203
  require "pry/pry_class"
198
204
  require "pry/pry_instance"
205
+ require "pry/cli"
@@ -0,0 +1,152 @@
1
+
2
+ class Pry
3
+
4
+ # Manage the processing of command line options
5
+ class CLI
6
+
7
+ NoOptionsError = Class.new(StandardError)
8
+
9
+ class << self
10
+
11
+ # @return [Proc] The Proc defining the valid command line options.
12
+ attr_accessor :options
13
+
14
+ # @return [Array] The Procs that process the parsed options.
15
+ attr_accessor :option_processors
16
+
17
+ # Add another set of CLI options (a Slop block)
18
+ def add_options(&block)
19
+ if options
20
+ old_options = options
21
+ self.options = proc do
22
+ instance_exec(&old_options)
23
+ instance_exec(&block)
24
+ end
25
+ else
26
+ self.options = block
27
+ end
28
+
29
+ self
30
+ end
31
+
32
+ # Bring in options defined in plugins
33
+ def add_plugin_options
34
+ Pry.plugins.values.each do |plugin|
35
+ plugin.load_cli_options
36
+ end
37
+
38
+ self
39
+ end
40
+
41
+ # Add a block responsible for processing parsed options.
42
+ def process_options(&block)
43
+ self.option_processors ||= []
44
+ option_processors << block
45
+
46
+ self
47
+ end
48
+
49
+ # Clear `options` and `option_processors`
50
+ def reset
51
+ self.options = nil
52
+ self.option_processors = nil
53
+ end
54
+
55
+ def parse_options(args=ARGV)
56
+ raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." if !options
57
+
58
+ opts = Slop.parse(args, :help => true, :multiple_switches => false, &options)
59
+ option_processors.each { |processor| processor.call(opts) } if option_processors # option processors are optional
60
+
61
+ self
62
+ end
63
+
64
+ end
65
+
66
+ reset
67
+ end
68
+ end
69
+
70
+ # Bring in options defined by plugins
71
+ Pry::CLI.add_plugin_options
72
+
73
+ # The default Pry command line options (before plugin options are included)
74
+ Pry::CLI.add_options do
75
+ banner %{Usage: pry [OPTIONS]
76
+ Start a Pry session.
77
+ See: `https://github.com/pry` for more information.
78
+ Copyright (c) 2011 John Mair (banisterfiend)
79
+ --
80
+ }
81
+ on :e, :exec, "A line of code to execute in context before the session starts", true
82
+
83
+ on "no-pager", "Disable pager for long output" do
84
+ Pry.config.pager = false
85
+ end
86
+
87
+ on "no-history", "Disable history loading" do
88
+ Pry.config.history.should_load = false
89
+ end
90
+
91
+ on "no-color", "Disable syntax highlighting for session" do
92
+ Pry.color = false
93
+ end
94
+
95
+ on :f, "Suppress loading of ~/.pryrc" do
96
+ # load ~/.pryrc, if not suppressed with -f option
97
+ Pry.config.should_load_rc = false
98
+ end
99
+
100
+ on "no-plugins", "Suppress loading of plugins." do
101
+ # suppress plugins if given --no-plugins optino
102
+ Pry.config.plugins.enabled = false
103
+ end
104
+
105
+ on "installed-plugins", "List installed plugins." do
106
+ puts "Installed Plugins:"
107
+ puts "--"
108
+ Pry.locate_plugins.each do |plugin|
109
+ puts "#{plugin.name}".ljust(18) + plugin.spec.summary
110
+ end
111
+ exit
112
+ end
113
+
114
+ on "simple-prompt", "Enable simple prompt mode" do
115
+ Pry.config.prompt = Pry::SIMPLE_PROMPT
116
+ end
117
+
118
+ on :r, :require, "`require` a Ruby script at startup", true do |file|
119
+ Pry.config.requires << file
120
+ end
121
+
122
+ on :I, "Add a path to the $LOAD_PATH", true do |path|
123
+ $LOAD_PATH << path
124
+ end
125
+
126
+ on :v, :version, "Display the Pry version" do
127
+ puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
128
+ exit
129
+ end
130
+
131
+ on(:c, :context,
132
+ "Start the session in the specified context. Equivalent to `context.pry` in a session.",
133
+ true,
134
+ :default => "TOPLEVEL_BINDING"
135
+ )
136
+ end.process_options do |opts|
137
+ # invoked via cli
138
+ Pry.cli = true
139
+
140
+ # create the actual context
141
+ context = Pry.binding_for(eval(opts[:context]))
142
+
143
+ if opts[:exec]
144
+ exec_string = opts[:exec] + "\n"
145
+ else
146
+ exec_string = ""
147
+ end
148
+
149
+ # Start the session (running any code passed with -e, if there is any)
150
+ Pry.start(context, :input => StringIO.new(exec_string))
151
+ end
152
+