mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
aliases inherit options from original, fixes #525
* there was an issue where Pry.config.command_prefix needed to be accessed by CommandSet#find_command before the config options had loaded -- we just avoid this issue by passing in "" if the config option is not yet defined ;) This is unlikely to cause any issues, but is a naughty hack all the same. * added tests to ensure options are inherited
This commit is contained in:
parent
03cdaf0c7e
commit
f7e0bfadde
4 changed files with 23 additions and 6 deletions
|
@ -127,7 +127,8 @@ class Pry
|
|||
end
|
||||
|
||||
def command_regex
|
||||
prefix = convert_to_regex(Pry.config.command_prefix)
|
||||
pr = defined?(Pry.config.command_prefix) ? Pry.config.command_prefix : ""
|
||||
prefix = convert_to_regex(pr)
|
||||
prefix = "(?:#{prefix})?" unless options[:use_prefix]
|
||||
|
||||
/^#{prefix}#{convert_to_regex(match)}(?!\S)/
|
||||
|
|
|
@ -221,9 +221,12 @@ class Pry
|
|||
# @example Pass explicit description (overriding default).
|
||||
# Pry.config.commands.alias_command "lM", "ls -M", :desc => "cutiepie"
|
||||
def alias_command(match, action, options={})
|
||||
options = {
|
||||
:desc => "Alias for `#{action}`",
|
||||
}.merge!(options)
|
||||
original_options = find_command(action).options.dup
|
||||
|
||||
options = original_options.merge!({
|
||||
:desc => "Alias for `#{action}`",
|
||||
:listing => match
|
||||
}).merge!(options)
|
||||
|
||||
# ensure default description is used if desc is nil
|
||||
desc = options.delete(:desc).to_s
|
||||
|
|
|
@ -239,8 +239,8 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
alias_command "show-method", "show-source", :shellwords => false
|
||||
alias_command "$", "show-source", :shellwords => false
|
||||
alias_command "show-method", "show-source"
|
||||
alias_command "$", "show-source"
|
||||
|
||||
command "show-command", "Show the source for CMD." do |*args|
|
||||
target = target()
|
||||
|
|
|
@ -156,6 +156,19 @@ describe Pry::CommandSet do
|
|||
run.should == true
|
||||
end
|
||||
|
||||
it 'should inherit options from original command' do
|
||||
run = false
|
||||
@set.command('foo', 'stuff', :shellwords => true, :interpolate => false) { run = true }
|
||||
|
||||
@set.alias_command 'bar', 'foo'
|
||||
@set.commands['bar'].options[:shellwords].should == @set.commands['foo'].options[:shellwords]
|
||||
@set.commands['bar'].options[:interpolate].should == @set.commands['foo'].options[:interpolate]
|
||||
|
||||
# however some options should not be inherited
|
||||
@set.commands['bar'].options[:listing].should.not == @set.commands['foo'].options[:listing]
|
||||
@set.commands['bar'].options[:listing].should == "bar"
|
||||
end
|
||||
|
||||
it 'should be able to specify alias\'s description when aliasing' do
|
||||
run = false
|
||||
@set.command('foo', 'stuff') { run = true }
|
||||
|
|
Loading…
Reference in a new issue