Permalink
Browse files

Can now accept a url to a github project

  • Loading branch information...
1 parent 6599bac commit 73f30427706c731ccf24ffe8d6af49ab190dc30a @nkpart committed Sep 8, 2009
Showing with 32 additions and 6 deletions.
  1. +22 −4 lib/dget.rb
  2. +10 −2 spec/dget_spec.rb
View
@@ -10,14 +10,32 @@
module DGet
VERSION = '0.0.1' unless defined? VERSION
- def self.cli(stdin, stdout, args)
+ GH = GitHubEngine.new unless defined? GH
+ GC = GoogleCodeEngine.new unless defined? GC
+
+
+ def self.parse_args args
+ if (args[0] =~ /github.com\/(.*)\/(.*)[\/]{0,1}/)
+ return ["github", $1 + "/" + $2, args[1]]
+ end
+
engine, project_spec, file = *args
- if (engine && project_spec) then
+ if (engine && project_spec)
+ return [engine, project_spec, file]
+ end
+
+ return []
+ end
+
+ def self.cli(stdin, stdout, args)
+ parsed = parse_args(args)
+ if !parsed.empty?
+ engine, project_spec, file = *parsed
case engine
when "github"
- GitHubEngine.new.do(project_spec, file)
+ GH.do(project_spec, file)
when "googlecode"
- GoogleCodeEngine.new.do(project_spec, file)
+ GC.do(project_spec, file)
end
else
stdout.puts "Usage: dget [github|googlecode] [user/project|project] [file]"
View
@@ -1,7 +1,15 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Dget" do
- it "fails" do
- fail "hey buddy, you should probably rename this file and start specing for real"
+ it "should accept some args" do
+ [
+ [%w(github dpp/liftweb), ["github", "dpp/liftweb", nil]],
+ [%w(github dpp/liftweb test.html), ["github", "dpp/liftweb", 'test.html']],
+ [["http://wiki.github.com/jgarber/redcloth"], ["github", "jgarber/redcloth", nil]],
+ [["http://wiki.github.com/jgarber/redcloth", "test.html"], ["github", "jgarber/redcloth", "test.html"]]
+ ].each do |args, out|
+ DGet.parse_args(args).should == out
+ end
+
end
end

0 comments on commit 73f3042

Please sign in to comment.