ansible-doc: avoid problems with YAML anchors when formatting man page (#70045)

* Avoid problems with YAML anchors when formatting man page.

* Add changelog.
This commit is contained in:
Felix Fontein 2020-06-30 21:33:44 +02:00 committed by GitHub
parent 74bedab8a9
commit 5e4f708241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "ansible-doc - improve man page formatting to avoid problems when YAML anchors are used (https://github.com/ansible/ansible/pull/70045)."

View file

@ -513,7 +513,8 @@ class DocCLI(CLI):
def add_fields(text, fields, limit, opt_indent, return_values=False, base_indent=''): def add_fields(text, fields, limit, opt_indent, return_values=False, base_indent=''):
for o in sorted(fields): for o in sorted(fields):
opt = fields[o] # Create a copy so we don't modify the original (in case YAML anchors have been used)
opt = dict(fields[o])
required = opt.pop('required', False) required = opt.pop('required', False)
if not isinstance(required, bool): if not isinstance(required, bool):
@ -562,7 +563,8 @@ class DocCLI(CLI):
conf = {} conf = {}
for config in ('env', 'ini', 'yaml', 'vars', 'keywords'): for config in ('env', 'ini', 'yaml', 'vars', 'keywords'):
if config in opt and opt[config]: if config in opt and opt[config]:
conf[config] = opt.pop(config) # Create a copy so we don't modify the original (in case YAML anchors have been used)
conf[config] = [dict(item) for item in opt.pop(config)]
for ignore in DocCLI.IGNORE: for ignore in DocCLI.IGNORE:
for item in conf[config]: for item in conf[config]:
if ignore in item: if ignore in item:
@ -593,6 +595,8 @@ class DocCLI(CLI):
@staticmethod @staticmethod
def get_man_text(doc): def get_man_text(doc):
# Create a copy so we don't modify the original
doc = dict(doc)
DocCLI.IGNORE = DocCLI.IGNORE + (context.CLIARGS['type'],) DocCLI.IGNORE = DocCLI.IGNORE + (context.CLIARGS['type'],)
opt_indent = " " opt_indent = " "