Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
6bd83601
H
hub
项目概览
github
/
hub
12 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6bd83601
编写于
12月 07, 2009
作者:
C
Chris Wanstrath
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Args and Commands module, refactorings
上级
c70c3f92
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
70 addition
and
41 deletion
+70
-41
bin/hub
bin/hub
+70
-41
未找到文件。
bin/hub
浏览文件 @
6bd83601
...
...
@@ -3,77 +3,106 @@
# hub(1)
class
Hub
PRIVATE
=
'git@github.com:%s/%s.git'
PUBLIC
=
'git://github.com/%s/%s.git'
USER
=
`git config --global github.user`
.
chomp
REPO
=
`basename $(pwd)`
.
chomp
VERSION
=
'0.1.0'
end
attr_reader
:args
def
initialize
(
*
args
)
@args
=
args
if
@args
.
empty?
@args
[
0
]
=
'help'
elsif
respond_to?
(
@args
[
0
]
)
send
(
@args
[
0
])
class
Hub
class
Args
<
Array
def
after
(
command
=
nil
,
&
block
)
@after
||=
block
?
block
:
command
end
def
after?
!!
@after
end
end
end
def
clone
ssh
=
@args
.
delete
(
'-p'
)
@args
.
each_with_index
do
|
arg
,
i
|
class
Hub
module
Commands
instance_methods
.
each
{
|
m
|
undef_method
(
m
)
unless
m
=~
/(^__|send|to\?$)/
}
extend
self
PRIVATE
=
'git@github.com:%s/%s.git'
PUBLIC
=
'git://github.com/%s/%s.git'
USER
=
`git config --global github.user`
.
chomp
REPO
=
`basename $(pwd)`
.
chomp
def
clone
(
args
)
ssh
=
args
.
delete
(
'-p'
)
args
.
each_with_index
do
|
arg
,
i
|
if
arg
.
scan
(
'/'
).
size
==
1
&&
!
arg
.
include?
(
':'
)
url
=
ssh
?
PRIVATE
:
PUBLIC
@
args
[
i
]
=
url
%
arg
.
split
(
'/'
)
args
[
i
]
=
url
%
arg
.
split
(
'/'
)
end
end
args
end
def
remote
if
@
args
[
1
]
==
'add'
if
@
args
.
delete
(
'-g'
)
ssh
=
@
args
.
delete
(
'-p'
)
user
=
@
args
.
last
def
remote
(
args
)
if
args
[
1
]
==
'add'
if
args
.
delete
(
'-g'
)
ssh
=
args
.
delete
(
'-p'
)
user
=
args
.
last
url
=
ssh
?
PRIVATE
:
PUBLIC
@
args
<<
url
%
[
user
,
REPO
]
args
<<
url
%
[
user
,
REPO
]
end
end
args
end
def
init
if
@
args
.
delete
(
'-g'
)
def
init
(
args
)
if
args
.
delete
(
'-g'
)
url
=
PRIVATE
%
[
USER
,
REPO
]
after
"git remote add origin
#{
url
}
"
args
.
after
"git remote add origin
#{
url
}
"
end
args
end
def
version
after
do
def
version
(
args
)
args
.
after
do
puts
"hub version %s"
%
VERSION
end
end
alias_method
"--version"
,
:version
end
end
class
Hub
attr_reader
:args
def
initialize
(
*
args
)
@args
=
Args
.
new
(
args
)
if
@args
.
empty?
@args
[
0
]
=
'help'
elsif
Commands
.
respond_to?
(
@args
[
0
])
Commands
.
send
(
@args
[
0
],
@args
)
end
end
def
command
"git
#{
@
args
.
join
(
' '
)
}
"
"git
#{
args
.
join
(
' '
)
}
"
end
def
after
(
command
=
nil
,
&
block
)
@after
||=
block
?
block
:
command
def
after
args
.
after
.
to_s
end
def
execute
if
@after
if
args
.
after?
execute_with_after_callback
else
exec
"git"
,
*
@
args
exec
"git"
,
*
args
end
end
def
execute_with_after_callback
if
system
(
"git"
,
*
@args
)
@after
.
respond_to?
(
:call
)
?
@after
.
call
:
exec
(
@after
)
after
=
args
.
after
if
system
(
"git"
,
*
args
)
after
.
respond_to?
(
:call
)
?
after
.
call
:
exec
(
after
)
exit
else
exit
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录