summaryrefslogtreecommitdiff
path: root/mercurial/help.py
diff options
context:
space:
mode:
Diffstat (limited to 'mercurial/help.py')
-rw-r--r--mercurial/help.py154
1 files changed, 30 insertions, 124 deletions
diff --git a/mercurial/help.py b/mercurial/help.py
index 79d9966..bebf9df 100644
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -6,119 +6,32 @@
# GNU General Public License version 2 or any later version.
from i18n import gettext, _
-import itertools, sys, os
-import extensions, revset, fileset, templatekw, templatefilters, filemerge
-import encoding, util, minirst
+import sys, os
+import extensions, revset, fileset, templatekw, templatefilters
+import util
def listexts(header, exts, indent=1):
'''return a text listing of the given extensions'''
- rst = []
- if exts:
- rst.append('\n%s\n\n' % header)
- for name, desc in sorted(exts.iteritems()):
- rst.append('%s:%s: %s\n' % (' ' * indent, name, desc))
- return rst
+ if not exts:
+ return ''
+ maxlength = max(len(e) for e in exts)
+ result = '\n%s\n\n' % header
+ for name, desc in sorted(exts.iteritems()):
+ result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
+ ':%s:' % name, desc)
+ return result
def extshelp():
- rst = loaddoc('extensions')().splitlines(True)
- rst.extend(listexts(_('enabled extensions:'), extensions.enabled()))
- rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
- doc = ''.join(rst)
+ doc = loaddoc('extensions')()
+ doc += listexts(_('enabled extensions:'), extensions.enabled())
+ doc += listexts(_('disabled extensions:'), extensions.disabled())
return doc
-def optrst(options, verbose):
- data = []
- multioccur = False
- for option in options:
- if len(option) == 5:
- shortopt, longopt, default, desc, optlabel = option
- else:
- shortopt, longopt, default, desc = option
- optlabel = _("VALUE") # default label
-
- if _("DEPRECATED") in desc and not verbose:
- continue
-
- so = ''
- if shortopt:
- so = '-' + shortopt
- lo = '--' + longopt
- if default:
- desc += _(" (default: %s)") % default
-
- if isinstance(default, list):
- lo += " %s [+]" % optlabel
- multioccur = True
- elif (default is not None) and not isinstance(default, bool):
- lo += " %s" % optlabel
-
- data.append((so, lo, desc))
-
- rst = minirst.maketable(data, 1)
-
- if multioccur:
- rst.append(_("\n[+] marked option can be specified multiple times\n"))
-
- return ''.join(rst)
-
-def topicmatch(kw):
- """Return help topics matching kw.
-
- Returns {'section': [(name, summary), ...], ...} where section is
- one of topics, commands, extensions, or extensioncommands.
- """
- kw = encoding.lower(kw)
- def lowercontains(container):
- return kw in encoding.lower(container) # translated in helptable
- results = {'topics': [],
- 'commands': [],
- 'extensions': [],
- 'extensioncommands': [],
- }
- for names, header, doc in helptable:
- if (sum(map(lowercontains, names))
- or lowercontains(header)
- or lowercontains(doc())):
- results['topics'].append((names[0], header))
- import commands # avoid cycle
- for cmd, entry in commands.table.iteritems():
- if cmd.startswith('debug'):
- continue
- if len(entry) == 3:
- summary = entry[2]
- else:
- summary = ''
- # translate docs *before* searching there
- docs = _(getattr(entry[0], '__doc__', None)) or ''
- if kw in cmd or lowercontains(summary) or lowercontains(docs):
- doclines = docs.splitlines()
- if doclines:
- summary = doclines[0]
- cmdname = cmd.split('|')[0].lstrip('^')
- results['commands'].append((cmdname, summary))
- for name, docs in itertools.chain(
- extensions.enabled().iteritems(),
- extensions.disabled().iteritems()):
- # extensions.load ignores the UI argument
- mod = extensions.load(None, name, '')
- if lowercontains(name) or lowercontains(docs):
- # extension docs are already translated
- results['extensions'].append((name, docs.splitlines()[0]))
- for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
- if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
- cmdname = cmd.split('|')[0].lstrip('^')
- if entry[0].__doc__:
- cmddoc = gettext(entry[0].__doc__).splitlines()[0]
- else:
- cmddoc = _('(no help text available)')
- results['extensioncommands'].append((cmdname, cmddoc))
- return results
-
def loaddoc(topic):
"""Return a delayed loader for help/topic.txt."""
def loader():
- if util.mainfrozen():
+ if hasattr(sys, 'frozen'):
module = sys.executable
else:
module = __file__
@@ -143,24 +56,23 @@ helptable = sorted([
(["patterns"], _("File Name Patterns"), loaddoc('patterns')),
(['environment', 'env'], _('Environment Variables'),
loaddoc('environment')),
- (['revisions', 'revs'], _('Specifying Single Revisions'),
+ (['revs', 'revisions'], _('Specifying Single Revisions'),
loaddoc('revisions')),
- (['multirevs', 'mrevs'], _('Specifying Multiple Revisions'),
+ (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'),
loaddoc('multirevs')),
- (['revsets', 'revset'], _("Specifying Revision Sets"), loaddoc('revsets')),
- (['filesets', 'fileset'], _("Specifying File Sets"), loaddoc('filesets')),
+ (['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')),
+ (['fileset', 'filesets'], _("Specifying File Sets"), loaddoc('filesets')),
(['diffs'], _('Diff Formats'), loaddoc('diffs')),
- (['merge-tools', 'mergetools'], _('Merge Tools'), loaddoc('merge-tools')),
- (['templating', 'templates', 'template', 'style'], _('Template Usage'),
+ (['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')),
+ (['templating', 'templates'], _('Template Usage'),
loaddoc('templates')),
(['urls'], _('URL Paths'), loaddoc('urls')),
- (["extensions"], _("Using Additional Features"), extshelp),
- (["subrepos", "subrepo"], _("Subrepositories"), loaddoc('subrepos')),
- (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
- (["glossary"], _("Glossary"), loaddoc('glossary')),
- (["hgignore", "ignore"], _("Syntax for Mercurial Ignore Files"),
- loaddoc('hgignore')),
- (["phases"], _("Working with Phases"), loaddoc('phases')),
+ (["extensions"], _("Using additional features"), extshelp),
+ (["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')),
+ (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
+ (["glossary"], _("Glossary"), loaddoc('glossary')),
+ (["hgignore", "ignore"], _("syntax for Mercurial ignore files"),
+ loaddoc('hgignore')),
])
# Map topics to lists of callable taking the current topic help and
@@ -181,13 +93,8 @@ def makeitemsdoc(topic, doc, marker, items):
continue
text = gettext(text)
lines = text.splitlines()
- doclines = [(lines[0])]
- for l in lines[1:]:
- # Stop once we find some Python doctest
- if l.strip().startswith('>>>'):
- break
- doclines.append(' ' + l.strip())
- entries.append('\n'.join(doclines))
+ lines[1:] = [(' ' + l.strip()) for l in lines[1:]]
+ entries.append('\n'.join(lines))
entries = '\n\n'.join(entries)
return doc.replace(marker, entries)
@@ -197,7 +104,6 @@ def addtopicsymbols(topic, marker, symbols):
addtopichook(topic, add)
addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols)
-addtopicsymbols('merge-tools', '.. internaltoolsmarker', filemerge.internals)
addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols)
-addtopicsymbols('templates', '.. keywordsmarker', templatekw.dockeywords)
+addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords)
addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters)