| 784 | |
| 785 | |
| 786 | class TopicDocumentEventHandler(TopicListerDocumentEventHandler): |
| 787 | def doc_breadcrumbs(self, help_command, **kwargs): |
| 788 | doc = help_command.doc |
| 789 | if doc.target != 'man': |
| 790 | doc.write('[ ') |
| 791 | doc.style.sphinx_reference_label(label='cli:aws', text='aws') |
| 792 | doc.write(' . ') |
| 793 | doc.style.sphinx_reference_label( |
| 794 | label='cli:aws help topics', text='topics' |
| 795 | ) |
| 796 | doc.write(' ]') |
| 797 | |
| 798 | def doc_title(self, help_command, **kwargs): |
| 799 | doc = help_command.doc |
| 800 | doc.style.new_paragraph() |
| 801 | doc.style.link_target_definition( |
| 802 | refname=f'cli:aws help {self.help_command.name}', link='' |
| 803 | ) |
| 804 | title = self._topic_tag_db.get_tag_single_value( |
| 805 | help_command.name, 'title' |
| 806 | ) |
| 807 | doc.style.h1(title) |
| 808 | |
| 809 | def doc_description(self, help_command, **kwargs): |
| 810 | doc = help_command.doc |
| 811 | topic_filename = os.path.join( |
| 812 | self._topic_tag_db.topic_dir, help_command.name + '.rst' |
| 813 | ) |
| 814 | contents = self._remove_tags_from_content(topic_filename) |
| 815 | doc.writeln(contents) |
| 816 | doc.style.new_paragraph() |
| 817 | |
| 818 | def _remove_tags_from_content(self, filename): |
| 819 | with open(filename) as f: |
| 820 | lines = f.readlines() |
| 821 | |
| 822 | content_begin_index = 0 |
| 823 | for i, line in enumerate(lines): |
| 824 | # If a line is encountered that does not begin with the tag |
| 825 | # end the search for tags and mark where tags end. |
| 826 | if not self._line_has_tag(line): |
| 827 | content_begin_index = i |
| 828 | break |
| 829 | |
| 830 | # Join all of the non-tagged lines back together. |
| 831 | return ''.join(lines[content_begin_index:]) |
| 832 | |
| 833 | def _line_has_tag(self, line): |
| 834 | for tag in self._topic_tag_db.valid_tags: |
| 835 | if line.startswith(':' + tag + ':'): |
| 836 | return True |
| 837 | return False |
| 838 | |
| 839 | def doc_subitems_start(self, help_command, **kwargs): |
| 840 | pass |
| 841 | |
| 842 | |
| 843 | class GlobalOptionsDocumenter: |