Don't clobber pre-existing options when adding new ones

This commit is contained in:
Conrad Irwin 2012-01-14 20:54:30 -08:00
parent 40a9cde119
commit 76924d98b3
2 changed files with 12 additions and 1 deletions

View File

@ -27,7 +27,8 @@ class Pry
# Define or get the command's options
def command_options(arg=nil)
@command_options = arg if arg
@command_options ||= {}
@command_options.merge!(arg) if arg
@command_options
end
# backward compatibility

View File

@ -223,6 +223,16 @@ describe "Pry::Command" do
mock_command(cmd, %w(--four 4 four))
end
it 'should allow overriding options after definition' do
cmd = @set.command_class /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
command_options :listing => 'number-one'
end
cmd.command_options[:shellwords].should == false
cmd.command_options[:listing].should == 'number-one'
end
end
describe 'tokenize' do