[TAKE 2][PATCH 0/5]: Show commands aliases and global options
in help
Thomas Arendsen Hein
thomas at intevation.de
Sat Aug 6 09:47:06 CDT 2005
* Goffredo Baroncelli <kreijack at aliceposta.it> [20050725 21:02]:
> the five patches which follow this email permit to hg to show the
> commands aliases and the global options when the 'hg help' command
> are used with the '-v' switch. Moreover the short list is showed
> only when hg is executed without parameters.
All patches applied to my tree, additional two patches are attached.
Pullable from http://hg.intevation.org/mercurial-tah/ as usual.
Thomas
--
Email: thomas at intevation.de
http://intevation.de/~thomas/
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID 221628fe9b62873d74b002e40ab715632bf9503d
# Parent f1555f48f884ad6a558f9db0561dd0769ef4920a
Always show short help when an unknown command is given.
diff -r f1555f48f884ad6a558f9db0561dd0769ef4920a -r 221628fe9b62873d74b002e40ab715632bf9503d mercurial/commands.py
--- a/mercurial/commands.py Sat Aug 6 12:33:14 2005
+++ b/mercurial/commands.py Sat Aug 6 13:04:59 2005
@@ -287,27 +287,24 @@
def help_(ui, cmd=None):
"""show help for a given command or all commands"""
if cmd and cmd != 'shortlist':
- try:
- i = find(cmd)
- ui.write("%s\n\n" % i[2])
-
- if i[1]:
- for s, l, d, c in i[1]:
- opt = ' '
- if s:
- opt = opt + '-' + s + ' '
- if l:
- opt = opt + '--' + l + ' '
- if d:
- opt = opt + '(' + str(d) + ')'
- ui.write(opt, "\n")
- if c:
- ui.write(' %s\n' % c)
- ui.write("\n")
-
- ui.write(i[0].__doc__, "\n")
- except UnknownCommand:
- ui.warn("hg: unknown command %s\n" % cmd)
+ i = find(cmd)
+ ui.write("%s\n\n" % i[2])
+
+ if i[1]:
+ for s, l, d, c in i[1]:
+ opt = ' '
+ if s:
+ opt = opt + '-' + s + ' '
+ if l:
+ opt = opt + '--' + l + ' '
+ if d:
+ opt = opt + '(' + str(d) + ')'
+ ui.write(opt, "\n")
+ if c:
+ ui.write(' %s\n' % c)
+ ui.write("\n")
+
+ ui.write(i[0].__doc__, "\n")
sys.exit(0)
else:
if ui.verbose:
@@ -1401,12 +1398,12 @@
help_(u, inst.args[0])
else:
u.warn("hg: %s\n" % inst.args[1])
- help_(u)
+ help_(u, 'shortlist')
sys.exit(-1)
except UnknownCommand, inst:
u = ui.ui()
u.warn("hg: unknown command '%s'\n" % inst.args[0])
- help_(u)
+ help_(u, 'shortlist')
sys.exit(1)
if options["time"]:
@@ -1491,5 +1488,8 @@
u.debug(inst, "\n")
u.warn("%s: invalid arguments\n" % cmd)
help_(u, cmd)
+ except UnknownCommand, inst:
+ u.warn("hg: unknown command '%s'\n" % inst.args[0])
+ help_(u, 'shortlist')
sys.exit(-1)
diff -r f1555f48f884ad6a558f9db0561dd0769ef4920a -r 221628fe9b62873d74b002e40ab715632bf9503d tests/test-help.out
--- a/tests/test-help.out Sat Aug 6 12:33:14 2005
+++ b/tests/test-help.out Sat Aug 6 13:04:59 2005
@@ -104,42 +104,40 @@
diff working directory (or selected files)
+ hg help foo
-hg: unknown command foo
+hg: unknown command 'foo'
+basic hg commands (use "hg help" for more):
+
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff working directory (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the current directory
+ log show the revision history of the repository or a single file
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert modified files or dirs back to their unmodified states
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
+ hg -q commands
hg: unknown command 'commands'
- add add the specified files on the next commit
- addremove add all new files, delete all missing files
- annotate show changeset information per file line
- cat output the latest or given revision of a file
- clone make a copy of an existing repository
- commit commit the specified files or all outstanding changes
- copy mark a file as copied or renamed for the next commit
- diff diff working directory (or selected files)
- export dump the header and diffs for one or more changesets
- forget don't add the specified files on the next commit
- heads show current repository heads
- help show help for a given command or all commands
- identify print information about the working copy
- import import an ordered set of patches
- init create a new repository in the current directory
- locate locate files matching specific patterns
- log show the revision history of the repository or a single file
- manifest output the latest or given revision of the project manifest
- parents show the parents of the working dir or revision
- paths show path or list of available paths
- pull pull changes from the specified source
- push push changes to the specified destination
- rawcommit raw commit interface
- recover roll back an interrupted transaction
- remove remove the specified files on the next commit
- revert revert modified files or dirs back to their unmodified states
- root print the root (top) of the current working dir
- serve export the repository via HTTP
- status show changed files in the working directory
- tag add a tag for the current tip or a given revision
- tags list repository tags
- tip show the tip revision
- undo undo the last commit or pull
- update update or merge working directory
- verify verify the integrity of the repository
- version output version and copyright information
+basic hg commands (use "hg help" for more):
+
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff working directory (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the current directory
+ log show the revision history of the repository or a single file
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert modified files or dirs back to their unmodified states
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID 8933ef744325d4ce9f09c100d603af5b4d165254
# Parent 221628fe9b62873d74b002e40ab715632bf9503d
Further help improvements:
Show command aliases in 'hg help something', unless in quiet mode.
Show short command description with 'hg help -q something'.
Show global options in verbose mode of command help.
State that Mercurial is a Distributed SCM.
diff -r 221628fe9b62873d74b002e40ab715632bf9503d -r 8933ef744325d4ce9f09c100d603af5b4d165254 mercurial/commands.py
--- a/mercurial/commands.py Sat Aug 6 13:04:59 2005
+++ b/mercurial/commands.py Sat Aug 6 14:43:12 2005
@@ -276,7 +276,8 @@
def show_version(ui):
"""output version and copyright information"""
- ui.write("Mercurial version %s\n" % version.get_version())
+ ui.write("Mercurial Distributed SCM (version %s)\n"
+ % version.get_version())
ui.status(
"\nCopyright (C) 2005 Matt Mackall <mpm at selenic.com>\n"
"This is free software; see the source for copying conditions. "
@@ -287,10 +288,25 @@
def help_(ui, cmd=None):
"""show help for a given command or all commands"""
if cmd and cmd != 'shortlist':
- i = find(cmd)
+ key, i = find(cmd)
+ # synopsis
ui.write("%s\n\n" % i[2])
- if i[1]:
+ # description
+ doc = i[0].__doc__
+ if ui.quiet:
+ doc = doc.splitlines(0)[0]
+ ui.write("%s\n" % doc.rstrip())
+
+ # aliases
+ if not ui.quiet:
+ aliases = ', '.join(key.split('|')[1:])
+ if aliases:
+ ui.write("\naliases: %s\n" % aliases)
+
+ # options
+ if not ui.quiet and i[1]:
+ ui.write("\noptions:\n\n")
for s, l, d, c in i[1]:
opt = ' '
if s:
@@ -302,33 +318,24 @@
ui.write(opt, "\n")
if c:
ui.write(' %s\n' % c)
- ui.write("\n")
-
- ui.write(i[0].__doc__, "\n")
- sys.exit(0)
+
else:
+ # program name
if ui.verbose:
show_version(ui)
- ui.write('\n')
- if ui.verbose:
- ui.write("global options:\n\n")
- for s, l, d, c in globalopts:
- opt = ' '
- if s:
- opt = opt + '-' + s + ' '
- if l:
- opt = opt + '--' + l + ' '
- if d:
- opt = opt + '(' + str(d) + ')'
- ui.write(opt, "\n")
- if c:
- ui.write(' %s\n' % c)
- ui.write("\n")
-
- ui.write('hg commands:\n\n')
-
+ else:
+ ui.status("Mercurial Distributed SCM\n")
+ ui.status('\n')
+
+ # list of commands
if cmd == "shortlist":
- ui.write('basic hg commands (use "hg help" for more):\n\n')
+ ui.status('basic commands (use "hg help" '
+ 'for the full list or option "-v" for details):\n\n')
+ elif ui.verbose:
+ ui.status('list of commands:\n\n')
+ else:
+ ui.status('list of commands (use "hg help -v" '
+ 'to show aliases and global options):\n\n')
h = {}
cmds = {}
@@ -336,9 +343,9 @@
f = c.split("|")[0]
if cmd == "shortlist" and not f.startswith("^"):
continue
+ f = f.lstrip("^")
if not ui.debugflag and f.startswith("debug"):
continue
- f = f.lstrip("^")
d = ""
if e[0].__doc__:
d = e[0].__doc__.splitlines(0)[0].rstrip()
@@ -354,6 +361,21 @@
ui.write(" %s:\n %s\n"%(commands,h[f]))
else:
ui.write(' %-*s %s\n' % (m, f, h[f]))
+
+ # global options
+ if ui.verbose:
+ ui.write("\nglobal options:\n\n")
+ for s, l, d, c in globalopts:
+ opt = ' '
+ if s:
+ opt = opt + '-' + s + ' '
+ if l:
+ opt = opt + '--' + l + ' '
+ if d:
+ opt = opt + '(' + str(d) + ')'
+ ui.write(opt, "\n")
+ if c:
+ ui.write(' %s\n' % c)
# Commands start here, listed alphabetically
@@ -1330,7 +1352,7 @@
def find(cmd):
for e in table.keys():
if re.match("(%s)$" % e, cmd):
- return table[e]
+ return e, table[e]
raise UnknownCommand(cmd)
@@ -1362,7 +1384,7 @@
else:
cmd, args = args[0], args[1:]
- i = find(cmd)
+ i = find(cmd)[1]
# combine global options into local
c = list(i[1])
diff -r 221628fe9b62873d74b002e40ab715632bf9503d -r 8933ef744325d4ce9f09c100d603af5b4d165254 tests/test-help
--- a/tests/test-help Sat Aug 6 13:04:59 2005
+++ b/tests/test-help Sat Aug 6 14:43:12 2005
@@ -1,11 +1,15 @@
#!/bin/sh
+hg
+hg -q
hg help
hg -q help
hg add -h
hg add --skjdfks
hg help diff
+hg help status
+hg -q help status
hg help foo
-hg -q commands
+hg skjdfks
exit 0
diff -r 221628fe9b62873d74b002e40ab715632bf9503d -r 8933ef744325d4ce9f09c100d603af5b4d165254 tests/test-help.out
--- a/tests/test-help.out Sat Aug 6 13:04:59 2005
+++ b/tests/test-help.out Sat Aug 6 14:43:12 2005
@@ -1,4 +1,44 @@
++ hg
+Mercurial Distributed SCM
+
+basic commands (use "hg help" for the full list or option "-v" for details):
+
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff working directory (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the current directory
+ log show the revision history of the repository or a single file
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert modified files or dirs back to their unmodified states
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
++ hg -q
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff working directory (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the current directory
+ log show the revision history of the repository or a single file
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert modified files or dirs back to their unmodified states
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
+ hg help
+Mercurial Distributed SCM
+
+list of commands (use "hg help -v" to show aliases and global options):
+
add add the specified files on the next commit
addremove add all new files, delete all missing files
annotate show changeset information per file line
@@ -76,68 +116,106 @@
hg add: option -h not recognized
hg add [FILE]...
- -I --include
- include path in search
- -X --exclude
- exclude path from search
-
add the specified files on the next commit
+
+options:
+
+ -I --include
+ include path in search
+ -X --exclude
+ exclude path from search
+ hg add --skjdfks
hg add: option --skjdfks not recognized
hg add [FILE]...
- -I --include
- include path in search
- -X --exclude
- exclude path from search
-
add the specified files on the next commit
+
+options:
+
+ -I --include
+ include path in search
+ -X --exclude
+ exclude path from search
+ hg help diff
hg diff [-r REV1 [-r REV2]] [FILE]...
+diff working directory (or selected files)
+
+options:
+
-r --rev
revision
-I --include
include path in search
-X --exclude
exclude path from search
-
-diff working directory (or selected files)
++ hg help status
+hg status [FILE]...
+
+show changed files in the working directory
+
+ M = modified
+ A = added
+ R = removed
+ ? = not tracked
+
+options:
+
+ -m --modified
+ show only modified files
+ -a --added
+ show only added files
+ -r --removed
+ show only removed files
+ -u --unknown
+ show only unknown (not tracked) files
+ -I --include
+ include path in search
+ -X --exclude
+ exclude path from search
++ hg -q help status
+hg status [FILE]...
+
+show changed files in the working directory
+ hg help foo
hg: unknown command 'foo'
-basic hg commands (use "hg help" for more):
-
- add add the specified files on the next commit
- annotate show changeset information per file line
- clone make a copy of an existing repository
- commit commit the specified files or all outstanding changes
- diff diff working directory (or selected files)
- export dump the header and diffs for one or more changesets
- init create a new repository in the current directory
- log show the revision history of the repository or a single file
- pull pull changes from the specified source
- push push changes to the specified destination
- remove remove the specified files on the next commit
- revert revert modified files or dirs back to their unmodified states
- serve export the repository via HTTP
- status show changed files in the working directory
- update update or merge working directory
-+ hg -q commands
-hg: unknown command 'commands'
-basic hg commands (use "hg help" for more):
-
- add add the specified files on the next commit
- annotate show changeset information per file line
- clone make a copy of an existing repository
- commit commit the specified files or all outstanding changes
- diff diff working directory (or selected files)
- export dump the header and diffs for one or more changesets
- init create a new repository in the current directory
- log show the revision history of the repository or a single file
- pull pull changes from the specified source
- push push changes to the specified destination
- remove remove the specified files on the next commit
- revert revert modified files or dirs back to their unmodified states
- serve export the repository via HTTP
- status show changed files in the working directory
- update update or merge working directory
+Mercurial Distributed SCM
+
+basic commands (use "hg help" for the full list or option "-v" for details):
+
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff working directory (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the current directory
+ log show the revision history of the repository or a single file
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert modified files or dirs back to their unmodified states
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
++ hg skjdfks
+hg: unknown command 'skjdfks'
+Mercurial Distributed SCM
+
+basic commands (use "hg help" for the full list or option "-v" for details):
+
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff working directory (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the current directory
+ log show the revision history of the repository or a single file
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert modified files or dirs back to their unmodified states
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
More information about the Mercurial
mailing list