pry 0.9.7.4 → 0.9.8pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -3
- data/README.markdown +3 -1
- data/Rakefile +48 -31
- data/bin/pry +2 -80
- data/lib/pry.rb +17 -20
- data/lib/pry/cli.rb +152 -0
- data/lib/pry/command_processor.rb +13 -0
- data/lib/pry/command_set.rb +102 -9
- data/lib/pry/config.rb +28 -6
- data/lib/pry/default_commands/context.rb +9 -8
- data/lib/pry/default_commands/documentation.rb +55 -13
- data/lib/pry/default_commands/easter_eggs.rb +1 -1
- data/lib/pry/default_commands/input.rb +25 -25
- data/lib/pry/default_commands/introspection.rb +19 -18
- data/lib/pry/default_commands/ls.rb +23 -38
- data/lib/pry/default_commands/shell.rb +47 -15
- data/lib/pry/helpers/command_helpers.rb +28 -6
- data/lib/pry/helpers/options_helpers.rb +7 -4
- data/lib/pry/helpers/text.rb +23 -3
- data/lib/pry/history.rb +55 -17
- data/lib/pry/history_array.rb +2 -0
- data/lib/pry/hooks.rb +108 -0
- data/lib/pry/indent.rb +9 -5
- data/lib/pry/method.rb +99 -50
- data/lib/pry/plugins.rb +10 -2
- data/lib/pry/pry_class.rb +48 -20
- data/lib/pry/pry_instance.rb +106 -91
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +73 -0
- data/man/pry.1 +195 -0
- data/man/pry.1.html +204 -0
- data/man/pry.1.ronn +141 -0
- data/pry.gemspec +21 -24
- data/test/helper.rb +12 -3
- data/test/test_cli.rb +78 -0
- data/test/test_command_set.rb +193 -1
- data/test/test_default_commands/test_context.rb +19 -4
- data/test/test_default_commands/test_input.rb +2 -2
- data/test/test_default_commands/test_introspection.rb +63 -6
- data/test/test_default_commands/test_ls.rb +8 -35
- data/test/test_default_commands/test_shell.rb +36 -1
- data/test/test_hooks.rb +175 -0
- data/test/test_indent.rb +2 -0
- data/test/test_method.rb +10 -0
- data/test/test_pry.rb +35 -34
- data/test/test_pry_history.rb +24 -24
- data/test/test_syntax_checking.rb +47 -0
- data/test/test_wrapped_module.rb +71 -0
- metadata +40 -34
data/.gitignore
CHANGED
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -1,32 +1,41 @@
|
|
1
1
|
require 'rake/clean'
|
2
|
-
require '
|
2
|
+
require 'rubygems/package_task'
|
3
3
|
|
4
4
|
$:.unshift 'lib'
|
5
5
|
require 'pry/version'
|
6
6
|
|
7
|
-
CLOBBER.include(
|
8
|
-
CLEAN.include(
|
9
|
-
"**/*.rbc", "**/.#*.*")
|
7
|
+
CLOBBER.include('**/*~', '**/*#*', '**/*.log')
|
8
|
+
CLEAN.include('**/*#*', '**/*#*.*', '**/*_flymake*.*', '**/*_flymake', '**/*.rbc', '**/.#*.*')
|
10
9
|
|
11
10
|
def apply_spec_defaults(s)
|
12
|
-
s.name =
|
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 =
|
20
|
-
s.executables = [
|
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(
|
24
|
-
s.add_dependency(
|
25
|
-
s.add_dependency(
|
26
|
-
s.
|
27
|
-
s.add_development_dependency(
|
28
|
-
s.add_development_dependency(
|
29
|
-
|
22
|
+
s.add_dependency('coderay', '~> 0.9')
|
23
|
+
s.add_dependency('slop', ['>= 2.4.1', '< 3'])
|
24
|
+
s.add_dependency('method_source','~> 0.6')
|
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
|
+
|
33
|
+
ENV["BUNDLE_GEMFILE"] = File.expand_path("../Gemfile", __FILE__)
|
34
|
+
Bundler.definition.missing_specs
|
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,33 +43,35 @@ 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 "
|
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 "
|
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
|
+
|
57
68
|
namespace :ruby do
|
58
69
|
spec = Gem::Specification.new do |s|
|
59
70
|
apply_spec_defaults(s)
|
60
71
|
s.platform = Gem::Platform::RUBY
|
61
72
|
end
|
62
73
|
|
63
|
-
|
74
|
+
Gem::PackageTask.new(spec) do |pkg|
|
64
75
|
pkg.need_zip = false
|
65
76
|
pkg.need_tar = false
|
66
77
|
end
|
@@ -76,11 +87,11 @@ end
|
|
76
87
|
namespace :jruby do
|
77
88
|
spec = Gem::Specification.new do |s|
|
78
89
|
apply_spec_defaults(s)
|
79
|
-
s.add_dependency(
|
80
|
-
s.platform =
|
90
|
+
s.add_dependency('spoon', '~> 0.0')
|
91
|
+
s.platform = 'java'
|
81
92
|
end
|
82
93
|
|
83
|
-
|
94
|
+
Gem::PackageTask.new(spec) do |pkg|
|
84
95
|
pkg.need_zip = false
|
85
96
|
pkg.need_tar = false
|
86
97
|
end
|
@@ -91,11 +102,11 @@ end
|
|
91
102
|
namespace v do
|
92
103
|
spec = Gem::Specification.new do |s|
|
93
104
|
apply_spec_defaults(s)
|
94
|
-
s.add_dependency(
|
105
|
+
s.add_dependency('win32console', '~> 1.3')
|
95
106
|
s.platform = "i386-#{v}"
|
96
107
|
end
|
97
108
|
|
98
|
-
|
109
|
+
Gem::PackageTask.new(spec) do |pkg|
|
99
110
|
pkg.need_zip = false
|
100
111
|
pkg.need_tar = false
|
101
112
|
end
|
@@ -103,10 +114,16 @@ end
|
|
103
114
|
end
|
104
115
|
|
105
116
|
desc "build all platform gems at once"
|
106
|
-
task :gems => [:clean, :rmgems,
|
117
|
+
task :gems => [:clean, :rmgems, 'ruby:gem', 'mswin32:gem', 'mingw32:gem', 'jruby:gem']
|
107
118
|
|
108
119
|
desc "remove all platform gems"
|
109
|
-
task :rmgems => [
|
120
|
+
task :rmgems => ['ruby:clobber_package']
|
121
|
+
|
122
|
+
desc "reinstall gem"
|
123
|
+
task :reinstall => :gems do
|
124
|
+
sh "gem uninstall pry" rescue nil
|
125
|
+
sh "gem install #{File.dirname(__FILE__)}/pkg/pry-#{Pry::VERSION}.gem"
|
126
|
+
end
|
110
127
|
|
111
128
|
desc "build and push latest gems"
|
112
129
|
task :pushgems => :gems do
|
data/bin/pry
CHANGED
@@ -12,83 +12,5 @@ rescue LoadError
|
|
12
12
|
require 'pry'
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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"
|
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
|
-
|
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
|
-
|
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
|
|
@@ -184,6 +179,7 @@ require "pry/version"
|
|
184
179
|
require "pry/rbx_method"
|
185
180
|
require "pry/rbx_path"
|
186
181
|
require "pry/method"
|
182
|
+
require "pry/wrapped_module"
|
187
183
|
require "pry/history_array"
|
188
184
|
require "pry/helpers"
|
189
185
|
require "pry/history"
|
@@ -196,3 +192,4 @@ require "pry/plugins"
|
|
196
192
|
require "pry/core_extensions"
|
197
193
|
require "pry/pry_class"
|
198
194
|
require "pry/pry_instance"
|
195
|
+
require "pry/cli"
|
data/lib/pry/cli.rb
ADDED
@@ -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
|
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
|
+
|