# HG changeset patch # User Thomas Arendsen Hein # Date 1125042993 -7200 # Node ID d8279ca39dc776c9e39d6473fbfd263c4e876069 # Parent 3c918b7ad8daeae3baf5f27569db8cd6b1987899 Adjust display and alignment of command options to match global options. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -271,6 +271,7 @@ def show_version(ui): 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) @@ -285,26 +286,15 @@ def help_(ui, cmd=None, with_version=Fal 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 @@ -351,16 +341,26 @@ def help_(ui, cmd=None, with_version=Fal # global options if ui.verbose: - ui.write("\nglobal options:\n\n") - opts, descriptions = [], [] - for shortopt, longopt, default, desc in globalopts: - opts.append("%2s%s" % - (shortopt and "-%s" % shortopt, - longopt and " --%s" % longopt)) - descriptions.append(desc) - opts_len = max(map(len, opts)) - for opt, desc in zip(opts, descriptions): - ui.write(" %-*s %s\n" % (opts_len, opt, desc)) + 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 diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -118,10 +118,8 @@ add the specified files on the next comm options: - -I --include - include path in search - -X --exclude - exclude path from search + -I --include include path in search + -X --exclude exclude path from search hg add: option --skjdfks not recognized hg add [OPTION]... [FILE]... @@ -129,24 +127,18 @@ add the specified files on the next comm options: - -I --include - include path in search - -X --exclude - exclude path from search + -I --include include path in search + -X --exclude exclude path from search hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]... diff working directory (or selected files) options: - -r --rev - revision - -a --text - treat all files as text - -I --include - include path in search - -X --exclude - exclude path from search + -r --rev revision + -a --text treat all files as text + -I --include include path in search + -X --exclude exclude path from search hg status [OPTION]... [FILE]... show changed files in the working directory @@ -158,18 +150,12 @@ show changed files in the working direct 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 + -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 status [OPTION]... [FILE]... show changed files in the working directory