fix: support numeric string

This commit is contained in:
egarette@silique.fr 2025-09-29 11:30:23 +02:00
parent 87b24e7367
commit 164f8c5a60
2 changed files with 15 additions and 1 deletions

View file

@ -1,7 +1,7 @@
""" """
Silique (https://www.silique.fr) Silique (https://www.silique.fr)
Copyright (C) 2024-2025 Copyright (C) 2024-2025
This program is free software: you can redistribute it and/or modify it 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 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 Free Software Foundation, either version 3 of the License, or (at your
@ -119,6 +119,7 @@ class RougailOutputFormatter:
self.attributes = {} self.attributes = {}
self.yaml = YAML() self.yaml = YAML()
self.conv_yaml = YAML()
def run(self): def run(self):
self.upgrade() self.upgrade()
@ -391,6 +392,15 @@ class RougailOutputFormatter:
else: else:
ret[name] = default ret[name] = default
add_column += len(str(default)) + 1 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: if "description" in variable:
description = variable["description"].strip() description = variable["description"].strip()
if self.remaining and (not multi or not default): if self.remaining and (not multi or not default):

View file

@ -13,4 +13,8 @@ var4: value # the forth variable
var5: value # the fifth variable var5: value # the fifth variable
var6: value # the sixth variable var6: value # the sixth variable
var7: '8080' # the seventh variable
var8: 'true' # the height variable
... ...