Merge branch 'dev' of github.com:banister/pry into dev

This commit is contained in:
Rob Gleeson 2011-05-07 16:04:17 +01:00
commit 5a85ea04d9
14 changed files with 35 additions and 41 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ Makefile
*.so *.so
*.o *.o
*.def *.def
*.rbc
doc/ doc/
pkg/ pkg/
coverage/ coverage/

View File

@ -34,15 +34,12 @@ class Pry
include Pry::Helpers::BaseHelpers include Pry::Helpers::BaseHelpers
attr_reader :commands attr_reader :commands
attr_reader :name
attr_reader :helper_module attr_reader :helper_module
# @param [Symbol] name Name of the command set
# @param [Array<CommandSet>] imported_sets Sets which will be imported # @param [Array<CommandSet>] imported_sets Sets which will be imported
# automatically # automatically
# @yield Optional block run to define commands # @yield Optional block run to define commands
def initialize(name, *imported_sets, &block) def initialize(*imported_sets, &block)
@name = name
@commands = {} @commands = {}
@helper_module = Module.new @helper_module = Module.new
@ -65,7 +62,7 @@ class Pry
# parameters passed into the block will be strings. Successive # parameters passed into the block will be strings. Successive
# command parameters are separated by whitespace at the Pry prompt. # command parameters are separated by whitespace at the Pry prompt.
# @example # @example
# MyCommands = Pry::CommandSet.new :mine do # MyCommands = Pry::CommandSet.new do
# command "greet", "Greet somebody" do |name| # command "greet", "Greet somebody" do |name|
# puts "Good afternoon #{name.capitalize}!" # puts "Good afternoon #{name.capitalize}!"
# end # end
@ -153,7 +150,7 @@ class Pry
# @param [String] name The command name. # @param [String] name The command name.
# @param [String] description The command description. # @param [String] description The command description.
# @example # @example
# MyCommands = Pry::CommandSet.new :test do # MyCommands = Pry::CommandSet.new do
# desc "help", "help description" # desc "help", "help description"
# end # end
def desc(name, description) def desc(name, description)

View File

@ -9,7 +9,7 @@ require "pry/default_commands/easter_eggs"
class Pry class Pry
# Default commands used by Pry. # Default commands used by Pry.
Commands = Pry::CommandSet.new :default do Commands = Pry::CommandSet.new do
import DefaultCommands::Documentation import DefaultCommands::Documentation
import DefaultCommands::Gems import DefaultCommands::Gems
import DefaultCommands::Context import DefaultCommands::Context

View File

@ -3,7 +3,7 @@ require "pry/default_commands/ls"
class Pry class Pry
module DefaultCommands module DefaultCommands
Context = Pry::CommandSet.new :context do Context = Pry::CommandSet.new do
import Ls import Ls
command "cd", "Start a Pry session on VAR (use `cd ..` to go back and `cd /` to return to Pry top-level)", :keep_retval => true do |obj| command "cd", "Start a Pry session on VAR (use `cd ..` to go back and `cd /` to return to Pry top-level)", :keep_retval => true do |obj|

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
Documentation = Pry::CommandSet.new :gems do Documentation = Pry::CommandSet.new do
command "ri", "View ri documentation. e.g `ri Array#each`" do |*args| command "ri", "View ri documentation. e.g `ri Array#each`" do |*args|
run ".ri", *args run ".ri", *args

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
EasterEggs = Pry::CommandSet.new :easter_eggs do EasterEggs = Pry::CommandSet.new do
command "game", "" do |highest| command "game", "" do |highest|
highest = highest ? highest.to_i : 100 highest = highest ? highest.to_i : 100

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
Gems = Pry::CommandSet.new :gems do Gems = Pry::CommandSet.new do
command "gem-install", "Install a gem and refresh the gem cache." do |gem_name| command "gem-install", "Install a gem and refresh the gem cache." do |gem_name|
gem_home = Gem.instance_variable_get(:@gem_home) gem_home = Gem.instance_variable_get(:@gem_home)

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
Input = Pry::CommandSet.new :input do Input = Pry::CommandSet.new do
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
output.puts "Input buffer cleared!" output.puts "Input buffer cleared!"

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
Introspection = Pry::CommandSet.new :introspection do Introspection = Pry::CommandSet.new do
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args| command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args|
target = target() target = target()

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
Ls = Pry::CommandSet.new :ls do Ls = Pry::CommandSet.new do
command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args| command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args|
options = {} options = {}

