Permalink
Browse files

Rename describe => desc and register => command, and make describe/fl…

…ags not take the command name
  • Loading branch information...
1 parent cf10b2f commit 35ef62851d38f4071568cde8d8c178e2ca8428c1 @kballard kballard committed May 25, 2008
Showing with 30 additions and 25 deletions.
  1. +19 −19 commands/commands.rb
  2. +11 −6 lib/github.rb
View
38 commands/commands.rb
@@ -1,12 +1,12 @@
-describe :home => "Open this repo's master branch in a web browser."
-register :home do |user|
+desc "Open this repo's master branch in a web browser."
+command :home do |user|
if helper.project
helper.open helper.homepage_for(user || helper.owner, 'master')
end
end
-describe :browse => "Open this repo in a web browser."
-register :browse do |user, branch|
+desc "Open this repo in a web browser."
+command :browse do |user, branch|
if helper.project
# if one arg given, treat it as a branch name
# unless it maches user/branch, then split it
@@ -20,16 +20,16 @@
end
end
-describe :network => "Open the network page for this repo in a web browser"
-register :network do |user|
+desc "Open the network page for this repo in a web browser"
+command :network do |user|
if helper.project
user ||= helper.owner
helper.open helper.network_page_for(user)
end
end
-describe :info => "Info about this project."
-register :info do
+desc "Info about this project."
+command :info do
puts "== Info for #{helper.project}"
puts "You are #{helper.owner}"
puts "Currently tracking:"
@@ -38,9 +38,9 @@
end
end
-describe :track => "Track another user's repository."
-flags :track, :private => "Use git@github.com: instead of git://github.com/"
-register :track do |user|
+desc "Track another user's repository."
+flags :private => "Use git@github.com: instead of git://github.com/"
+command :track do |user|
die "Specify a user to track" if user.nil?
die "Already tracking #{user}" if helper.tracking?(user)
@@ -51,9 +51,9 @@
end
end
-describe :pull => "Pull from a remote."
-flags :pull, :merge => "Automatically merge remote's changes into your master."
-register :pull do |user, branch|
+desc "Pull from a remote."
+flags :merge => "Automatically merge remote's changes into your master."
+command :pull do |user, branch|
die "Specify a user to pull from" if user.nil?
user, branch = user.split("/", 2) if branch.nil?
branch ||= 'master'
@@ -68,9 +68,9 @@
end
end
-describe :clone => "Clone a repo."
-flags :clone, :ssh => "Clone using the git@github.com style url"
-register :clone do |user, repo, dir|
+desc "Clone a repo."
+flags :ssh => "Clone using the git@github.com style url"
+command :clone do |user, repo, dir|
die "Specify a user to pull from" if user.nil?
user, repo = user.split('/') unless repo
die "Specify a repo to pull from" if repo.nil?
@@ -82,8 +82,8 @@
end
end
-describe :'pull-request' => "Generate the text for a pull request"
-register :'pull-request' do |user, branch|
+desc "Generate the text for a pull request"
+command :'pull-request' do |user, branch|
if helper.project
die "Specify a user for the pull request" if user.nil?
user, branch = user.split('/', 2) if branch.nil?
View
17 lib/github.rb
@@ -23,17 +23,22 @@ module GitHub
BasePath = File.expand_path(File.dirname(__FILE__) + '/..')
- def register(command, &block)
+ def command(command, &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)
end
- def describe(hash)
- descriptions.update hash
+ def desc(str)
+ @next_description = str
end
- def flags(command, hash)
- flag_descriptions[command].update hash
+ def flags(hash)
+ @next_flags ||= {}
+ @next_flags.update hash
end
def helper(command, &block)
@@ -105,7 +110,7 @@ def debug?
end
end
-GitHub.register :default do
+GitHub.command :default do
puts "Usage: github command <space separated arguments>", ''
puts "Available commands:", ''
longest = GitHub.descriptions.map { |d,| d.to_s.size }.max

0 comments on commit 35ef628

Please sign in to comment.