grem 0.0.1 → 0.0.2
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/Rakefile +1 -1
- data/lib/grem.rb +2 -2
- data/lib/grem/cli.rb +52 -11
- metadata +11 -1
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ $hoe = Hoe.spec 'grem' do
|
|
14
14
|
self.developer 'Ben Atkin', 'ben@benatkin.com'
|
15
15
|
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
16
|
self.rubyforge_name = self.name # TODO this is default value
|
17
|
-
|
17
|
+
self.extra_deps = [['launchy','>= 0.3.5']]
|
18
18
|
end
|
19
19
|
|
20
20
|
require 'newgem/tasks'
|
data/lib/grem.rb
CHANGED
data/lib/grem/cli.rb
CHANGED
@@ -1,18 +1,29 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'launchy'
|
3
|
+
require 'pathname'
|
2
4
|
|
3
5
|
module Grem
|
4
6
|
class CLI
|
5
7
|
def self.execute(stdout, arguments=[])
|
6
|
-
|
7
|
-
options = {
|
8
|
-
}
|
9
|
-
mandatory_options = %w()
|
10
|
-
|
11
8
|
parser = OptionParser.new do |opts|
|
12
9
|
opts.banner = <<-BANNER.gsub(/^ /,'')
|
13
10
|
The (GitHub) REpo Manager (grem) clones a github repo into ~/github/username/reponame.
|
14
11
|
|
15
|
-
|
12
|
+
Cloning:
|
13
|
+
|
14
|
+
#{File.basename($0)} github_username repo_name
|
15
|
+
|
16
|
+
Clones a repo to ~/github/\#{github_username}/\#{repo_name}
|
17
|
+
|
18
|
+
Browsing:
|
19
|
+
|
20
|
+
#{File.basename($0)}
|
21
|
+
|
22
|
+
Browses to a page on GitHub based on the current directory.
|
23
|
+
~/github goes to http://github.com/
|
24
|
+
~/github/benatkin goes to http://github.com/benatkin
|
25
|
+
~/github/benatkin/grem and deeper goes to http://github.com/benatkin/grem
|
26
|
+
outside ~/github prints a friendly error message
|
16
27
|
|
17
28
|
Options are:
|
18
29
|
BANNER
|
@@ -21,15 +32,17 @@ module Grem
|
|
21
32
|
"Show this help message.") { stdout.puts opts; exit }
|
22
33
|
opts.parse!(arguments)
|
23
34
|
|
24
|
-
if
|
25
|
-
stdout
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
if arguments.length == 2
|
36
|
+
self.clone(stdout, arguments)
|
37
|
+
elsif arguments.length == 0
|
38
|
+
self.browse(stdout, arguments)
|
39
|
+
else
|
29
40
|
stdout.puts opts; exit
|
30
41
|
end
|
31
42
|
end
|
43
|
+
end
|
32
44
|
|
45
|
+
def self.clone(stdout, arguments=[])
|
33
46
|
username = arguments[0]
|
34
47
|
reponame = arguments[1]
|
35
48
|
|
@@ -47,5 +60,33 @@ module Grem
|
|
47
60
|
system('git', 'clone', remote_path)
|
48
61
|
end
|
49
62
|
end
|
63
|
+
|
64
|
+
def self.browse(stdout, arguments=[])
|
65
|
+
url = 'http://github.com/'
|
66
|
+
|
67
|
+
github = Pathname.new(File.expand_path('~/github'))
|
68
|
+
here = Pathname.new(Dir.pwd)
|
69
|
+
if self.is_under(here, github) then
|
70
|
+
relative = here.relative_path_from(github).to_s
|
71
|
+
while true
|
72
|
+
break if File.split(File.split(relative)[0])[0] ==
|
73
|
+
File.split(File.split(File.split(relative)[0])[0])[0]
|
74
|
+
relative = File.split(relative)[0]
|
75
|
+
end
|
76
|
+
url += relative if relative != '.'
|
77
|
+
else
|
78
|
+
stdout.puts 'It appears that you are not in ~/github. For usage info, run "grem --help".'
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
Launchy.open(url)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.is_under(here, github)
|
85
|
+
while here.parent != here
|
86
|
+
return true if here == github
|
87
|
+
here = here.parent
|
88
|
+
end
|
89
|
+
return false
|
90
|
+
end
|
50
91
|
end
|
51
92
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Atkin
|
@@ -12,6 +12,16 @@ cert_chain: []
|
|
12
12
|
date: 2010-04-08 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: launchy
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.3.5
|
24
|
+
version:
|
15
25
|
- !ruby/object:Gem::Dependency
|
16
26
|
name: rubyforge
|
17
27
|
type: :development
|