Add support for epilogs
An epilog is text that's displayed after the argument help. It can be useful to provide some broader context as to the command in question. This change update the 'sphinxext' plugin to include this in its output. Change-Id: I7f0bf8ba92dc34cc2e3e9fa2a93ec91ee2f9f8ac
This commit is contained in:
parent
e7a6a596c5
commit
f7e3ac4509
@ -30,6 +30,7 @@ class Command(object):
|
|||||||
deprecated = False
|
deprecated = False
|
||||||
|
|
||||||
_description = ''
|
_description = ''
|
||||||
|
_epilog = None
|
||||||
|
|
||||||
def __init__(self, app, app_args, cmd_name=None):
|
def __init__(self, app, app_args, cmd_name=None):
|
||||||
self.app = app
|
self.app = app
|
||||||
@ -59,11 +60,16 @@ class Command(object):
|
|||||||
desc = ''
|
desc = ''
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
|
def get_epilog(self):
|
||||||
|
"""Return the command epilog."""
|
||||||
|
return self._epilog
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
"""Return an :class:`argparse.ArgumentParser`.
|
"""Return an :class:`argparse.ArgumentParser`.
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description=self.get_description(),
|
description=self.get_description(),
|
||||||
|
epilog=self.get_epilog(),
|
||||||
prog=prog_name,
|
prog=prog_name,
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
@ -176,6 +176,7 @@ class AutoprogramCliffDirective(rst.Directive):
|
|||||||
command = command_class(None, None)
|
command = command_class(None, None)
|
||||||
parser = command.get_parser(command_name)
|
parser = command.get_parser(command_name)
|
||||||
description = command.get_description()
|
description = command.get_description()
|
||||||
|
epilog = command.get_epilog()
|
||||||
|
|
||||||
# Drop the automatically-added help action
|
# Drop the automatically-added help action
|
||||||
for action in parser._actions:
|
for action in parser._actions:
|
||||||
@ -216,6 +217,17 @@ class AutoprogramCliffDirective(rst.Directive):
|
|||||||
|
|
||||||
self.state.nested_parse(result, 0, section)
|
self.state.nested_parse(result, 0, section)
|
||||||
|
|
||||||
|
# Epilog
|
||||||
|
|
||||||
|
# Like description, this is parsed as reStructuredText
|
||||||
|
|
||||||
|
if epilog:
|
||||||
|
result.append('', source_name)
|
||||||
|
|
||||||
|
for line in statemachine.string2lines(
|
||||||
|
epilog, tab_width=4, convert_whitespace=True):
|
||||||
|
result.append(line, source_name)
|
||||||
|
|
||||||
return [section]
|
return [section]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user