From c2050dbb49b69e6999ea49ac00f2c7b8bdffa565 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Tue, 25 Dec 2012 22:18:14 +0200 Subject: [PATCH] Make subclassed commands always carry all options By options I mean the command options like `:listing`, `:shellwords`, etc. Signed-off-by: Kyrylo Silin --- lib/pry/command.rb | 2 +- spec/command_spec.rb | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 530873f6..8c615d0c 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -37,7 +37,7 @@ class Pry # Define or get the command's options def command_options(arg=nil) - @command_options ||= {} + @command_options ||= Pry::DEFAULT_COMMAND_OPTIONS.call(match) @command_options.merge!(arg) if arg @command_options end diff --git a/spec/command_spec.rb b/spec/command_spec.rb index 27ef2b7e..ed95b2e8 100644 --- a/spec/command_spec.rb +++ b/spec/command_spec.rb @@ -695,13 +695,14 @@ describe "Pry::Command" do end end - describe "commands made with custom sub-classes" do - before do + describe "a command made with a custom sub-class" do + before do class MyTestCommand < Pry::ClassCommand match /my-*test/ - description "So just how many sound technicians does it take to change a lightbulb? 1? 2? 3? 1-2-3? Testing?" - options :shellwords => false, :listing => "my-test" + description 'So just how many sound technicians does it take to' \ + 'change a lightbulb? 1? 2? 3? 1-2-3? Testing?' + options :shellwords => false, :listing => 'my-test' def process output.puts command_name * 2 @@ -715,13 +716,27 @@ describe "Pry::Command" do Pry.commands.delete 'my-test' end - it "should allow creating custom sub-classes of Pry::Command" do - pry_eval("my---test").should =~ /my-testmy-test/ + it "allows creation of custom sub-classes of Pry::Command" do + pry_eval('my---test').should =~ /my-testmy-test/ + end + + it "never loses its command options" do + options_hash = { + :requires_gem => [], + :keep_retval => false, + :argument_required => false, + :interpolate => true, + :shellwords => false, + :listing => 'my-test', + :use_prefix => true, + :takes_block => false + } + MyTestCommand.options.should == options_hash end if !mri18_and_no_real_source_location? - it "should show the source of the process method" do - pry_eval("show-source my-test").should =~ /output.puts command_name/ + it "shows the source of the process method" do + pry_eval('show-source my-test').should =~ /output.puts command_name/ end end end