Skip to content

Commit

Permalink
Refactor repeated code into get_don method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergius-Nyah committed Dec 22, 2023
1 parent 41c6707 commit 8f940db
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions awscli/clidocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ def unregister(self):
self._map_handlers(self.help_command.session,
self.help_command.event_class,
self.help_command.session.unregister)

# These are default doc handlers that apply in the general case.

def doc_breadcrumbs(self, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
if doc.target != 'man':
cmd_names = help_command.event_class.split('.')
doc.write('[ ')
Expand All @@ -126,7 +125,7 @@ def doc_breadcrumbs(self, help_command, **kwargs):
doc.write(' ]')

def doc_title(self, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
doc.style.new_paragraph()
reference = help_command.event_class.replace('.', ' ')
if reference != 'aws':
Expand All @@ -135,20 +134,20 @@ def doc_title(self, help_command, **kwargs):
doc.style.h1(help_command.name)

def doc_description(self, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
doc.style.h2(DESCRIPTION) # Replace local constants with global constants
doc.include_doc_string(help_command.description)
doc.style.new_paragraph()

def doc_synopsis_start(self, help_command, **kwargs):
self._documented_arg_groups = []
doc = help_command.doc
doc = self.get_doc(help_command)
doc.style.h2(SYNOPSIS) # Replace local constants with global constants
doc.style.start_codeblock()
doc.writeln('%s' % help_command.name)

def doc_synopsis_option(self, arg_name, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
argument = help_command.arg_table[arg_name]
if argument.group_name in self._arg_groups:
if argument.group_name in self._documented_arg_groups:
Expand All @@ -168,7 +167,7 @@ def doc_synopsis_option(self, arg_name, help_command, **kwargs):
doc.writeln('%s' % option_str)

def doc_synopsis_end(self, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
# Append synopsis for global options.
doc.write_from_file(GLOBAL_OPTIONS_SYNOPSIS_FILE)
doc.style.end_codeblock()
Expand All @@ -178,12 +177,12 @@ def doc_synopsis_end(self, help_command, **kwargs):
self._documented_arg_groups = []

def doc_options_start(self, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
doc.style.h2(OPTIONS) # Replace local constants with global constants
if not help_command.arg_table:
doc.write('*None*\n')
def doc_option(self, arg_name, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
argument = help_command.arg_table[arg_name]
self._document_arg_group(argument, doc)
self._document_individual_arg(argument, doc)
Expand All @@ -194,17 +193,17 @@ def doc_option(self, arg_name, help_command, **kwargs):


def doc_global_option(self, help_command, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
doc.style.h2('Global Options')
doc.write_from_file(GLOBAL_OPTIONS_FILE)

def doc_relateditems_start(self, help_command, **kwargs):
if help_command.related_items:
doc = help_command.doc
doc = self.get_doc(help_command)
doc.style.h2('See Also')

def doc_relateditem(self, help_command, related_item, **kwargs):
doc = help_command.doc
doc = self.get_doc(help_command)
doc.write('* ')
doc.style.sphinx_reference_label(
label='cli:%s' % related_item,
Expand Down

0 comments on commit 8f940db

Please sign in to comment.