##// END OF EJS Templates
help: basic support for showing only specified topic sections...
Matt Mackall -
r22587:c3c3dd31 default
parent child Browse files
Show More
@@ -3834,14 +3834,23 b' def help_(ui, name=None, **opts):'
3834 3834 keep.append('unix')
3835 3835 keep.append(sys.platform.lower())
3836 3836
3837 section = None
3838 if name and '.' in name:
3839 name, section = name.split('.')
3840
3837 3841 text = help.help_(ui, name, **opts)
3838 3842
3839 formatted, pruned = minirst.format(text, textwidth, keep=keep)
3843 formatted, pruned = minirst.format(text, textwidth, keep=keep,
3844 section=section)
3845 if section and not formatted:
3846 raise util.Abort(_("help section not found"))
3847
3840 3848 if 'verbose' in pruned:
3841 3849 keep.append('omitted')
3842 3850 else:
3843 3851 keep.append('notomitted')
3844 formatted, pruned = minirst.format(text, textwidth, keep=keep)
3852 formatted, pruned = minirst.format(text, textwidth, keep=keep,
3853 section=section)
3845 3854 ui.write(formatted)
3846 3855
3847 3856
@@ -648,9 +648,15 b' def formatblocks(blocks, width):'
648 648 text = ''.join(formatblock(b, width) for b in blocks)
649 649 return text
650 650
651 def format(text, width=80, indent=0, keep=None, style='plain'):
651 def format(text, width=80, indent=0, keep=None, style='plain', section=None):
652 652 """Parse and format the text according to width."""
653 653 blocks, pruned = parse(text, indent, keep or [])
654 if section:
655 sections = getsections(blocks)
656 blocks = []
657 for name, nest, b in sections:
658 if name == section:
659 blocks = b
654 660 if style == 'html':
655 661 text = formathtml(blocks)
656 662 else:
@@ -665,6 +671,14 b' def getsections(blocks):'
665 671 nest = ""
666 672 level = 0
667 673 secs = []
674
675 def getname(b):
676 x = b['lines'][0]
677 x = x.lower().strip('"')
678 if '(' in x:
679 x = x.split('(')[0]
680 return x
681
668 682 for b in blocks:
669 683 if b['type'] == 'section':
670 684 i = b['underline']
@@ -672,7 +686,14 b' def getsections(blocks):'
672 686 nest += i
673 687 level = nest.index(i) + 1
674 688 nest = nest[:level]
675 secs.append((b['lines'][0], level, [b]))
689 secs.append((getname(b), level, [b]))
690 if b['type'] == 'definition':
691 i = ' '
692 if i not in nest:
693 nest += i
694 level = nest.index(i) + 1
695 nest = nest[:level]
696 secs.append((getname(b), level, [b]))
676 697 else:
677 698 if not secs:
678 699 # add an initial empty section
@@ -1046,6 +1046,25 b' Test omit indicating for help'
1046 1046
1047 1047 This paragraph is never omitted, too (for topic)
1048 1048
1049 Test section lookup
1050
1051 $ hg help revset.merge
1052 "merge()"
1053 Changeset is a merge changeset.
1054
1055 $ hg help glossary.dag
1056 DAG
1057 The repository of changesets of a distributed version control system
1058 (DVCS) can be described as a directed acyclic graph (DAG), consisting
1059 of nodes and edges, where nodes correspond to changesets and edges
1060 imply a parent -> child relation. This graph can be visualized by
1061 graphical tools such as "hg log --graph". In Mercurial, the DAG is
1062 limited by the requirement for children to have at most two parents.
1063
1064 $ hg help glossary.mcguffin
1065 abort: help section not found
1066 [255]
1067
1049 1068 Test usage of section marks in help documents
1050 1069
1051 1070 $ cd "$TESTDIR"/../doc
General Comments 0
You need to be logged in to leave comments. Login now