-
Notifications
You must be signed in to change notification settings - Fork 0
/
githubrepl
executable file
·84 lines (73 loc) · 1.75 KB
/
githubrepl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
# -*- ruby -*-
#
# Repl for exploring git. More here:
#
# http://www.jeffpalm.com/blog/archives/002194.html
#
require 'rubygems'
require 'hubruby'
require 'lib/treerepl'
include TreeRepl
# ----------------------------------------------------------------------
# Commands
#-----------------------------------------------------------------------
class Clone < Cmd
def initialize(repl)
super(repl,'clone')
end
def help
'Clone the current repository'
end
def exec(args)
args = ['.'] if args.empty?
args.each do |arg|
rel = repl.eval_path repl.cur,arg
if rel.kind_of? RepositoryNode
rep = rel.obj
url = "https://github.com/#{rep.owner}/#{rep.name}"
system 'git','clone',url
else
STDERR.puts 'Invalid repository: ' + arg
end
end
end
end
# ----------------------------------------------------------------------
# Adapter classes
# ----------------------------------------------------------------------
class UserNode < NamedNode
def initialize(o)
super(o,o.login)
end
def symbols
[:followers,
:following,
:repositories,
:watched]
end
end
class RepositoryNode < NamedNode
def initialize(o)
super(o,o.name)
end
def symbols
[:watchers,
:branches]
end
end
CmdNode.classes2tree_nodes = {
GitHub::User => UserNode,
GitHub::Repository => RepositoryNode,
}
# ----------------------------------------------------------------------
# Main entry
# ----------------------------------------------------------------------
def main(argv)
node = argv.empty? ? nil : UserNode.new(GitHub.user(argv[0]))
repl = Repl.new UserNode
repl.finder = lambda {|name| GitHub.user name}
repl.add_command Clone
repl.main node
end
main ARGV