Add append_newline flag for #33686 (#36273)

This commit is contained in:
Joseph Hall 2016-09-14 09:04:58 -06:00 committed by Nicole Thomas
parent 6a76a3a7e0
commit 3dec622eb6

View File

@ -2024,6 +2024,7 @@ def blockreplace(path,
backup='.bak',
dry_run=False,
show_changes=True,
append_newline=False,
):
'''
.. versionadded:: 2014.1.0
@ -2078,6 +2079,10 @@ def blockreplace(path,
Output a unified diff of the old file and the new file. If ``False``,
return a boolean if any changes were made.
append_newline:
Append a newline to the content block. For more information see:
https://github.com/saltstack/salt/issues/33686
CLI Example:
.. code-block:: bash
@ -2167,6 +2172,9 @@ def blockreplace(path,
if prepend_if_not_found:
# add the markers and content at the beginning of file
new_file.insert(0, marker_end + '\n')
if append_newline is True:
new_file.insert(0, content + '\n')
else:
new_file.insert(0, content)
new_file.insert(0, marker_start + '\n')
done = True
@ -2177,6 +2185,9 @@ def blockreplace(path,
new_file[-1] += '\n'
# add the markers and content at the end of file
new_file.append(marker_start + '\n')
if append_newline is True:
new_file.append(content + '\n')
else:
new_file.append(content)
new_file.append(marker_end + '\n')
done = True