pry 0.9.10pre1-java → 0.9.11-java
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/.travis.yml +3 -1
- data/CHANGELOG +63 -2
- data/CONTRIBUTORS +43 -25
- data/Gemfile +7 -0
- data/Guardfile +62 -0
- data/README.markdown +4 -4
- data/Rakefile +34 -35
- data/lib/pry.rb +107 -54
- data/lib/pry/cli.rb +34 -11
- data/lib/pry/code.rb +165 -182
- data/lib/pry/code/code_range.rb +70 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +153 -0
- data/lib/pry/command.rb +160 -22
- data/lib/pry/command_set.rb +37 -26
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +53 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +78 -0
- data/lib/pry/commands/cat/file_formatter.rb +84 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +30 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/deprecated_commands.rb +2 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +206 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
- data/lib/pry/commands/edit/method_patcher.rb +122 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +24 -0
- data/lib/pry/commands/find_method.rb +199 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +29 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +95 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +161 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +51 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/ls.rb +339 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +69 -0
- data/lib/pry/commands/pry_backtrace.rb +26 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +39 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +56 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +43 -0
- data/lib/pry/commands/shell_mode.rb +27 -0
- data/lib/pry/commands/show_doc.rb +78 -0
- data/lib/pry/commands/show_info.rb +139 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +37 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +20 -0
- data/lib/pry/commands/whereami.rb +114 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/completion.rb +120 -46
- data/lib/pry/config.rb +11 -0
- data/lib/pry/core_extensions.rb +30 -19
- data/lib/pry/editor.rb +129 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +89 -119
- data/lib/pry/helpers/command_helpers.rb +7 -122
- data/lib/pry/helpers/table.rb +100 -0
- data/lib/pry/helpers/text.rb +4 -4
- data/lib/pry/history_array.rb +5 -0
- data/lib/pry/hooks.rb +1 -3
- data/lib/pry/indent.rb +104 -30
- data/lib/pry/method.rb +66 -22
- data/lib/pry/module_candidate.rb +26 -15
- data/lib/pry/pager.rb +70 -0
- data/lib/pry/plugins.rb +1 -2
- data/lib/pry/pry_class.rb +63 -22
- data/lib/pry/pry_instance.rb +58 -37
- data/lib/pry/rubygem.rb +74 -0
- data/lib/pry/terminal_info.rb +43 -0
- data/lib/pry/test/helper.rb +185 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +58 -24
- data/pry.gemspec +21 -37
- data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
- data/spec/code_object_spec.rb +277 -0
- data/{test/test_code.rb → spec/code_spec.rb} +19 -1
- data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
- data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
- data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
- data/{test/test_command.rb → spec/command_spec.rb} +250 -149
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +19 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +727 -0
- data/spec/commands/exit_all_spec.rb +34 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +34 -0
- data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +75 -0
- data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
- data/spec/commands/hist_spec.rb +181 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +177 -0
- data/spec/commands/play_spec.rb +140 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +378 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +597 -0
- data/spec/commands/whereami_spec.rb +154 -0
- data/spec/completion_spec.rb +233 -0
- data/spec/control_d_handler_spec.rb +58 -0
- data/spec/editor_spec.rb +79 -0
- data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
- data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
- data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
- data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/{test → spec/fixtures}/testrc +0 -0
- data/{test → spec/fixtures}/testrcbad +0 -0
- data/spec/helper.rb +34 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +43 -0
- data/spec/helpers/table_spec.rb +83 -0
- data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
- data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
- data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
- data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
- data/{test/test_method.rb → spec/method_spec.rb} +65 -1
- data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
- data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
- data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
- data/spec/pry_output_spec.rb +95 -0
- data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
- data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
- data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
- data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
- metadata +239 -115
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/test/helper.rb +0 -223
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/test_cd.rb +0 -321
- data/test/test_default_commands/test_context.rb +0 -288
- data/test/test_default_commands/test_documentation.rb +0 -315
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_pry_output.rb +0 -41
@@ -0,0 +1,25 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Nesting < Pry::ClassCommand
|
3
|
+
match 'nesting'
|
4
|
+
group 'Navigating Pry'
|
5
|
+
description 'Show nesting information.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Show nesting information.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
output.puts 'Nesting status:'
|
13
|
+
output.puts '--'
|
14
|
+
_pry_.binding_stack.each_with_index do |obj, level|
|
15
|
+
if level == 0
|
16
|
+
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)"
|
17
|
+
else
|
18
|
+
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Pry::Commands.add_command(Pry::Command::Nesting)
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Play < Pry::ClassCommand
|
3
|
+
match 'play'
|
4
|
+
group 'Editing'
|
5
|
+
description 'Playback a string variable or a method or a file as input.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: play [OPTIONS] [--help]
|
9
|
+
|
10
|
+
The play command enables you to replay code from files and methods as if they
|
11
|
+
were entered directly in the Pry REPL.
|
12
|
+
|
13
|
+
play --lines 149..153
|
14
|
+
play -i 20 --lines 1..3
|
15
|
+
play Pry#repl --lines 1..-1
|
16
|
+
play Rakefile --lines 5
|
17
|
+
|
18
|
+
https://github.com/pry/pry/wiki/User-Input#wiki-Play
|
19
|
+
BANNER
|
20
|
+
|
21
|
+
def options(opt)
|
22
|
+
CodeCollector.inject_options(opt)
|
23
|
+
|
24
|
+
opt.on :open, 'Plays the select content except except' \
|
25
|
+
' the last line. Useful for replaying methods and leaving the method definition "open". `amend-line`' \
|
26
|
+
' can then be used to modify the method.'
|
27
|
+
end
|
28
|
+
|
29
|
+
def process
|
30
|
+
@cc = CodeCollector.new(args, opts, _pry_)
|
31
|
+
|
32
|
+
perform_play
|
33
|
+
run "show-input" unless Pry::Code.complete_expression?(eval_string)
|
34
|
+
end
|
35
|
+
|
36
|
+
def perform_play
|
37
|
+
eval_string << (opts.present?(:open) ? restrict_to_lines(content, (0..-2)) : content)
|
38
|
+
run "fix-indent"
|
39
|
+
end
|
40
|
+
|
41
|
+
def should_use_default_file?
|
42
|
+
!args.first && !opts.present?(:in) && !opts.present?(:out)
|
43
|
+
end
|
44
|
+
|
45
|
+
def content
|
46
|
+
if should_use_default_file?
|
47
|
+
file_content
|
48
|
+
else
|
49
|
+
@cc.content
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# The file to play from when no code object is specified.
|
54
|
+
# e.g `play --lines 4..10`
|
55
|
+
def default_file
|
56
|
+
target.eval("__FILE__") && File.expand_path(target.eval("__FILE__"))
|
57
|
+
end
|
58
|
+
|
59
|
+
def file_content
|
60
|
+
if default_file && File.exists?(default_file)
|
61
|
+
@cc.restrict_to_lines(File.read(default_file), @cc.line_range)
|
62
|
+
else
|
63
|
+
raise CommandError, "File does not exist! File was: #{default_file.inspect}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Pry::Commands.add_command(Pry::Command::Play)
|
69
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::PryBacktrace < Pry::ClassCommand
|
3
|
+
match 'pry-backtrace'
|
4
|
+
group 'Context'
|
5
|
+
description 'Show the backtrace for the Pry session.'
|
6
|
+
|
7
|
+
banner <<-BANNER
|
8
|
+
Usage: pry-backtrace [OPTIONS] [--help]
|
9
|
+
|
10
|
+
Show the backtrace for the position in the code where Pry was started. This can
|
11
|
+
be used to infer the behavior of the program immediately before it entered Pry,
|
12
|
+
just like the backtrace property of an exception.
|
13
|
+
|
14
|
+
NOTE: if you are looking for the backtrace of the most recent exception raised,
|
15
|
+
just type: `_ex_.backtrace` instead.
|
16
|
+
See: https://github.com/pry/pry/wiki/Special-Locals
|
17
|
+
BANNER
|
18
|
+
|
19
|
+
def process
|
20
|
+
stagger_output text.bold('Backtrace:') +
|
21
|
+
"\n--\n" + _pry_.backtrace.join("\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Pry::Commands.add_command(Pry::Command::PryBacktrace)
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Version < Pry::ClassCommand
|
3
|
+
match 'pry-version'
|
4
|
+
group 'Misc'
|
5
|
+
description 'Show Pry version.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Show Pry version.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Pry::Commands.add_command(Pry::Command::Version)
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Pry
|
2
|
+
# N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing.
|
3
|
+
class Command::RaiseUp < Pry::ClassCommand
|
4
|
+
match /raise-up(!?\b.*)/
|
5
|
+
group 'Context'
|
6
|
+
description 'Raise an exception out of the current pry instance.'
|
7
|
+
command_options :listing => 'raise-up'
|
8
|
+
|
9
|
+
banner <<-BANNER
|
10
|
+
Raise up, like exit, allows you to quit pry. Instead of returning a value
|
11
|
+
however, it raises an exception. If you don't provide the exception to be
|
12
|
+
raised, it will use the most recent exception (in pry `_ex_`).
|
13
|
+
|
14
|
+
When called as raise-up! (with an exclamation mark), this command raises the
|
15
|
+
exception through any nested prys you have created by "cd"ing into objects.
|
16
|
+
|
17
|
+
raise-up "get-me-out-of-here"
|
18
|
+
|
19
|
+
# This is equivalent to the command above.
|
20
|
+
raise "get-me-out-of-here"
|
21
|
+
raise-up
|
22
|
+
BANNER
|
23
|
+
|
24
|
+
def process
|
25
|
+
return stagger_output help if captures[0] =~ /(-h|--help)\b/
|
26
|
+
# Handle 'raise-up', 'raise-up "foo"', 'raise-up RuntimeError, 'farble' in a rubyesque manner
|
27
|
+
target.eval("_pry_.raise_up#{captures[0]}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Pry::Commands.add_command(Pry::Command::RaiseUp)
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ReloadCode < Pry::ClassCommand
|
3
|
+
match 'reload-code'
|
4
|
+
group 'Misc'
|
5
|
+
description 'Reload the source file that contains the specified code object.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Reload the source file that contains the specified code object.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
code_object = Pry::CodeObject.lookup(obj_name, _pry_)
|
13
|
+
|
14
|
+
check_for_reloadability(code_object)
|
15
|
+
reload_code_object(code_object)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def reload_code_object(code_object)
|
21
|
+
load code_object.source_file
|
22
|
+
output.puts "#{obj_name} was reloaded!"
|
23
|
+
end
|
24
|
+
|
25
|
+
def obj_name
|
26
|
+
@obj_name ||= args.empty? ? "self" : args.join(" ")
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_for_reloadability(code_object)
|
30
|
+
if !code_object
|
31
|
+
raise CommandError, "Cannot locate #{obj_name}!"
|
32
|
+
elsif !File.exists?(code_object.source_file)
|
33
|
+
raise CommandError, "Cannot reload #{obj_name} as it has no associated file on disk. File found was: #{code_object.source_file}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Pry::Commands.add_command(Pry::Command::ReloadCode)
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Reset < Pry::ClassCommand
|
3
|
+
match 'reset'
|
4
|
+
group 'Context'
|
5
|
+
description 'Reset the REPL to a clean state.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Reset the REPL to a clean state.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
output.puts 'Pry reset.'
|
13
|
+
exec 'pry'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Pry::Commands.add_command(Pry::Command::Reset)
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Ri < Pry::ClassCommand
|
3
|
+
match 'ri'
|
4
|
+
group 'Introspection'
|
5
|
+
description 'View ri documentation.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: ri [spec]
|
9
|
+
|
10
|
+
View ri documentation. Relies on the "rdoc" gem being installed.
|
11
|
+
See also "show-doc" command.
|
12
|
+
|
13
|
+
ri Array#each
|
14
|
+
BANNER
|
15
|
+
|
16
|
+
def process(spec)
|
17
|
+
# Lazily load RI
|
18
|
+
require 'rdoc/ri/driver'
|
19
|
+
|
20
|
+
unless defined? RDoc::RI::PryDriver
|
21
|
+
|
22
|
+
# Subclass RI so that it formats its output nicely, and uses `lesspipe`.
|
23
|
+
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
24
|
+
|
25
|
+
subclass.class_eval do
|
26
|
+
def page
|
27
|
+
paging_text = StringIO.new
|
28
|
+
yield paging_text
|
29
|
+
Pry::Pager.page(paging_text.string)
|
30
|
+
end
|
31
|
+
|
32
|
+
def formatter(io)
|
33
|
+
if @formatter_klass then
|
34
|
+
@formatter_klass.new
|
35
|
+
else
|
36
|
+
RDoc::Markup::ToAnsi.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
RDoc::RI.const_set :PryDriver, subclass # hook it up!
|
42
|
+
end
|
43
|
+
|
44
|
+
# Spin-up an RI insance.
|
45
|
+
ri = RDoc::RI::PryDriver.new :use_stdout => true, :interactive => false
|
46
|
+
|
47
|
+
begin
|
48
|
+
ri.display_names [spec] # Get the documentation (finally!)
|
49
|
+
rescue RDoc::RI::Driver::NotFoundError => e
|
50
|
+
output.puts "error: '#{e.name}' not found"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Pry::Commands.add_command(Pry::Command::Ri)
|
56
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pry/commands/code_collector'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Command::SaveFile < Pry::ClassCommand
|
5
|
+
match 'save-file'
|
6
|
+
group 'Input and Output'
|
7
|
+
description 'Export to a file using content from the REPL.'
|
8
|
+
|
9
|
+
banner <<-'BANNER'
|
10
|
+
Usage: save-file [OPTIONS] --to [FILE]
|
11
|
+
|
12
|
+
Export to a file using content from the REPL.
|
13
|
+
|
14
|
+
save-file my_method --to hello.rb
|
15
|
+
save-file -i 1..10 --to hello.rb --append
|
16
|
+
save-file show-method --to my_command.rb
|
17
|
+
save-file sample_file.rb --lines 2..10 --to output_file.rb
|
18
|
+
BANNER
|
19
|
+
|
20
|
+
def options(opt)
|
21
|
+
CodeCollector.inject_options(opt)
|
22
|
+
|
23
|
+
opt.on :to=, "Specify the output file path"
|
24
|
+
opt.on :a, :append, "Append output to file"
|
25
|
+
end
|
26
|
+
|
27
|
+
def process
|
28
|
+
@cc = CodeCollector.new(args, opts, _pry_)
|
29
|
+
raise CommandError, "Found no code to save." if @cc.content.empty?
|
30
|
+
|
31
|
+
if !file_name
|
32
|
+
display_content
|
33
|
+
else
|
34
|
+
save_file
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def file_name
|
39
|
+
opts[:to] || nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def save_file
|
43
|
+
File.open(file_name, mode) do |f|
|
44
|
+
f.puts @cc.content
|
45
|
+
end
|
46
|
+
output.puts "#{file_name} successfully saved"
|
47
|
+
end
|
48
|
+
|
49
|
+
def display_content
|
50
|
+
output.puts @cc.content
|
51
|
+
output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
|
52
|
+
output.puts "No file saved!\n--"
|
53
|
+
end
|
54
|
+
|
55
|
+
def mode
|
56
|
+
opts.present?(:append) ? "a" : "w"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Pry::Commands.add_command(Pry::Command::SaveFile)
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ShellCommand < Pry::ClassCommand
|
3
|
+
match /\.(.*)/
|
4
|
+
group 'Input and Output'
|
5
|
+
description "All text following a '.' is forwarded to the shell."
|
6
|
+
command_options :listing => '.<shell command>', :use_prefix => false,
|
7
|
+
:takes_block => true
|
8
|
+
|
9
|
+
banner <<-'BANNER'
|
10
|
+
Usage: .COMMAND_NAME
|
11
|
+
|
12
|
+
All text following a "." is forwarded to the shell.
|
13
|
+
|
14
|
+
.ls -aF
|
15
|
+
.uname
|
16
|
+
BANNER
|
17
|
+
|
18
|
+
def process(cmd)
|
19
|
+
if cmd =~ /^cd\s+(.+)/i
|
20
|
+
dest = $1
|
21
|
+
begin
|
22
|
+
Dir.chdir File.expand_path(dest)
|
23
|
+
rescue Errno::ENOENT
|
24
|
+
raise CommandError, "No such directory: #{dest}"
|
25
|
+
end
|
26
|
+
else
|
27
|
+
pass_block(cmd)
|
28
|
+
|
29
|
+
if command_block
|
30
|
+
command_block.call `#{cmd}`
|
31
|
+
else
|
32
|
+
Pry.config.system.call(output, cmd, _pry_)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def complete(search)
|
38
|
+
super + Bond::Rc.files(search.split(" ").last || '')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ShellMode < Pry::ClassCommand
|
3
|
+
match 'shell-mode'
|
4
|
+
group 'Input and Output'
|
5
|
+
description 'Toggle shell mode. Bring in pwd prompt and file completion.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Toggle shell mode. Bring in pwd prompt and file completion.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
case _pry_.prompt
|
13
|
+
when Pry::SHELL_PROMPT
|
14
|
+
_pry_.pop_prompt
|
15
|
+
_pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS
|
16
|
+
else
|
17
|
+
_pry_.push_prompt Pry::SHELL_PROMPT
|
18
|
+
_pry_.custom_completions = Pry::FILE_COMPLETIONS
|
19
|
+
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target,
|
20
|
+
_pry_.instance_eval(&Pry::FILE_COMPLETIONS)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Pry::Commands.add_command(Pry::Command::ShellMode)
|
26
|
+
Pry::Commands.alias_command 'file-mode', 'shell-mode'
|
27
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'pry/commands/show_info'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Command::ShowDoc < Command::ShowInfo
|
5
|
+
include Pry::Helpers::DocumentationHelpers
|
6
|
+
|
7
|
+
match 'show-doc'
|
8
|
+
group 'Introspection'
|
9
|
+
description 'Show the documentation for a method or class.'
|
10
|
+
|
11
|
+
banner <<-BANNER
|
12
|
+
Usage: show-doc [OPTIONS] [METH]
|
13
|
+
Aliases: ?
|
14
|
+
|
15
|
+
Show the documentation for a method or class. Tries instance methods first and
|
16
|
+
then methods by default.
|
17
|
+
|
18
|
+
show-doc hi_method # docs for hi_method
|
19
|
+
show-doc Pry # for Pry class
|
20
|
+
show-doc Pry -a # for all definitions of Pry class (all monkey patches)
|
21
|
+
BANNER
|
22
|
+
|
23
|
+
# The docs for code_object prepared for display.
|
24
|
+
def content_for(code_object)
|
25
|
+
Code.new(render_doc_markup_for(code_object),
|
26
|
+
start_line_for(code_object), :text).
|
27
|
+
with_line_numbers(use_line_numbers?).to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
# process the markup (if necessary) and apply colors
|
31
|
+
def render_doc_markup_for(code_object)
|
32
|
+
docs = docs_for(code_object)
|
33
|
+
|
34
|
+
if code_object.command?
|
35
|
+
# command '--help' shouldn't use markup highlighting
|
36
|
+
docs
|
37
|
+
else
|
38
|
+
process_comment_markup(docs)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return docs for the code_object, adjusting for whether the code_object
|
43
|
+
# has yard docs available, in which case it returns those.
|
44
|
+
# (note we only have to check yard docs for modules since they can
|
45
|
+
# have multiple docs, but methods can only be doc'd once so we
|
46
|
+
# dont need to check them)
|
47
|
+
def docs_for(code_object)
|
48
|
+
if code_object.module_with_yard_docs?
|
49
|
+
# yard docs
|
50
|
+
code_object.yard_doc
|
51
|
+
else
|
52
|
+
# normal docs (i.e comments above method/module/command)
|
53
|
+
code_object.doc
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Which sections to include in the 'header', can toggle: :owner,
|
58
|
+
# :signature and visibility.
|
59
|
+
def header_options
|
60
|
+
super.merge :signature => true
|
61
|
+
end
|
62
|
+
|
63
|
+
# figure out start line of docs by back-calculating based on
|
64
|
+
# number of lines in the comment and the start line of the code_object
|
65
|
+
# @return [Fixnum] start line of docs
|
66
|
+
def start_line_for(code_object)
|
67
|
+
if code_object.command? || opts.present?(:'base-one')
|
68
|
+
1
|
69
|
+
else
|
70
|
+
code_object.source_line.nil? ? 1 :
|
71
|
+
(code_object.source_line - code_object.doc.lines.count)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Pry::Commands.add_command(Pry::Command::ShowDoc)
|
77
|
+
Pry::Commands.alias_command '?', 'show-doc'
|
78
|
+
end
|