--- a/mercurial/commands.py Thu Aug 25 17:13:48 2005 -0700
+++ b/mercurial/commands.py Fri Aug 26 01:56:49 2005 -0700
@@ -343,9 +343,13 @@
"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
)
-def help_(ui, cmd=None):
+def help_(ui, cmd=None, with_version=False):
"""show help for a given command or all commands"""
+ option_lists = []
if cmd and cmd != 'shortlist':
+ if with_version:
+ show_version(ui)
+ ui.write('\n')
key, i = find(cmd)
# synopsis
ui.write("%s\n\n" % i[2])
@@ -356,30 +360,19 @@
doc = doc.splitlines(0)[0]
ui.write("%s\n" % doc.rstrip())
- # aliases
if not ui.quiet:
+ # aliases
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:
- 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)
+ # options
+ if i[1]:
+ option_lists.append(("options", i[1]))
else:
# program name
- if ui.verbose:
+ if ui.verbose or with_version:
show_version(ui)
else:
ui.status("Mercurial Distributed SCM\n")
@@ -422,18 +415,26 @@
# 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)
+ option_lists.append(("global options", globalopts))
+
+ # list all option lists
+ opt_output = []
+ for title, options in option_lists:
+ opt_output.append(("\n%s:\n" % title, None))
+ for shortopt, longopt, default, desc in options:
+ opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
+ longopt and " --%s" % longopt),
+ "%s%s" % (desc,
+ default and " (default: %s)" % default
+ or "")))
+
+ if opt_output:
+ opts_len = max([len(line[0]) for line in opt_output if line[1]])
+ for first, second in opt_output:
+ if second:
+ ui.write(" %-*s %s\n" % (opts_len, first, second))
+ else:
+ ui.write("%s\n" % first)
# Commands start here, listed alphabetically
@@ -668,6 +669,7 @@
raise util.Abort(".hg/dirstate inconsistent with current parent's manifest")
def debugconfig(ui):
+ """show combined config settings from all hgrc files"""
try:
repo = hg.repository(ui)
except: pass
@@ -714,6 +716,7 @@
ui.write("}\n")
def debugwalk(ui, repo, *pats, **opts):
+ """show how files match on given patterns"""
items = list(walk(repo, pats, opts))
if not items: return
fmt = '%%s %%-%ds %%-%ds %%s\n' % (
@@ -791,6 +794,7 @@
repo.forget(forget)
def grep(ui, repo, pattern = None, *pats, **opts):
+ """search for a pattern in specified files and revisions"""
if pattern is None: pattern = opts['regexp']
if not pattern: raise util.Abort('no pattern to search for')
reflags = 0
@@ -1475,7 +1479,7 @@
[('U', 'noupdate', None, 'skip update after cloning'),
('e', 'ssh', "", 'ssh command'),
('', 'remotecmd', "", 'remote hg command')],
- 'hg clone [OPTIONS] SOURCE [DEST]'),
+ 'hg clone [OPTION]... SOURCE [DEST]'),
"^commit|ci":
(commit,
[('A', 'addremove', None, 'run add/remove during commit'),
@@ -1505,12 +1509,12 @@
('a', 'text', None, 'treat all files as text'),
('I', 'include', [], 'include path in search'),
('X', 'exclude', [], 'exclude path from search')],
- 'hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'),
+ 'hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'),
"^export":
(export,
[('o', 'output', "", 'output to file'),
('a', 'text', None, 'treat all files as text')],
- "hg export [-o OUTFILE] REV..."),
+ "hg export [-a] [-o OUTFILE] REV..."),
"forget":
(forget,
[('I', 'include', [], 'include path in search'),
@@ -1534,7 +1538,7 @@
"heads":
(heads,
[('b', 'branches', None, 'find branch info')],
- 'hg [-b] heads'),
+ 'hg heads [-b]'),
"help": (help_, [], 'hg help [COMMAND]'),
"identify|id": (identify, [], 'hg identify'),
"import|patch":
@@ -1542,7 +1546,7 @@
[('p', 'strip', 1, 'path strip'),
('f', 'force', None, 'skip check for outstanding changes'),
('b', 'base', "", 'base path')],
- "hg import [-p NUM] [-b BASE] PATCH..."),
+ "hg import [-f] [-p NUM] [-b BASE] PATCH..."),
"incoming|in": (incoming, [], 'hg incoming [SOURCE]'),
"^init": (init, [], 'hg init [DEST]'),
"locate":
@@ -1559,7 +1563,7 @@
('X', 'exclude', [], 'exclude path from search'),
('r', 'rev', [], 'revision'),
('p', 'patch', None, 'show patch')],
- 'hg log [-r REV1 [-r REV2]] [-p] [FILE]'),
+ 'hg log [-I] [-X] [-r REV]... [-p] [FILE]'),
"manifest": (manifest, [], 'hg manifest [REV]'),
"outgoing|out": (outgoing, [], 'hg outgoing [DEST]'),
"parents": (parents, [], 'hg parents [REV]'),
@@ -1569,13 +1573,13 @@
[('u', 'update', None, 'update working directory'),
('e', 'ssh', "", 'ssh command'),
('', 'remotecmd', "", 'remote hg command')],
- 'hg pull [OPTIONS] [SOURCE]'),
+ 'hg pull [-u] [-e FILE] [--remotecmd FILE] [SOURCE]'),
"^push":
(push,
[('f', 'force', None, 'force push'),
('e', 'ssh', "", 'ssh command'),
('', 'remotecmd', "", 'remote hg command')],
- 'hg push [-f] [DEST]'),
+ 'hg push [-f] [-e FILE] [--remotecmd FILE] [DEST]'),
"rawcommit":
(rawcommit,
[('p', 'parent', [], 'parent'),
@@ -1634,19 +1638,21 @@
'hg update [-b TAG] [-m] [-C] [REV]'),
"verify": (verify, [], 'hg verify'),
"version": (show_version, [], 'hg version'),
- }
+}
-globalopts = [('v', 'verbose', None, 'verbose mode'),
- ('', 'debug', None, 'debug mode'),
- ('q', 'quiet', None, 'quiet mode'),
- ('', 'profile', None, 'profile'),
- ('', 'cwd', '', 'change working directory'),
- ('R', 'repository', "", 'repository root directory'),
- ('', 'traceback', None, 'print traceback on exception'),
- ('y', 'noninteractive', None, 'run non-interactively'),
- ('', 'version', None, 'output version information and exit'),
- ('', 'time', None, 'time how long the command takes'),
- ]
+globalopts = [
+ ('R', 'repository', "", 'repository root directory'),
+ ('', 'cwd', '', 'change working directory'),
+ ('y', 'noninteractive', None, 'run non-interactively'),
+ ('q', 'quiet', None, 'quiet mode'),
+ ('v', 'verbose', None, 'verbose mode'),
+ ('', 'debug', None, 'debug mode'),
+ ('', 'traceback', None, 'print traceback on exception'),
+ ('', 'time', None, 'time how long the command takes'),
+ ('', 'profile', None, 'profile'),
+ ('', 'version', None, 'output version information and exit'),
+ ('h', 'help', None, 'display help and exit'),
+]
norepo = "clone init version help debugconfig debugdata" + \
" debugindex debugindexdot paths"
@@ -1679,17 +1685,15 @@
except fancyopts.getopt.GetoptError, inst:
raise ParseError(None, inst)
- if options["version"]:
- return ("version", show_version, [], options, cmdoptions)
- elif not args:
- return ("help", help_, ["shortlist"], options, cmdoptions)
+ if args:
+ cmd, args = args[0], args[1:]
+ i = find(cmd)[1]
+ c = list(i[1])
else:
- cmd, args = args[0], args[1:]
-
- i = find(cmd)[1]
+ cmd = None
+ c = []
# combine global options into local
- c = list(i[1])
for o in globalopts:
c.append((o[0], o[1], options[o[1]], o[3]))
@@ -1704,7 +1708,7 @@
options[n] = cmdoptions[n]
del cmdoptions[n]
- return (cmd, i[0], args, options, cmdoptions)
+ return (cmd, cmd and i[0] or None, args, options, cmdoptions)
def dispatch(args):
signal.signal(signal.SIGTERM, catchterm)
@@ -1730,14 +1734,6 @@
help_(u, 'shortlist')
sys.exit(1)
- if options['cwd']:
- try:
- os.chdir(options['cwd'])
- except OSError, inst:
- u = ui.ui()
- u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
- sys.exit(1)
-
if options["time"]:
def get_times():
t = os.times()
@@ -1757,6 +1753,23 @@
try:
try:
+ if options['help']:
+ help_(u, cmd, options['version'])
+ sys.exit(0)
+ elif options['version']:
+ show_version(u)
+ sys.exit(0)
+ elif not cmd:
+ help_(u, 'shortlist')
+ sys.exit(0)
+
+ if options['cwd']:
+ try:
+ os.chdir(options['cwd'])
+ except OSError, inst:
+ u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
+ sys.exit(1)
+
if cmd not in norepo.split():
path = options["repository"] or ""
repo = hg.repository(ui=u, path=path)