Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
9afdd8d0
H
hub
项目概览
github
/
hub
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
9afdd8d0
编写于
3月 20, 2012
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
teach custom commands to respect `-h` & `--help` flags
Fixes #151
上级
a4b7a20b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
3 deletion
+49
-3
lib/hub/commands.rb
lib/hub/commands.rb
+33
-3
test/hub_test.rb
test/hub_test.rb
+16
-0
未找到文件。
lib/hub/commands.rb
浏览文件 @
9afdd8d0
...
...
@@ -38,6 +38,8 @@ module Hub
OWNER_RE
=
/[a-zA-Z0-9-]+/
NAME_WITH_OWNER_RE
=
/^(?:
#{
NAME_RE
}
|
#{
OWNER_RE
}
\/
#{
NAME_RE
}
)$/
CUSTOM_COMMANDS
=
%w[alias create browse compare fork pull-request]
def
run
(
args
)
slurp_global_flags
(
args
)
...
...
@@ -45,13 +47,17 @@ module Hub
args
.
unshift
'help'
if
args
.
empty?
cmd
=
args
[
0
]
expanded_args
=
expand_alias
(
cmd
)
cmd
=
expanded_args
[
0
]
if
expanded_args
if
expanded_args
=
expand_alias
(
cmd
)
cmd
=
expanded_args
[
0
]
expanded_args
.
concat
args
[
1
..-
1
]
end
respect_help_flags
(
expanded_args
||
args
)
if
custom_command?
cmd
# git commands can have dashes
cmd
=
cmd
.
sub
(
/(\w)-/
,
'\1_'
)
if
method_defined?
(
cmd
)
and
cmd
!=
'run'
args
[
0
,
1
]
=
expanded_args
if
expanded_args
args
.
replace
expanded_args
if
expanded_args
send
(
cmd
,
args
)
end
rescue
Errno
::
ENOENT
...
...
@@ -689,6 +695,30 @@ module Hub
# from the command line.
#
def
custom_command?
cmd
CUSTOM_COMMANDS
.
include?
cmd
end
# Show short usage help for `-h` flag, and open man page for `--help`
def
respect_help_flags
args
return
if
args
.
size
>
2
case
args
[
1
]
when
'-h'
pattern
=
/(git|hub)
#{
Regexp
.
escape
args
[
0
].
gsub
(
'-'
,
'\-'
)
}
/
hub_raw_manpage
.
each_line
{
|
line
|
if
line
=~
pattern
$stderr
.
print
"Usage: "
$stderr
.
puts
line
.
gsub
(
/\\f./
,
''
).
gsub
(
'\-'
,
'-'
)
abort
end
}
abort
"Error: couldn't find usage help for
#{
args
[
0
]
}
"
when
'--help'
puts
hub_manpage
exit
end
end
# The text print when `hub help` is run, kept in its own method
# for the convenience of the author.
def
improved_help_text
...
...
test/hub_test.rb
浏览文件 @
9afdd8d0
...
...
@@ -1053,6 +1053,22 @@ Use git-config(1) to display the currently configured GitHub username:
config
end
def
test_help_flag_on_command
help_manpage
=
hub
(
"browse --help"
)
assert_includes
"git + hub = github"
,
help_manpage
assert_includes
"git browse"
,
help_manpage
end
def
test_help_short_flag_on_command
usage_help
=
hub
(
"create -h"
)
expected
=
"Usage: git create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE]
\n
"
assert_equal
expected
,
usage_help
usage_help
=
hub
(
"pull-request -h"
)
expected
=
"Usage: git pull-request [-f] [TITLE|-i ISSUE] [-b BASE] [-h HEAD]
\n
"
assert_equal
expected
,
usage_help
end
def
test_help_hub_no_groff
stub_available_commands
()
assert_equal
"** Can't find groff(1)
\n
"
,
hub
(
"help hub"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录