Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 40292:9c6473d2038b
help: splitting the topics by category
Differential Revision: https://phab.mercurial-scm.org/D5066
author | Rodrigo Damazio <rdamazio@google.com> |
---|---|
date | Fri, 12 Oct 2018 17:57:36 +0200 |
parents | 170926caf44c |
children | c303d65d2e34 |
comparison
equal
deleted
inserted
replaced
40291:170926caf44c | 40292:9c6473d2038b |
---|---|
60 # Extensions with custom categories should add their names here. | 60 # Extensions with custom categories should add their names here. |
61 CATEGORY_NAMES = { | 61 CATEGORY_NAMES = { |
62 registrar.command.CATEGORY_NONE: 'Uncategorized commands', | 62 registrar.command.CATEGORY_NONE: 'Uncategorized commands', |
63 } | 63 } |
64 | 64 |
65 # Topic categories. | |
66 TOPIC_CATEGORY_NONE = 'none' | |
67 | |
68 # The order in which topic categories will be displayed. | |
69 # Extensions with custom categories should insert them into this list | |
70 # after/before the appropriate item, rather than replacing the list or | |
71 # assuming absolute positions. | |
72 TOPIC_CATEGORY_ORDER = [ | |
73 TOPIC_CATEGORY_NONE, | |
74 ] | |
75 | |
76 # Human-readable topic category names. These are translated. | |
77 TOPIC_CATEGORY_NAMES = { | |
78 TOPIC_CATEGORY_NONE: 'Uncategorized topics', | |
79 } | |
80 | |
65 def listexts(header, exts, indent=1, showdeprecated=False): | 81 def listexts(header, exts, indent=1, showdeprecated=False): |
66 '''return a text listing of the given extensions''' | 82 '''return a text listing of the given extensions''' |
67 rst = [] | 83 rst = [] |
68 if exts: | 84 if exts: |
69 for name, desc in sorted(exts.iteritems()): | 85 for name, desc in sorted(exts.iteritems()): |
150 results = {'topics': [], | 166 results = {'topics': [], |
151 'commands': [], | 167 'commands': [], |
152 'extensions': [], | 168 'extensions': [], |
153 'extensioncommands': [], | 169 'extensioncommands': [], |
154 } | 170 } |
155 for names, header, doc in helptable: | 171 for topic in helptable: |
172 names, header, doc = topic[0:3] | |
156 # Old extensions may use a str as doc. | 173 # Old extensions may use a str as doc. |
157 if (sum(map(lowercontains, names)) | 174 if (sum(map(lowercontains, names)) |
158 or lowercontains(header) | 175 or lowercontains(header) |
159 or (callable(doc) and lowercontains(doc(ui)))): | 176 or (callable(doc) and lowercontains(doc(ui)))): |
160 results['topics'].append((names[0], header)) | 177 results['topics'].append((names[0], header)) |
517 exts = listexts(_('enabled extensions:'), extensions.enabled()) | 534 exts = listexts(_('enabled extensions:'), extensions.enabled()) |
518 if exts: | 535 if exts: |
519 rst.append('\n') | 536 rst.append('\n') |
520 rst.extend(exts) | 537 rst.extend(exts) |
521 | 538 |
522 rst.append(_("\nadditional help topics:\n\n")) | 539 rst.append(_("\nadditional help topics:\n")) |
523 topics = [] | 540 # Group commands by category. |
524 for names, header, doc in helptable: | 541 topiccats = {} |
525 topics.append((names[0], header)) | 542 for topic in helptable: |
526 for t, desc in topics: | 543 names, header, doc = topic[0:3] |
527 rst.append(" :%s: %s\n" % (t, desc)) | 544 if len(topic) > 3 and topic[3]: |
545 category = topic[3] | |
546 else: | |
547 category = TOPIC_CATEGORY_NONE | |
548 | |
549 topiccats.setdefault(category, []).append((names[0], header)) | |
550 | |
551 # Check that all categories have an order. | |
552 missing_order = set(topiccats.keys()) - set(TOPIC_CATEGORY_ORDER) | |
553 if missing_order: | |
554 ui.develwarn( | |
555 'help categories missing from TOPIC_CATEGORY_ORDER: %s' % | |
556 missing_order) | |
557 | |
558 # Output topics per category. | |
559 for cat in TOPIC_CATEGORY_ORDER: | |
560 topics = topiccats.get(cat, []) | |
561 if topics: | |
562 if len(topiccats) > 1: | |
563 catname = gettext(TOPIC_CATEGORY_NAMES[cat]) | |
564 rst.append("\n%s:\n" % catname) | |
565 rst.append("\n") | |
566 for t, desc in topics: | |
567 rst.append(" :%s: %s\n" % (t, desc)) | |
528 | 568 |
529 if ui.quiet: | 569 if ui.quiet: |
530 pass | 570 pass |
531 elif ui.verbose: | 571 elif ui.verbose: |
532 rst.append('\n%s\n' % optrst(_("global options"), | 572 rst.append('\n%s\n' % optrst(_("global options"), |
557 for names, header, doc in subtopics[name]: | 597 for names, header, doc in subtopics[name]: |
558 if subtopic in names: | 598 if subtopic in names: |
559 break | 599 break |
560 | 600 |
561 if not header: | 601 if not header: |
562 for names, header, doc in helptable: | 602 for topic in helptable: |
603 names, header, doc = topic[0:3] | |
563 if name in names: | 604 if name in names: |
564 break | 605 break |
565 else: | 606 else: |
566 raise error.UnknownCommand(name) | 607 raise error.UnknownCommand(name) |
567 | 608 |