From 7f20729c372f52dc6d7da816435f93e70c8a81a5 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Tue, 30 May 2023 14:07:30 +0200 Subject: [PATCH] fix: add stdout as fallback if no out file is defined (#248) --- dockerautotag/cli.py | 12 ++++++++---- dockerautotag/utils.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dockerautotag/cli.py b/dockerautotag/cli.py index cd25b0d..eb5d43f 100644 --- a/dockerautotag/cli.py +++ b/dockerautotag/cli.py @@ -3,6 +3,7 @@ import argparse import copy import os +import sys from collections import defaultdict import semantic_version @@ -118,12 +119,15 @@ class Autotag: v = self._tag_suffix(v, config["suffix"], config["suffix_strict"]) v = self._tag_extra(v, config["extra"]) - if config["file"]: - try: + try: + if config["file"]: with open(config["file"], "w") as f: f.write(",".join(v)) - except OSError as e: - self.logger.error(f"Unable to write file: {e!s}") + else: + sys.stdout.write(",".join(v)) + sys.stdout.write("\n") + except OSError as e: + self.logger.error(f"Unable to write file: {e!s}") def main(): diff --git a/dockerautotag/utils.py b/dockerautotag/utils.py index 983d6ca..0283ac4 100644 --- a/dockerautotag/utils.py +++ b/dockerautotag/utils.py @@ -22,7 +22,7 @@ def trim_prefix(text, prefix): def to_prerelease(tup): - return "".join(tup) + return ".".join(tup) class Singleton(type):