1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

alias_command: fold sep. desc arg into options hash

* i.e, instead of alias_command "ls", "ls -M", "my description", :options => blah
  use alias_command "ls", "ls -M", :desc => "my description", :options => blah
This commit is contained in:
John Mair 2012-03-26 04:01:07 +13:00
parent 527e9d1c19
commit 9e9f6a51c3
2 changed files with 9 additions and 7 deletions

View file

@ -205,19 +205,21 @@ class Pry
# @param [String, Regex] name The name of the alias (can be a regex).
# @param [String] action The action to be performed (typically
# another command).
# @param [String, nil] desc New description of the command.
# @param [Hash] options The optional configuration parameters,
# accepts the same as the `command` method, but also allows the
# command description to be passed this way too.
# command description to be passed this way too as `:desc`
# @example Creating an alias for `ls -M`
# Pry.config.commands.alias_command "lM", "ls -M"
def alias_command(name, action, desc="Alias for `#{action}`", options={})
# @example Pass explicit description (overriding default).
# Pry.config.commands.alias_command "lM", "ls -M", :desc => "cutiepie"
def alias_command(name, action, options={})
options = {
:desc => "Alias for `#{action}`",
:alias => true
}.merge!(options)
# ensure default description is used if desc is nil
desc = "Alias for `#{action}`" if !desc
desc = options.delete(:desc).to_s
create_command name, desc, options do
define_method(:process) do

View file

@ -138,7 +138,7 @@ describe Pry::CommandSet do
run = false
@set.command('foo', 'stuff') { run = true }
@set.alias_command 'bar', 'foo', "tobina"
@set.alias_command 'bar', 'foo', :desc => "tobina"
@set.commands['bar'].name.should == 'bar'
@set.commands['bar'].description.should == "tobina"
@ -162,7 +162,7 @@ describe Pry::CommandSet do
run = false
@set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
@set.alias_command /^b.r/, 'foo1', nil, :listing => "bar"
@set.alias_command /^b.r/, 'foo1', :listing => "bar"
@set.commands[/^b.r/].options[:listing].should == "bar"
end
@ -170,7 +170,7 @@ describe Pry::CommandSet do
run = false
@set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
@set.alias_command "bar", 'foo1', nil
@set.alias_command "bar", 'foo1'
@set.commands["bar"].description.should == "Alias for `foo1`"
end
end