View File

@ -1,7 +1,7 @@
class Pry class Pry
module DefaultCommands module DefaultCommands
Shell = Pry::CommandSet.new :shell do Shell = Pry::CommandSet.new do
# this cannot be accessed, it's just for help purposes. # this cannot be accessed, it's just for help purposes.
command ".<shell command>", "All text following a '.' is forwarded to the shell." do command ".<shell command>", "All text following a '.' is forwarded to the shell." do

View File

@ -67,7 +67,7 @@ class Pry
end end
CommandTester = Pry::CommandSet.new :test do CommandTester = Pry::CommandSet.new do
command "command1", "command 1 test" do command "command1", "command 1 test" do
output.puts "command1" output.puts "command1"
end end

View File

@ -2,11 +2,7 @@ require 'helper'
describe Pry::CommandSet do describe Pry::CommandSet do
before do before do
@set = Pry::CommandSet.new(:some_name) @set = Pry::CommandSet.new
end
it 'should use the name specified at creation' do
@set.name.should == :some_name
end end
it 'should call the block used for the command when it is called' do it 'should call the block used for the command when it is called' do
@ -54,7 +50,7 @@ describe Pry::CommandSet do
it 'should be able to import some commands from other sets' do it 'should be able to import some commands from other sets' do
run = false run = false
other_set = Pry::CommandSet.new :foo do other_set = Pry::CommandSet.new do
command('foo') { run = true } command('foo') { run = true }
command('bar') {} command('bar') {}
end end
@ -72,7 +68,7 @@ describe Pry::CommandSet do
it 'should be able to import a whole set' do it 'should be able to import a whole set' do
run = [] run = []
other_set = Pry::CommandSet.new :foo do other_set = Pry::CommandSet.new do
command('foo') { run << true } command('foo') { run << true }
command('bar') { run << true } command('bar') { run << true }
end end
@ -88,7 +84,7 @@ describe Pry::CommandSet do
run = false run = false
@set.command('foo') { run = true } @set.command('foo') { run = true }
Pry::CommandSet.new(:other, @set).run_command nil, 'foo' Pry::CommandSet.new(@set).run_command nil, 'foo'
run.should == true run.should == true
end end
@ -157,7 +153,7 @@ describe Pry::CommandSet do
end end
it 'should import helpers from imported sets' do it 'should import helpers from imported sets' do
imported_set = Pry::CommandSet.new :test do imported_set = Pry::CommandSet.new do
helpers do helpers do
def imported_helper_method; end def imported_helper_method; end
end end
@ -169,7 +165,7 @@ describe Pry::CommandSet do
end end
it 'should import helpers even if only some commands are imported' do it 'should import helpers even if only some commands are imported' do
imported_set = Pry::CommandSet.new :test do imported_set = Pry::CommandSet.new do
helpers do helpers do
def imported_helper_method; end def imported_helper_method; end
end end

View File

@ -425,7 +425,7 @@ describe Pry do
describe "commands" do describe "commands" do
it 'should interpolate ruby code into commands' do it 'should interpolate ruby code into commands' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "hello", "", :keep_retval => true do |arg| command "hello", "", :keep_retval => true do |arg|
arg arg
end end
@ -449,7 +449,7 @@ describe Pry do
end end
it 'should define a command that keeps its return value' do it 'should define a command that keeps its return value' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "hello", "", :keep_retval => true do command "hello", "", :keep_retval => true do
:kept_hello :kept_hello
end end
@ -461,7 +461,7 @@ describe Pry do
end end
it 'should define a command that does NOT keep its return value' do it 'should define a command that does NOT keep its return value' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "hello", "", :keep_retval => false do command "hello", "", :keep_retval => false do
:kept_hello :kept_hello
end end
@ -473,7 +473,7 @@ describe Pry do
end end
it 'should set the commands default, and the default should be overridable' do it 'should set the commands default, and the default should be overridable' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "hello" do command "hello" do
output.puts "hello world" output.puts "hello world"
end end
@ -485,7 +485,7 @@ describe Pry do
Pry.new(:input => InputTester.new("hello"), :output => str_output).rep Pry.new(:input => InputTester.new("hello"), :output => str_output).rep
str_output.string.should =~ /hello world/ str_output.string.should =~ /hello world/
other_klass = Pry::CommandSet.new :test2 do other_klass = Pry::CommandSet.new do
command "goodbye", "" do command "goodbye", "" do
output.puts "goodbye world" output.puts "goodbye world"
end end
@ -498,7 +498,7 @@ describe Pry do
end end
it 'should inherit "help" command from Pry::CommandBase' do it 'should inherit "help" command from Pry::CommandBase' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "h", "h command" do command "h", "h command" do
end end
end end
@ -510,7 +510,7 @@ describe Pry do
end end
it 'should inherit commands from Pry::Commands' do it 'should inherit commands from Pry::Commands' do
klass = Pry::CommandSet.new :test, Pry::Commands do klass = Pry::CommandSet.new Pry::Commands do
command "v" do command "v" do
end end
end end
@ -522,7 +522,7 @@ describe Pry do
end end
it 'should alias a command with another command' do it 'should alias a command with another command' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
alias_command "help2", "help" alias_command "help2", "help"
end end
@ -531,7 +531,7 @@ describe Pry do
end end
it 'should change description of a command using desc' do it 'should change description of a command using desc' do
klass = Pry::CommandSet.new :test do; end klass = Pry::CommandSet.new do; end
orig = klass.commands["help"].description orig = klass.commands["help"].description
klass.instance_eval do klass.instance_eval do
desc "help", "blah" desc "help", "blah"
@ -541,7 +541,7 @@ describe Pry do
end end
it 'should run a command from within a command' do it 'should run a command from within a command' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "v" do command "v" do
output.puts "v command" output.puts "v command"
end end
@ -557,13 +557,13 @@ describe Pry do
end end
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
command "v" do command "v" do
output.puts "#{target.eval('self')}" output.puts "#{target.eval('self')}"
end end
end end
child_klass = Pry::CommandSet.new :test2, klass do child_klass = Pry::CommandSet.new klass do
end end
str_output = StringIO.new str_output = StringIO.new
@ -574,7 +574,7 @@ describe Pry do
end end
it 'should import commands from another command object' do it 'should import commands from another command object' do
klass = Pry::CommandSet.new :test do klass = Pry::CommandSet.new do
import_from Pry::Commands, "ls", "jump-to" import_from Pry::Commands, "ls", "jump-to"
end end
@ -583,7 +583,7 @@ describe Pry do
end end
it 'should delete some inherited commands when using delete method' do it 'should delete some inherited commands when using delete method' do
klass = Pry::CommandSet.new :test, Pry::Commands do klass = Pry::CommandSet.new Pry::Commands do
command "v" do command "v" do
end end
@ -601,7 +601,7 @@ describe Pry do
end end
it 'should override some inherited commands' do it 'should override some inherited commands' do
klass = Pry::CommandSet.new :test, Pry::Commands do klass = Pry::CommandSet.new Pry::Commands do
command "jump-to" do command "jump-to" do
output.puts "jump-to the music" output.puts "jump-to the music"
end end