提交 875d4288 编写于 作者: M Mislav Marohnić

[help] Enable `hub help --web <command>`

- `share/man/man1/*.html` now live in `share/doc/hub-doc/*.html`
- `help.format` git config values "web" & "html" now supported
上级 8b5f6fe6
......@@ -3,6 +3,7 @@
/bin
.bundle
bundle/
share/doc/*
share/man/*
!share/man/man1/hub.1.md
tmp/
......
......@@ -82,6 +82,8 @@ share/man/.man-pages.stamp: $(HELP_ALL:=.md) ./man-template.html bin/md2roff
--date="$(BUILD_DATE)" --version="$(HUB_VERSION)" \
--template=./man-template.html \
share/man/man1/*.md
mkdir -p share/doc/hub-doc
mv share/man/*/*.html share/doc/hub-doc/
touch $@
%.1.md: bin/hub
......
......@@ -8,6 +8,7 @@ import (
"sort"
"strings"
"github.com/github/hub/git"
"github.com/github/hub/ui"
"github.com/github/hub/utils"
"github.com/kballard/go-shellquote"
......@@ -59,6 +60,8 @@ func runHelp(helpCmd *Command, args *Args) {
p := utils.NewArgsParser()
p.RegisterBool("--all", "-a")
p.RegisterBool("--plain-text")
p.RegisterBool("--man", "-m")
p.RegisterBool("--web", "-w")
p.Parse(args.Params)
if p.Bool("--all") {
......@@ -69,12 +72,27 @@ func runHelp(helpCmd *Command, args *Args) {
return
}
cmdName := args.FirstParam()
isWeb := func() bool {
if p.Bool("--web") {
return true
}
if p.Bool("--man") {
return false
}
if f, err := git.Config("help.format"); err == nil {
return f == "web" || f == "html"
}
return false
}
cmdName := ""
if words := args.Words(); len(words) > 0 {
cmdName = words[0]
}
if cmdName == "hub" {
err := displayManPage("hub", args)
err := displayManPage("hub", args, isWeb())
utils.Check(err)
args.NoForward()
return
}
......@@ -82,15 +100,14 @@ func runHelp(helpCmd *Command, args *Args) {
if foundCmd == nil {
return
}
args.NoForward()
if p.Bool("--plain-text") {
ui.Println(foundCmd.HelpText())
return
os.Exit(0)
}
manPage := fmt.Sprintf("hub-%s", foundCmd.Name())
err := displayManPage(manPage, args)
err := displayManPage(manPage, args, isWeb())
utils.Check(err)
}
......@@ -117,7 +134,19 @@ func runListCmds(cmd *Command, args *Args) {
//
// otherwise:
// less -R {PREFIX}/share/man/man1/<page>.1.txt
func displayManPage(manPage string, args *Args) error {
func displayManPage(manPage string, args *Args, isWeb bool) error {
programPath, err := utils.CommandPath(args.ProgramPath)
if err != nil {
return err
}
if isWeb {
manPage += ".1.html"
manFile := filepath.Join(programPath, "..", "..", "share", "doc", "hub-doc", manPage)
args.Replace(args.Executable, "web--browse", manFile)
return nil
}
var manArgs []string
manProgram, _ := utils.CommandPath("man")
if manProgram != "" {
......@@ -135,11 +164,6 @@ func displayManPage(manPage string, args *Args) error {
}
}
programPath, err := utils.CommandPath(args.ProgramPath)
if err != nil {
return err
}
env := os.Environ()
if strings.HasSuffix(manPage, ".txt") {
manFile := filepath.Join(programPath, "..", "..", "share", "man", "man1", manPage)
......@@ -154,7 +178,11 @@ func displayManPage(manPage string, args *Args) error {
c.Stdout = os.Stdout
c.Stderr = os.Stderr
c.Env = env
return c.Run()
if err := c.Run(); err != nil {
return err
}
os.Exit(0)
return nil
}
func lookupCmd(name string) *Command {
......
......@@ -26,3 +26,18 @@ Feature: hub help
Scenario: Shows help for a hub command
When I successfully run `hub help fork`
Then "man hub-fork" should be run
Scenario: Show help in HTML format
When I successfully run `hub help -w fork`
Then "man hub-fork" should not be run
And "git web--browse PATH/hub-fork.1.html" should be run
Scenario: Show help in HTML format by default
Given I successfully run `git config --global help.format html`
When I successfully run `hub help fork`
Then "git web--browse PATH/hub-fork.1.html" should be run
Scenario: Override HTML format back to man
Given I successfully run `git config --global help.format html`
When I successfully run `hub help -m fork`
Then "man hub-fork" should be run
......@@ -5,7 +5,15 @@
set -e
command="$1"
[ "$command" = "config" ] || echo git "$@" >> "$HOME"/.history
case "$command" in
"config" ) ;;
"web--browse" )
echo git web--browse PATH/$(basename "$2") >> "$HOME"/.history
;;
* )
echo git "$@" >> "$HOME"/.history
;;
esac
case "$command" in
"--list-cmds="* )
......
......@@ -16,7 +16,7 @@ fi
prefix="${PREFIX:-$prefix}"
prefix="${prefix:-/usr/local}"
for src in bin/hub share/man/*/*.1 share/vim/vimfiles/*/*.vim; do
for src in bin/hub share/man/*/*.1 share/doc/*/*.html share/vim/vimfiles/*/*.vim; do
dest="${DESTDIR}${prefix}/${src}"
mkdir -p "${dest%/*}"
[[ $src == share/* ]] && mode="644" || mode=755
......
......@@ -39,11 +39,10 @@ if [ "$os" = "windows" ]; then
crlf README.md "${tmpdir}/README.txt"
crlf LICENSE "${tmpdir}/LICENSE.txt"
mkdir "${tmpdir}/help"
for man in share/man/*/*.html; do crlf "$man" "${tmpdir}/help/${man##*/}"; done
for man in share/doc/*/*.html; do crlf "$man" "${tmpdir}/help/${man##*/}"; done
crlf script/install.bat "${tmpdir}/install.bat"
else
cp -R README.md LICENSE etc share "$tmpdir"
rm -rf "${tmpdir}/share/man/"*/*.html
rm -rf "${tmpdir}/share/man/"*/*.md
cp script/install.sh "${tmpdir}/install"
chmod +x "${tmpdir}/install"
......
......@@ -20,7 +20,7 @@ publish_documentation() {
pushd "$doc_dir"
git rm hub*.html >/dev/null
cp ../share/man/*/*.html .
cp ../share/doc/*/*.html .
git add hub*.html
GIT_COMMITTER_NAME='Travis CI' GIT_COMMITTER_EMAIL='travis@travis-ci.org' \
GIT_AUTHOR_NAME='Mislav Marohnić' GIT_AUTHOR_EMAIL='mislav@github.com' \
......
......@@ -44,12 +44,14 @@ check_formatting() {
}
install_test() {
touch share/man/man1/hub.1
touch share/man/man1/hub.1 share/doc/hub-doc/hub.1.html
DESTDIR="$PWD/tmp/destdir" prefix=/my/prefix bash < script/install.sh
test -x tmp/destdir/my/prefix/bin/hub
test -e tmp/destdir/my/prefix/share/man/man1/hub.1
test ! -x tmp/destdir/my/prefix/share/man/man1/hub.1
rm share/man/man1/hub.1
test -e tmp/destdir/my/prefix/share/doc/hub-doc/hub.1.html
test ! -x tmp/destdir/my/prefix/share/doc/hub-doc/hub.1.html
rm share/man/man1/hub.1 share/doc/hub-doc/hub.1.html
}
[ -z "$HUB_COVERAGE" ] || script/coverage prepare
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册