##// END OF EJS Templates
help: extract logic for listing commands and topics...
Ludovic Chabant -
r46218:65cb924a default
parent child Browse files
Show More
@@ -638,6 +638,53 b' def inserttweakrc(ui, topic, doc):'
638 return re.sub(br'( *)%s' % re.escape(marker), sub, doc)
638 return re.sub(br'( *)%s' % re.escape(marker), sub, doc)
639
639
640
640
641 def _getcategorizedhelpcmds(ui, cmdtable, name, select=None):
642 # Category -> list of commands
643 cats = {}
644 # Command -> short description
645 h = {}
646 # Command -> string showing synonyms
647 syns = {}
648 for c, e in pycompat.iteritems(cmdtable):
649 fs = cmdutil.parsealiases(c)
650 f = fs[0]
651 syns[f] = fs
652 func = e[0]
653 if select and not select(f):
654 continue
655 doc = pycompat.getdoc(func)
656 if filtercmd(ui, f, func, name, doc):
657 continue
658 doc = gettext(doc)
659 if not doc:
660 doc = _(b"(no help text available)")
661 h[f] = doc.splitlines()[0].rstrip()
662
663 cat = getattr(func, 'helpcategory', None) or (
664 registrar.command.CATEGORY_NONE
665 )
666 cats.setdefault(cat, []).append(f)
667 return cats, h, syns
668
669
670 def _getcategorizedhelptopics(ui, topictable):
671 # Group commands by category.
672 topiccats = {}
673 syns = {}
674 for topic in topictable:
675 names, header, doc = topic[0:3]
676 if len(topic) > 3 and topic[3]:
677 category = topic[3]
678 else:
679 category = TOPIC_CATEGORY_NONE
680
681 topicname = names[0]
682 syns[topicname] = list(names)
683 if not filtertopic(ui, topicname):
684 topiccats.setdefault(category, []).append((topicname, header))
685 return topiccats, syns
686
687
641 addtopichook(b'config', inserttweakrc)
688 addtopichook(b'config', inserttweakrc)
642
689
643
690
@@ -760,31 +807,9 b' def help_('
760 return rst
807 return rst
761
808
762 def helplist(select=None, **opts):
809 def helplist(select=None, **opts):
763 # Category -> list of commands
810 cats, h, syns = _getcategorizedhelpcmds(
764 cats = {}
811 ui, commands.table, name, select
765 # Command -> short description
812 )
766 h = {}
767 # Command -> string showing synonyms
768 syns = {}
769 for c, e in pycompat.iteritems(commands.table):
770 fs = cmdutil.parsealiases(c)
771 f = fs[0]
772 syns[f] = b', '.join(fs)
773 func = e[0]
774 if select and not select(f):
775 continue
776 doc = pycompat.getdoc(func)
777 if filtercmd(ui, f, func, name, doc):
778 continue
779 doc = gettext(doc)
780 if not doc:
781 doc = _(b"(no help text available)")
782 h[f] = doc.splitlines()[0].rstrip()
783
784 cat = getattr(func, 'helpcategory', None) or (
785 registrar.command.CATEGORY_NONE
786 )
787 cats.setdefault(cat, []).append(f)
788
813
789 rst = []
814 rst = []
790 if not h:
815 if not h:
@@ -805,7 +830,7 b' def help_('
805 cmds = sorted(cmds)
830 cmds = sorted(cmds)
806 for c in cmds:
831 for c in cmds:
807 if ui.verbose:
832 if ui.verbose:
808 rst.append(b" :%s: %s\n" % (syns[c], h[c]))
833 rst.append(b" :%s: %s\n" % (b', '.join(syns[c]), h[c]))
809 else:
834 else:
810 rst.append(b' :%s: %s\n' % (c, h[c]))
835 rst.append(b' :%s: %s\n' % (c, h[c]))
811
836
@@ -844,20 +869,7 b' def help_('
844 rst.extend(exts)
869 rst.extend(exts)
845
870
846 rst.append(_(b"\nadditional help topics:\n"))
871 rst.append(_(b"\nadditional help topics:\n"))
847 # Group commands by category.
872 topiccats, topicsyns = _getcategorizedhelptopics(ui, helptable)
848 topiccats = {}
849 for topic in helptable:
850 names, header, doc = topic[0:3]
851 if len(topic) > 3 and topic[3]:
852 category = topic[3]
853 else:
854 category = TOPIC_CATEGORY_NONE
855
856 topicname = names[0]
857 if not filtertopic(ui, topicname):
858 topiccats.setdefault(category, []).append(
859 (topicname, header)
860 )
861
873
862 # Check that all categories have an order.
874 # Check that all categories have an order.
863 missing_order = set(topiccats.keys()) - set(TOPIC_CATEGORY_ORDER)
875 missing_order = set(topiccats.keys()) - set(TOPIC_CATEGORY_ORDER)
General Comments 0
You need to be logged in to leave comments. Login now