ghs 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/ghs +39 -46
- metadata +3 -3
data/bin/ghs
CHANGED
@@ -1,64 +1,57 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
2
3
|
require "yaml"
|
3
|
-
require
|
4
|
-
require 'optparse'
|
4
|
+
require 'trollop'
|
5
5
|
require 'open-uri'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
opts.on("-b", "--best", "If multiple repos are found, choose the best one.") do |opt|
|
11
|
-
app['best'] = opt
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
begin
|
16
|
-
options.parse!(ARGV)
|
17
|
-
rescue OptionParser::ParseError => e
|
18
|
-
STDERR.puts "#{$0}: #{e}"
|
7
|
+
def find_user
|
8
|
+
x = `git config github.user`
|
9
|
+
x.chomp
|
19
10
|
end
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
def get_repo(user, repo)
|
13
|
+
begin
|
14
|
+
YAML.load(open("http://github.com/api/v2/yaml/repos/show/#{user}/#{repo}").read)
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
24
18
|
end
|
25
19
|
|
26
|
-
repo
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if results["repositories"].length > 1 && !app['best']
|
33
|
-
STDERR.puts "#{$0}: Multiple repos found, not sure which one you wanted.\nTo let me make the choice, rerun with the --best flag."
|
34
|
-
exit
|
35
|
-
end
|
36
|
-
|
37
|
-
repo_name = results["repositories"][0]["name"] || results["repositories"][0][:name]
|
38
|
-
username = results["repositories"][0]["username"] || results["repositories"][0][:username]
|
20
|
+
def find_user_repo(repo)
|
21
|
+
user = find_user
|
22
|
+
return nil if user == ""
|
23
|
+
get_repo(user, repo)
|
24
|
+
end
|
39
25
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
26
|
+
def find_generic_repo(repo)
|
27
|
+
results = YAML.load(open("http://github.com/api/v2/yaml/repos/search/#{repo}").read)
|
28
|
+
Trollop::die "Couldn't find a url" if results["repositories"].empty?
|
29
|
+
Trollop::die "Multiple repos found, not sure which one you wanted.\nTo let me make the choice, rerun with the --best flag" unless results["repositories"].size == 1 || OPTS[:best]
|
30
|
+
user = results["repositories"][0][:username]
|
31
|
+
get_repo(user, repo)
|
32
|
+
end
|
44
33
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
34
|
+
OPTS = Trollop::options do
|
35
|
+
banner <<-EOS
|
36
|
+
Find the clone url for any repo on github, quickly.
|
37
|
+
Usage: #{$0} [repo name]
|
38
|
+
Use it to clone a repo: git clone `ghs [reponame]`
|
39
|
+
EOS
|
40
|
+
opt :best, "If multiple repos are found, choose the first one."
|
41
|
+
end
|
49
42
|
|
50
|
-
if
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
Trollop::die("no repo specified") if ARGV.empty?
|
44
|
+
result = find_user_repo(ARGV[0]) || find_generic_repo(ARGV[0])
|
45
|
+
Trollop::die "couldn't find a url." unless result
|
46
|
+
result = result["repository"]
|
54
47
|
|
55
48
|
STDERR.puts "
|
56
49
|
==
|
57
50
|
|
58
|
-
Matched repository: #{
|
59
|
-
Description: #{
|
51
|
+
Matched repository: #{result[:name]}
|
52
|
+
Description: #{result[:description]}
|
60
53
|
|
61
54
|
==
|
62
55
|
"
|
63
56
|
|
64
|
-
puts "#{url}.git"
|
57
|
+
puts "#{result[:url]}.git"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aditya Bhargava
|