Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 16781:c0b98f436cce
help: move some helper functions to help.py
author | Olav Reinert <seroton10@gmail.com> |
---|---|
date | Tue, 22 May 2012 22:08:41 +0200 |
parents | 497deec204d1 |
children | e740746ea557 |
comparison
equal
deleted
inserted
replaced
16780:d064da05590d | 16781:c0b98f436cce |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from i18n import gettext, _ | 8 from i18n import gettext, _ |
9 import itertools, sys, os | 9 import itertools, sys, os |
10 import extensions, revset, fileset, templatekw, templatefilters, filemerge | 10 import extensions, revset, fileset, templatekw, templatefilters, filemerge |
11 import encoding, util | 11 import encoding, util, minirst |
12 | 12 |
13 def listexts(header, exts, indent=1): | 13 def listexts(header, exts, indent=1): |
14 '''return a text listing of the given extensions''' | 14 '''return a text listing of the given extensions''' |
15 if not exts: | 15 if not exts: |
16 return '' | 16 return '' |
24 def extshelp(): | 24 def extshelp(): |
25 doc = loaddoc('extensions')() | 25 doc = loaddoc('extensions')() |
26 doc += listexts(_('enabled extensions:'), extensions.enabled()) | 26 doc += listexts(_('enabled extensions:'), extensions.enabled()) |
27 doc += listexts(_('disabled extensions:'), extensions.disabled()) | 27 doc += listexts(_('disabled extensions:'), extensions.disabled()) |
28 return doc | 28 return doc |
29 | |
30 def optrst(options, verbose): | |
31 data = [] | |
32 multioccur = False | |
33 for option in options: | |
34 if len(option) == 5: | |
35 shortopt, longopt, default, desc, optlabel = option | |
36 else: | |
37 shortopt, longopt, default, desc = option | |
38 optlabel = _("VALUE") # default label | |
39 | |
40 if _("DEPRECATED") in desc and not verbose: | |
41 continue | |
42 | |
43 so = '' | |
44 if shortopt: | |
45 so = '-' + shortopt | |
46 lo = '--' + longopt | |
47 if default: | |
48 desc += _(" (default: %s)") % default | |
49 | |
50 if isinstance(default, list): | |
51 lo += " %s [+]" % optlabel | |
52 multioccur = True | |
53 elif (default is not None) and not isinstance(default, bool): | |
54 lo += " %s" % optlabel | |
55 | |
56 data.append((so, lo, desc)) | |
57 | |
58 rst = minirst.maketable(data, 1) | |
59 | |
60 if multioccur: | |
61 rst += _("\n[+] marked option can be specified multiple times\n") | |
62 | |
63 return rst | |
64 | |
65 # list all option lists | |
66 def opttext(optlist, width, verbose): | |
67 rst = '' | |
68 if not optlist: | |
69 return '' | |
70 | |
71 for title, options in optlist: | |
72 rst += '\n%s\n' % title | |
73 if options: | |
74 rst += "\n" | |
75 rst += optrst(options, verbose) | |
76 rst += '\n' | |
77 | |
78 return '\n' + minirst.format(rst, width) | |
29 | 79 |
30 def topicmatch(kw): | 80 def topicmatch(kw): |
31 """Return help topics matching kw. | 81 """Return help topics matching kw. |
32 | 82 |
33 Returns {'section': [(name, summary), ...], ...} where section is | 83 Returns {'section': [(name, summary), ...], ...} where section is |