Make subclassed commands always carry all options
By options I mean the command options like `:listing`, `:shellwords`, etc. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
177a0b5ef8
commit
c2050dbb49
|
@ -37,7 +37,7 @@ class Pry
|
||||||
|
|
||||||
# Define or get the command's options
|
# Define or get the command's options
|
||||||
def command_options(arg=nil)
|
def command_options(arg=nil)
|
||||||
@command_options ||= {}
|
@command_options ||= Pry::DEFAULT_COMMAND_OPTIONS.call(match)
|
||||||
@command_options.merge!(arg) if arg
|
@command_options.merge!(arg) if arg
|
||||||
@command_options
|
@command_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -695,13 +695,14 @@ describe "Pry::Command" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "commands made with custom sub-classes" do
|
describe "a command made with a custom sub-class" do
|
||||||
before do
|
|
||||||
|
|
||||||
|
before do
|
||||||
class MyTestCommand < Pry::ClassCommand
|
class MyTestCommand < Pry::ClassCommand
|
||||||
match /my-*test/
|
match /my-*test/
|
||||||
description "So just how many sound technicians does it take to change a lightbulb? 1? 2? 3? 1-2-3? Testing?"
|
description 'So just how many sound technicians does it take to' \
|
||||||
options :shellwords => false, :listing => "my-test"
|
'change a lightbulb? 1? 2? 3? 1-2-3? Testing?'
|
||||||
|
options :shellwords => false, :listing => 'my-test'
|
||||||
|
|
||||||
def process
|
def process
|
||||||
output.puts command_name * 2
|
output.puts command_name * 2
|
||||||
|
@ -715,13 +716,27 @@ describe "Pry::Command" do
|
||||||
Pry.commands.delete 'my-test'
|
Pry.commands.delete 'my-test'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow creating custom sub-classes of Pry::Command" do
|
it "allows creation of custom sub-classes of Pry::Command" do
|
||||||
pry_eval("my---test").should =~ /my-testmy-test/
|
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
|
end
|
||||||
|
|
||||||
if !mri18_and_no_real_source_location?
|
if !mri18_and_no_real_source_location?
|
||||||
it "should show the source of the process method" do
|
it "shows the source of the process method" do
|
||||||
pry_eval("show-source my-test").should =~ /output.puts command_name/
|
pry_eval('show-source my-test').should =~ /output.puts command_name/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue