# HG changeset patch # User Alexis S. L. Carvalho # Date 1184885005 10800 # Node ID 93b7e2fa7ee32aa6f82b2f221eb5afdc2121d858 # Parent b8076522e889859ce8954ac5655b210531b25d45 help: avoid traceback if an extension has only debug commands diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1340,7 +1340,7 @@ def help_(ui, name=None, with_version=Fa addglobalopts(False) - def helplist(select=None): + def helplist(header, select=None): h = {} cmds = {} for c, e in table.items(): @@ -1358,6 +1358,11 @@ def help_(ui, name=None, with_version=Fa h[f] = doc.splitlines(0)[0].rstrip() cmds[f] = c.lstrip("^") + if not h: + ui.status(_('no commands defined\n')) + return + + ui.status(header) fns = h.keys() fns.sort() m = max(map(len, fns)) @@ -1407,14 +1412,10 @@ def help_(ui, name=None, with_version=Fa try: ct = mod.cmdtable except AttributeError: - ct = None - if not ct: - ui.status(_('no commands defined\n')) - return - - ui.status(_('list of commands:\n\n')) + ct = {} + modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct]) - helplist(modcmds.has_key) + helplist(_('list of commands:\n\n'), modcmds.has_key) if name and name != 'shortlist': i = None @@ -1438,11 +1439,11 @@ def help_(ui, name=None, with_version=Fa # list of commands if name == "shortlist": - ui.status(_('basic commands:\n\n')) + header = _('basic commands:\n\n') else: - ui.status(_('list of commands:\n\n')) - - helplist() + header = _('list of commands:\n\n') + + helplist(header) # list all option lists opt_output = [] diff --git a/tests/test-extension b/tests/test-extension --- a/tests/test-extension +++ b/tests/test-extension @@ -64,3 +64,18 @@ emptypath=`pwd`/empty.py echo '[extensions]' > $HGRCPATH echo "empty = $emptypath" >> $HGRCPATH hg help empty + +cat > debugextension.py < $HGRCPATH +echo "debugextension = $debugpath" >> $HGRCPATH +hg help debugextension +hg --debug help debugextension diff --git a/tests/test-extension.out b/tests/test-extension.out --- a/tests/test-extension.out +++ b/tests/test-extension.out @@ -22,3 +22,30 @@ Foo empty extension - empty cmdtable no commands defined +debugextension extension - only debugcommands + +no commands defined +debugextension extension - only debugcommands + +list of commands: + + debugfoobar: + yet another debug command + +global options: + -R --repository repository root directory or symbolic path name + --cwd change working directory + -y --noninteractive do not prompt, assume 'yes' for any required answers + -q --quiet suppress output + -v --verbose enable additional output + --config set/override config option + --debug enable debugging output + --debugger start debugger + --encoding set the charset encoding (default: ascii) + --encodingmode set the charset encoding mode (default: strict) + --lsprof print improved command execution profile + --traceback print traceback on exception + --time time how long the command takes + --profile print command execution profile + --version output version information and exit + -h --help display help and exit