From 9e9f6a51c3f57d8c91fda279b600bddbe84380c6 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 26 Mar 2012 04:01:07 +1300 Subject: [PATCH] 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 --- lib/pry/command_set.rb | 10 ++++++---- test/test_command_set.rb | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 412eb866..4b9738cd 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -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 diff --git a/test/test_command_set.rb b/test/test_command_set.rb index 9909b2d1..22979720 100644 --- a/test/test_command_set.rb +++ b/test/test_command_set.rb @@ -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