зеркало из https://github.com/mislav/hub.git
add improved help
This commit is contained in:
Родитель
6506456ce6
Коммит
5667d94f51
87
bin/hub
87
bin/hub
|
@ -139,6 +139,93 @@ class Hub
|
|||
end
|
||||
end
|
||||
alias_method "--version", :version
|
||||
|
||||
# $ hub help
|
||||
# (print improved help text)
|
||||
def help(args)
|
||||
return if args.size > 1
|
||||
puts improved_help_text
|
||||
exit
|
||||
end
|
||||
|
||||
# The text print when `hub help` is run, kept in its own method
|
||||
# for the convenience of the author.
|
||||
def improved_help_text
|
||||
<<-help
|
||||
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
|
||||
[-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR]
|
||||
[--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]
|
||||
|
||||
Creating a git repository:
|
||||
clone Clone a repository into a new directory
|
||||
init Create an empty git repository or reinitialize an existing one
|
||||
|
||||
Working with content:
|
||||
add Add file contents to the index
|
||||
branch List, create, or delete branches
|
||||
checkout Checkout a branch or paths to the working tree
|
||||
commit Record changes to the repository
|
||||
diff Show changes between commits, commit and working tree, etc
|
||||
log Show commit logs
|
||||
merge Join two or more development histories together
|
||||
mv Move or rename a file, a directory, or a symlink
|
||||
rm Remove files from the working tree and from the index
|
||||
status Show the working tree status
|
||||
show Show various types of objects
|
||||
tag Create, list, delete or verify a tag object signed with GPG
|
||||
|
||||
Over the network:
|
||||
fetch Download objects and refs from another repository
|
||||
pull Fetch from and merge with another repository or a local branch
|
||||
push Update remote refs along with associated objects
|
||||
remote Manage a set of tracked repositories
|
||||
|
||||
Advanced commands:
|
||||
bisect Find by binary search the change that introduced a bug
|
||||
grep Print lines matching a pattern
|
||||
reset Reset current HEAD to the specified state
|
||||
rebase Forward-port local commits to the updated upstream head
|
||||
|
||||
See 'git help COMMAND' for more information on a specific command.
|
||||
help
|
||||
end
|
||||
|
||||
# All calls to `puts` in after hooks or commands are paged,
|
||||
# git-style.
|
||||
def puts(content)
|
||||
page_stdout
|
||||
super
|
||||
end
|
||||
|
||||
# http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
|
||||
def page_stdout
|
||||
return if PLATFORM =~ /win32/
|
||||
return unless $stdout.tty?
|
||||
|
||||
read, write = IO.pipe
|
||||
|
||||
if Kernel.fork
|
||||
# Parent process, become pager
|
||||
$stdin.reopen(read)
|
||||
read.close
|
||||
write.close
|
||||
|
||||
# Don't page if the input is short enough
|
||||
ENV['LESS'] = 'FSRX'
|
||||
|
||||
# Wait until we have input before we start the pager
|
||||
Kernel.select [STDIN]
|
||||
|
||||
pager = ENV['PAGER'] || 'less'
|
||||
exec pager rescue exec "/bin/sh", "-c", pager
|
||||
else
|
||||
# Child process
|
||||
$stdout.reopen(write)
|
||||
$stderr.reopen(write) if $stderr.tty?
|
||||
read.close
|
||||
write.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -81,4 +81,12 @@ class HubTest < Test::Unit::TestCase
|
|||
h = hub("--version")
|
||||
assert_equal "git version 1.6.4.2\nhub version 0.1.0\n", h
|
||||
end
|
||||
|
||||
def test_help
|
||||
assert_equal Hub::Commands.improved_help_text, hub("help")
|
||||
end
|
||||
|
||||
def test_help_by_default
|
||||
assert_equal Hub::Commands.improved_help_text, hub("")
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче