Assign default value to `:listing` option
When you create a class command, there is a problem with `:listing` option, which doesn't carry the correct default value. Consider the example: class MakeMeHappy < Pry::ClassCommand match 'woot' end `MakeMeHappy` command matches against 'woot' String, but its `:listing` option is set to the "nil" String, which is incorrect. We can fix it by setting `:listing` explicitly: command_options :listing => 'woot' It's a repetitive task, so we can automate it. Holy smoke, this why we all use computers, after all! With help of this commit there is no need to set `:listing` manually. Pry will handle it for you. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
1dda70c695
commit
ad5bb4c399
|
@ -25,7 +25,11 @@ class Pry
|
|||
attr_writer :match
|
||||
|
||||
def match(arg=nil)
|
||||
@match = arg if arg
|
||||
if arg
|
||||
@command_options ||= default_options(arg)
|
||||
@command_options[:listing] = arg.is_a?(String) ? arg : arg.inspect
|
||||
@match = arg
|
||||
end
|
||||
@match
|
||||
end
|
||||
|
||||
|
|
|
@ -733,11 +733,18 @@ describe "Pry::Command" do
|
|||
Pry.commands.delete 'my-test'
|
||||
end
|
||||
|
||||
it "allows creation of custom sub-classes of Pry::Command" do
|
||||
it "allows creation of custom subclasses of Pry::Command" do
|
||||
pry_eval('my---test').should =~ /my-testmy-test/
|
||||
end
|
||||
|
||||
it "never loses its command options" do
|
||||
if !mri18_and_no_real_source_location?
|
||||
it "shows the source of the process method" do
|
||||
pry_eval('show-source my-test').should =~ /output.puts command_name/
|
||||
end
|
||||
end
|
||||
|
||||
describe "command options hash" do
|
||||
it "is always present" do
|
||||
options_hash = {
|
||||
:requires_gem => [],
|
||||
:keep_retval => false,
|
||||
|
@ -751,13 +758,48 @@ describe "Pry::Command" do
|
|||
MyTestCommand.options.should == options_hash
|
||||
end
|
||||
|
||||
if !mri18_and_no_real_source_location?
|
||||
it "shows the source of the process method" do
|
||||
pry_eval('show-source my-test').should =~ /output.puts command_name/
|
||||
describe ":listing option" do
|
||||
it "defaults to :match if not set explicitly" do
|
||||
class HappyNewYear < Pry::ClassCommand
|
||||
match 'happy-new-year'
|
||||
description 'Happy New Year 2013'
|
||||
end
|
||||
Pry.commands.add_command HappyNewYear
|
||||
|
||||
HappyNewYear.options[:listing].should == 'happy-new-year'
|
||||
|
||||
Pry.commands.delete 'happy-new-year'
|
||||
end
|
||||
|
||||
it "can be set explicitly" do
|
||||
class MerryChristmas < Pry::ClassCommand
|
||||
match 'merry-christmas'
|
||||
description 'Merry Christmas!'
|
||||
command_options :listing => 'happy-holidays'
|
||||
end
|
||||
Pry.commands.add_command MerryChristmas
|
||||
|
||||
MerryChristmas.options[:listing].should == 'happy-holidays'
|
||||
|
||||
Pry.commands.delete 'merry-christmas'
|
||||
end
|
||||
|
||||
it "equals to :match option's inspect, if :match is Regexp" do
|
||||
class CoolWinter < Pry::ClassCommand
|
||||
match /.*winter/
|
||||
description 'Is winter cool or cool?'
|
||||
end
|
||||
Pry.commands.add_command CoolWinter
|
||||
|
||||
CoolWinter.options[:listing].should == '/.*winter/'
|
||||
|
||||
Pry.commands.delete /.*winter/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "commands can save state" do
|
||||
before do
|
||||
@set = Pry::CommandSet.new do
|
||||
|
|
Loading…
Reference in New Issue