Made command sets respect :keep_retval

This commit is contained in:
Mon ouïe 2011-04-25 18:09:04 +02:00
parent 0ecfe74ee4
commit 7de77868b4
2 changed files with 13 additions and 6 deletions

View File

@ -10,7 +10,8 @@ class Pry
class CommandSet
class Command < Struct.new(:name, :description, :options, :block)
def call(context, *args)
context.instance_exec(*args, &block)
ret = context.instance_exec(*args, &block)
ret if options[:keep_retval]
end
end
@ -89,7 +90,7 @@ class Pry
def alias_command(new_name, old_name, desc = nil)
commands[new_name] = commands[old_name].dup
commands[new_name].name = new_name
commands[new_name].description = desc
commands[new_name].description = desc if desc
end
# Runs a command.

View File

@ -801,10 +801,6 @@ describe Pry::CommandSet do
@set.name.should == :some_name
end
it 'should have no commands' do
@set.commands.should.be.empty
end
it 'should call the block used for the command when it is called' do
run = false
@set.command 'foo' do
@ -911,4 +907,14 @@ describe Pry::CommandSet do
@set.commands['foo'].description.should == 'baz'
end
it 'should return nil for commands by default' do
@set.command('foo') { 3 }
@set.run_command(nil, 'foo').should == nil
end
it 'should be able to keep return values' do
@set.command('foo', '', :keep_retval => true) { 3 }
@set.run_command(nil, 'foo').should == 3
end
end