From e71611f17a05d4c5b3ccf350b65aaaba4e474f88 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 12 Dec 2022 11:16:27 +0100 Subject: [PATCH] Add -A/--append parameter to append generated changelog lines to existing file instead of overwriting it --- gitdch | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gitdch b/gitdch index 6abc256..ad30202 100755 --- a/gitdch +++ b/gitdch @@ -69,6 +69,18 @@ parser.add_argument( help='Generated Debian changelog output path (default: stdout)', ) +parser.add_argument( + '-A', + '--append', + action='store_true', + dest='append', + help=( + 'Append mode: if the output changelog file already exists, append ' + 'generated changelog lines at the begining of the file (optional, ' + 'default: overwriting the file)' + ) +) + parser.add_argument( '-n', '--package-name', @@ -266,6 +278,10 @@ for version in versions: if options.output: log.info('Write generated Debian changelog in file %s', options.output) + if options.append and os.path.exists(options.output): + with open(options.output, 'r', encoding='utf8') as fd: + changelog_lines += [""] + changelog_lines += fd.readlines() with open(options.output, 'w', encoding='utf8') as fd: fd.writelines(changelog_lines) else: