mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Merge branch 'rking/bond' into HEAD
This commit is contained in:
commit
84c154e275
12 changed files with 128 additions and 31 deletions
2
Rakefile
2
Rakefile
|
@ -25,6 +25,8 @@ def apply_spec_defaults(s)
|
|||
s.add_development_dependency('bacon', '~> 1.1')
|
||||
s.add_development_dependency('open4', '~> 1.3')
|
||||
s.add_development_dependency('rake', '~> 0.9')
|
||||
# TODO: make this a plain dependency:
|
||||
s.add_development_dependency('bond', '~> 0.4.2')
|
||||
end
|
||||
|
||||
def check_dependencies
|
||||
|
|
60
lib/pry.rb
60
lib/pry.rb
|
@ -166,13 +166,13 @@ if Pry::Helpers::BaseHelpers.mri_18?
|
|||
end
|
||||
end
|
||||
|
||||
require "method_source"
|
||||
require 'method_source'
|
||||
require 'shellwords'
|
||||
require "stringio"
|
||||
require "coderay"
|
||||
require "optparse"
|
||||
require "slop"
|
||||
require "rbconfig"
|
||||
require 'stringio'
|
||||
require 'coderay'
|
||||
require 'optparse'
|
||||
require 'slop'
|
||||
require 'rbconfig'
|
||||
require 'tempfile'
|
||||
|
||||
begin
|
||||
|
@ -202,23 +202,31 @@ if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi
|
|||
end
|
||||
end
|
||||
|
||||
require "pry/version"
|
||||
require "pry/rbx_method"
|
||||
require "pry/rbx_path"
|
||||
require "pry/code"
|
||||
require "pry/method"
|
||||
require "pry/wrapped_module"
|
||||
require "pry/history_array"
|
||||
require "pry/helpers"
|
||||
require "pry/history"
|
||||
require "pry/command"
|
||||
require "pry/command_set"
|
||||
require "pry/commands"
|
||||
require "pry/custom_completions"
|
||||
require "pry/completion"
|
||||
require "pry/plugins"
|
||||
require "pry/core_extensions"
|
||||
require "pry/pry_class"
|
||||
require "pry/pry_instance"
|
||||
require "pry/cli"
|
||||
require "pry/pager"
|
||||
require 'pry/version'
|
||||
require 'pry/rbx_method'
|
||||
require 'pry/rbx_path'
|
||||
require 'pry/code'
|
||||
require 'pry/method'
|
||||
require 'pry/wrapped_module'
|
||||
require 'pry/history_array'
|
||||
require 'pry/helpers'
|
||||
require 'pry/history'
|
||||
require 'pry/command'
|
||||
require 'pry/command_set'
|
||||
require 'pry/commands'
|
||||
require 'pry/custom_completions'
|
||||
require 'pry/completion'
|
||||
require 'pry/plugins'
|
||||
require 'pry/core_extensions'
|
||||
require 'pry/pry_class'
|
||||
require 'pry/pry_instance'
|
||||
require 'pry/cli'
|
||||
require 'pry/pager'
|
||||
|
||||
begin
|
||||
require 'bond'
|
||||
rescue LoadError
|
||||
Pry.config.completer = Pry::InputCompleter
|
||||
else
|
||||
Pry.config.completer = Pry::BondCompleter
|
||||
end
|
||||
|
|
|
@ -392,6 +392,12 @@ class Pry
|
|||
@dependencies_met ||= command_dependencies_met?(command_options)
|
||||
end
|
||||
|
||||
# Generate completions for this command
|
||||
#
|
||||
# @param [String] search The line typed so far
|
||||
# @return [Array<String>] Completion words
|
||||
def complete(search); Bond::DefaultMission.completions; end
|
||||
|
||||
private
|
||||
|
||||
# Run the `#call` method and all the registered hooks.
|
||||
|
@ -499,6 +505,15 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
# Generate shell completions
|
||||
# @param [String] search The line typed so far
|
||||
# @return [Array<String>] the words to complete
|
||||
def complete(search)
|
||||
slop.map do |opt|
|
||||
[opt.long && "--#{opt.long}" || opt.short && "-#{opt.short}"]
|
||||
end.flatten(1).compact + super
|
||||
end
|
||||
|
||||
# A function called just before `options(opt)` as part of `call`.
|
||||
#
|
||||
# This function can be used to set up any context your command needs to run, for example
|
||||
|
|
|
@ -348,6 +348,20 @@ class Pry
|
|||
command.new(context).call_safely(*args)
|
||||
end
|
||||
|
||||
# Generate completions for the user's search.
|
||||
# @param [String] search The line to search for
|
||||
# @param [Hash] context The context to create the command with
|
||||
# @return [Array<String>]
|
||||
def complete(search, context={})
|
||||
if command = find_command(search)
|
||||
command.new(context).complete(search)
|
||||
else
|
||||
commands.keys.select do |x|
|
||||
String === x && x.start_with?(search)
|
||||
end + Bond::DefaultMission.completions
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_options(match)
|
||||
|
|
|
@ -26,6 +26,10 @@ class Pry
|
|||
opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
|
||||
end
|
||||
|
||||
def complete(search)
|
||||
super + Bond::Rc.files(search.split(" ").last || '')
|
||||
end
|
||||
|
||||
def process
|
||||
if [opts.present?(:ex), opts.present?(:temp), opts.present?(:in), !args.empty?].count(true) > 1
|
||||
raise CommandError, "Only one of --ex, --temp, --in and FILE may be specified."
|
||||
|
|
|
@ -1,9 +1,22 @@
|
|||
# taken from irb
|
||||
|
||||
require "readline"
|
||||
|
||||
class Pry
|
||||
|
||||
module BondCompleter
|
||||
|
||||
def self.build_completion_proc(target, pry=nil, commands=[""])
|
||||
Bond.restart(:eval_binding => lambda{ pry.current_context })
|
||||
Bond.complete(:on => /\A/) do |input|
|
||||
Pry.commands.complete(input.line,
|
||||
:pry_instance => pry,
|
||||
:target => pry.current_context,
|
||||
:command_set => pry.commands)
|
||||
end
|
||||
|
||||
proc{ |*a| Bond.agent.call(*a) }
|
||||
end
|
||||
end
|
||||
|
||||
# Implements tab completion for Readline in Pry
|
||||
module InputCompleter
|
||||
|
||||
|
@ -42,6 +55,7 @@ class Pry
|
|||
# @param [Binding] target The current binding context.
|
||||
# @param [Array<String>] commands The array of Pry commands.
|
||||
def self.build_completion_proc(target, pry=nil, commands=[""])
|
||||
|
||||
proc do |input|
|
||||
|
||||
# if there are multiple contexts e.g. cd 1/2/3
|
||||
|
|
|
@ -228,6 +228,9 @@ class Pry
|
|||
# Pry.config.extra_sticky_locals = { :random_number => proc {
|
||||
# rand(10) } }
|
||||
attr_accessor :extra_sticky_locals
|
||||
|
||||
# @return [#build_completion_proc] A completer to use.
|
||||
attr_accessor :completer
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -360,7 +360,7 @@ class Pry
|
|||
@indent.reset if eval_string.empty?
|
||||
|
||||
current_prompt = select_prompt(eval_string, target)
|
||||
completion_proc = Pry::InputCompleter.build_completion_proc(target, self,
|
||||
completion_proc = Pry.config.completer.build_completion_proc(target, self,
|
||||
instance_eval(&custom_completions))
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["John Mair (banisterfiend)", "Conrad Irwin"]
|
||||
s.date = "2012-08-13"
|
||||
s.date = "2012-08-18"
|
||||
s.description = "An IRB alternative and runtime developer console"
|
||||
s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com"]
|
||||
s.executables = ["pry"]
|
||||
|
@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency(%q<bacon>, ["~> 1.1"])
|
||||
s.add_development_dependency(%q<open4>, ["~> 1.3"])
|
||||
s.add_development_dependency(%q<rake>, ["~> 0.9"])
|
||||
s.add_development_dependency(%q<bond>, ["~> 0.4.2"])
|
||||
else
|
||||
s.add_dependency(%q<coderay>, ["~> 1.0.5"])
|
||||
s.add_dependency(%q<slop>, ["~> 3.3.1"])
|
||||
|
@ -34,6 +35,7 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency(%q<bacon>, ["~> 1.1"])
|
||||
s.add_dependency(%q<open4>, ["~> 1.3"])
|
||||
s.add_dependency(%q<rake>, ["~> 0.9"])
|
||||
s.add_dependency(%q<bond>, ["~> 0.4.2"])
|
||||
end
|
||||
else
|
||||
s.add_dependency(%q<coderay>, ["~> 1.0.5"])
|
||||
|
@ -42,5 +44,6 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency(%q<bacon>, ["~> 1.1"])
|
||||
s.add_dependency(%q<open4>, ["~> 1.3"])
|
||||
s.add_dependency(%q<rake>, ["~> 0.9"])
|
||||
s.add_dependency(%q<bond>, ["~> 0.4.2"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -696,6 +696,20 @@ describe "Pry::Command" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'complete' do
|
||||
it 'should return the arguments that are defined' do
|
||||
@set.create_command "torrid" do
|
||||
def options(opt)
|
||||
opt.on :test
|
||||
opt.on :lest
|
||||
opt.on :pests
|
||||
end
|
||||
end
|
||||
|
||||
@set.complete('torrid ').should.include('--test')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'group' do
|
||||
before do
|
||||
@set.import(
|
||||
|
|
|
@ -610,4 +610,16 @@ describe Pry::CommandSet do
|
|||
@set.process_line('nannnnnny oggggg')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.complete' do
|
||||
it "should list all command names" do
|
||||
@set.create_command('susan'){ }
|
||||
@set.complete('sus').should.include 'susan'
|
||||
end
|
||||
|
||||
it "should delegate to commands" do
|
||||
@set.create_command('susan'){ def complete(search); ['--foo']; end }
|
||||
@set.complete('susan ').should == ['--foo']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,11 @@ def completer_test(bind, pry=nil, assert_flag=true)
|
|||
return proc {|*symbols| symbols.each(&test) }
|
||||
end
|
||||
|
||||
describe 'bond-based completion' do
|
||||
it 'should pull in Bond by default' do
|
||||
Pry.config.completer.should == Pry::BondCompleter
|
||||
end
|
||||
end
|
||||
|
||||
describe Pry::InputCompleter do
|
||||
|
||||
|
@ -20,9 +25,13 @@ describe Pry::InputCompleter do
|
|||
module SymbolyName
|
||||
def self.name; :symboly_name; end
|
||||
end
|
||||
|
||||
$default_completer = Pry.config.completer
|
||||
Pry.config.completer = Pry::InputCompleter
|
||||
end
|
||||
|
||||
after do
|
||||
Pry.config.completer = $default_completer
|
||||
Object.remove_const :SymbolyName
|
||||
end
|
||||
|
||||
|
@ -216,4 +225,3 @@ describe Pry::InputCompleter do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue