Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'eolamey/master'

  • Loading branch information...
commit 8f2b6f100f38dc8cb99c2a128cde7999b8247516 2 parents d8d2235 + a1f1087
@defunkt defunkt authored
Showing with 28 additions and 8 deletions.
  1. +8 −8 lib/github.rb
  2. +20 −0 spec/github_spec.rb
View
16 lib/github.rb
@@ -25,13 +25,19 @@ module GitHub
BasePath = File.expand_path(File.dirname(__FILE__) + '/..')
- def command(command, &block)
+ def command(command, options = {}, &block)
debug "Registered `#{command}`"
descriptions[command] = @next_description if @next_description
@next_description = nil
flag_descriptions[command].update @next_flags if @next_flags
@next_flags = nil
commands[command.to_s] = Command.new(block)
+ aliases = options[:alias] || options[:aliases]
+ aliases = [aliases] unless (aliases.nil? || aliases.respond_to?(:each))
+ aliases.each do |command_alias|
+ commands[command_alias.to_s] = commands[command.to_s]
+ end if options[:aliases]
+ command
end
def desc(str)
@@ -123,7 +129,7 @@ def debug?
end
end
-GitHub.command :default do
+GitHub.command :default, :aliases => ['', '-h', 'help', '-help', '--help'] do
puts "Usage: github command <space separated arguments>", ''
puts "Available commands:", ''
longest = GitHub.descriptions.map { |d,| d.to_s.size }.max
@@ -138,9 +144,3 @@ def debug?
end
puts
end
-
-GitHub.commands[''] = GitHub.commands['default']
-GitHub.commands['-h'] = GitHub.commands['default']
-GitHub.commands['--help'] = GitHub.commands['default']
-GitHub.commands['-help'] = GitHub.commands['default']
-GitHub.commands['help'] = GitHub.commands['default']
View
20 spec/github_spec.rb
@@ -62,4 +62,24 @@
GitHub.activate(['default', '--debug'])
GitHub.should be_debug
end
+
+ it "should allow for an alias on a commad" do
+ GitHub.command 'some-command', :aliases => 'an-alias' do
+ end
+ GitHub.commands['an-alias'].should_not be_nil
+ GitHub.commands['an-alias'].should_not == GitHub.commands['non-existant-command']
+ GitHub.commands['an-alias'].should == GitHub.commands['some-command']
+ end
+
+ it "should allow for an array of aliases on a commad" do
+ GitHub.command 'another-command', :aliases => ['some-alias-1', 'some-alias-2'] do
+ end
+ GitHub.commands['some-alias-1'].should_not be_nil
+ GitHub.commands['some-alias-1'].should_not == GitHub.commands['non-existant-command']
+ GitHub.commands['some-alias-1'].should_not be_nil
+ GitHub.commands['some-alias-1'].should_not == GitHub.commands['non-existant-command']
+ GitHub.commands['some-alias-1'].should == GitHub.commands['another-command']
+ GitHub.commands['some-alias-2'].should == GitHub.commands['another-command']
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.