From 164f8c5a608743a44495770771935bf509c5cca5 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 29 Sep 2025 11:30:23 +0200 Subject: [PATCH] fix: support numeric string --- src/rougail/output_formatter/__init__.py | 12 +++++++++++- tests/results/00_6string/rougail/00-base.yml | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rougail/output_formatter/__init__.py b/src/rougail/output_formatter/__init__.py index fd1e71f..8a286d5 100644 --- a/src/rougail/output_formatter/__init__.py +++ b/src/rougail/output_formatter/__init__.py @@ -1,7 +1,7 @@ """ Silique (https://www.silique.fr) Copyright (C) 2024-2025 - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your @@ -119,6 +119,7 @@ class RougailOutputFormatter: self.attributes = {} self.yaml = YAML() + self.conv_yaml = YAML() def run(self): self.upgrade() @@ -391,6 +392,15 @@ class RougailOutputFormatter: else: ret[name] = default add_column += len(str(default)) + 1 + if isinstance(default, str): + # some entries have ' (like '8080') those characters are not count, so add it + with BytesIO() as ymlfh: + self.conv_yaml.dump(default, ymlfh) + ret2 = ymlfh.getvalue().decode("utf-8").strip() + if ret2.endswith("..."): + ret2 = ret2[:-3].strip() + if default != ret2: + add_column += len(ret2) - len(default) if "description" in variable: description = variable["description"].strip() if self.remaining and (not multi or not default): diff --git a/tests/results/00_6string/rougail/00-base.yml b/tests/results/00_6string/rougail/00-base.yml index 19ba92a..8edb192 100644 --- a/tests/results/00_6string/rougail/00-base.yml +++ b/tests/results/00_6string/rougail/00-base.yml @@ -13,4 +13,8 @@ var4: value # the forth variable var5: value # the fifth variable var6: value # the sixth variable + +var7: '8080' # the seventh variable + +var8: 'true' # the height variable ...