[PATCH 03 of 10] help: generate and use rst for the complete help topic
Erik Zielke
ez at aragost.com
Wed Nov 17 17:11:02 UTC 2010
# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1289291905 -3600
# Node ID 494f49235490c88504f183630001824fcb708e60
# Parent 8b1c0f96014d2a6c955a9a92c5efd72358b48e08
help: generate and use rst for the complete help topic
This also introduces a config object, to send information to the help
module.
diff -r 8b1c0f96014d -r 494f49235490 mercurial/commands.py
--- a/mercurial/commands.py Tue Nov 09 09:28:51 2010 +0100
+++ b/mercurial/commands.py Tue Nov 09 09:38:25 2010 +0100
@@ -1871,6 +1871,7 @@
"""
option_lists = []
textwidth = ui.termwidth() - 2
+ helpconfig = help.createhelpconfig(name, ui.verbose)
def addglobalopts(aliases):
if ui.verbose:
@@ -1993,20 +1994,11 @@
addglobalopts(True)
def helptopic(name):
- for names, header, doc in help.helptable:
- if name in names:
- break
- else:
- raise error.UnknownCommand(name)
-
- # description
- if not doc:
- doc = _("(no help text available)")
- if hasattr(doc, '__call__'):
- doc = doc()
-
- ui.write("%s\n\n" % header)
- ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
+ helptopicrst = help.generatehelptopicrst(helpconfig)
+ formatted, pruned = minirst.format(helptopicrst, textwidth,
+ keep=helpconfig['keep'])
+ ui.write(formatted)
+ ui.write('\n')
def helpext(name):
try:
diff -r 8b1c0f96014d -r 494f49235490 mercurial/help.py
--- a/mercurial/help.py Tue Nov 09 09:28:51 2010 +0100
+++ b/mercurial/help.py Tue Nov 09 09:38:25 2010 +0100
@@ -7,7 +7,7 @@
from i18n import gettext, _
import sys, os, textwrap
-import extensions, util
+import extensions, util, error
def moduledoc(file):
@@ -187,6 +187,40 @@
return ''.join(versionlines)
+def createhelpconfig(name, verbose):
+ helpconfig = {'name': name,
+ 'keep': []
+ }
+ if verbose:
+ helpconfig['keep'].append('verbose')
+
+ return helpconfig
+
+def generatehelptopicrst(helpconfig):
+ """Returns rst for the help topic with the given name"""
+
+ for names, header, doc in helptable:
+ if helpconfig['name'] in names:
+ break
+ else:
+ raise error.UnknownCommand(helpconfig['name'])
+
+ # description
+ if not doc:
+ doc = _("(no help text available)")
+ if hasattr(doc, '__call__'):
+ doc = doc()
+
+ lines = []
+ lines.append("%s\n\n" % header)
+ oldlines = doc.splitlines()
+
+ indentedlines = [' %s' % line for line in oldlines]
+
+ lines.extend('\n'.join(indentedlines))
+ lines.append('\n')
+ return ''.join(lines)
+
helptable = [
(["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
(["dates"], _("Date Formats"), loaddoc('dates')),
More information about the Mercurial-devel
mailing list