Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
c6c1f371
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,发现更多精彩内容 >>
提交
c6c1f371
编写于
12月 09, 2009
作者:
C
Chris Wanstrath
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
`hub help hub`
上级
389a0665
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
72 addition
and
3 deletion
+72
-3
lib/hub/commands.rb
lib/hub/commands.rb
+50
-3
test/hub_test.rb
test/hub_test.rb
+22
-0
未找到文件。
lib/hub/commands.rb
浏览文件 @
c6c1f371
...
...
@@ -145,9 +145,13 @@ module Hub
# $ hub help
# (print improved help text)
def
help
(
args
)
return
if
args
.
size
>
1
puts
improved_help_text
exit
if
args
[
1
]
==
'hub'
puts
hub_manpage
exit
elsif
args
.
size
==
1
puts
improved_help_text
exit
end
end
# The text print when `hub help` is run, kept in its own method
...
...
@@ -208,6 +212,49 @@ help
end
end
# Returns the terminal-formatted manpage, ready to be printed to
# the screen.
def
hub_manpage
return
"** Can't find groff(1)"
unless
groff?
require
'open3'
out
=
nil
Open3
.
popen3
(
groff_command
)
do
|
stdin
,
stdout
,
_
|
stdin
.
puts
hub_raw_manpage
stdin
.
close
out
=
stdout
.
read
.
strip
end
out
end
# Returns true if groff is installed and in our path, false if
# not.
def
groff?
system
(
"which groff"
)
end
# The groff command complete with crazy arguments we need to run
# in order to turn our raw roff (manpage markup) into something
# readable on the terminal.
def
groff_command
"groff -Wall -mtty-char -mandoc -Tascii"
end
# Returns the raw hub manpage. If we're not running in standalone
# mode, it's a file sitting at the root under the `man`
# directory.
#
# If we are running in standalone mode the manpage will be
# included after the __END__ of the file so we can grab it using
# DATA.
def
hub_raw_manpage
if
File
.
exists?
file
=
File
.
dirname
(
__FILE__
)
+
'/../../man/hub.1'
File
.
read
(
file
)
else
DATA
.
read
end
end
# All calls to `puts` in after hooks or commands are paged,
# git-style.
def
puts
(
*
args
)
...
...
test/hub_test.rb
浏览文件 @
c6c1f371
...
...
@@ -97,4 +97,26 @@ class HubTest < Test::Unit::TestCase
def
test_help_by_default
assert_equal
Hub
::
Commands
.
improved_help_text
,
hub
(
""
)
end
def
test_help_hub
help_manpage
=
hub
(
"help hub"
)
assert_includes
"git + hub = github"
,
help_manpage
assert_includes
"Writes shell aliasing code for"
,
help_manpage
assert_includes
"Chris Wanstrath :: chris@ozmm.org"
,
help_manpage
puts
help_manpage
assert_includes
<<-
config
,
help_manpage
Use git-config(1) to display the currently configured GitHub username:
$ git config --global github.user
config
end
def
test_help_hub_no_groff
help_manpage
=
hub
(
"help hub"
)
do
Hub
::
Commands
.
class_eval
do
def
groff?
;
false
end
end
end
assert_equal
"** Can't find groff(1)
\n
"
,
help_manpage
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录