feat: support multi lines for help

This commit is contained in:
egarette@silique.fr 2025-03-30 19:39:29 +02:00
parent b2f2aa4406
commit 307c2933c5
5 changed files with 63 additions and 4 deletions

View file

@ -25,7 +25,7 @@ from ruamel.yaml import YAML, CommentedMap
from ruamel.yaml.tokens import CommentToken
from ruamel.yaml.error import CommentMark
from ruamel.yaml.comments import CommentedSeq
from ruamel.yaml.scalarstring import LiteralScalarString, FoldedScalarString
from ruamel.yaml.scalarstring import LiteralScalarString, FoldedScalarString, ScalarString
from djlint.settings import Config
from djlint.reformat import formatter
@ -285,12 +285,16 @@ class RougailOutputFormatter:
return _get_last_obj(o[param], o, param, 'seq')
return typ, parent, param
param = list(obj)[-1]
if isinstance(obj[param], ScalarString):
enter = '\n'
else:
enter = '\n\n'
typ, parent, param = _get_last_obj(obj[param], obj, param, 'map')
if typ == 'seq':
func = parent.yaml_key_comment_extend
else:
func = parent.yaml_value_comment_extend
func(param, [CommentToken('\n\n', CommentMark(0)), None])
func(param, [CommentToken(enter, CommentMark(0)), None])
def object_to_yaml(self, key, type_, value, multi, object_path):
if isinstance(value, list):
@ -307,7 +311,6 @@ class RougailOutputFormatter:
return new_values
if isinstance(value, JinjaCalculation):
jinja = CommentedMap()
# replace \n to space a add index of \n (now a space) to fold_pos
jinja_values = formatter(self.config, value.jinja.strip())[:-1]
if key == 'default' and not multi:
jinja["jinja"] = FoldedScalarString(jinja_values)
@ -370,6 +373,8 @@ class RougailOutputFormatter:
return {value.key: variable}
elif type_ == 'port' and isinstance(value, str) and value.isnumeric():
return int(value)
elif key == 'help' and '\n' in value:
return LiteralScalarString(value)
return value
def calc_variable_path(self, object_path, variable_path):

View file

@ -0,0 +1,18 @@
---
version: 1.1
secret1:
description: the first variable
type: secret
params:
min_len: 10
secret2:
description: the second variable
type: secret
params:
max_len: 10
forbidden_char:
- $
- ^
default: value

View file

@ -0,0 +1,18 @@
---
version: 1.1
var1:
description: the first variable
help: |-
Multi line
Help
With useful information
var2:
description: the second variable
help: |-
Multi line
Help
With useful information

View file

@ -0,0 +1,18 @@
---
version: 1.1
var1:
description: the first <variable>
help: |-
Multi line
<Help>
With useful information
var2:
description: the second <variable>
help: |-
Multi line
<Help>
With useful information

View file

@ -11,7 +11,7 @@ excludes = [
]
test_ok = get_structures_list(excludes)
# test_ok = [Path('../rougail-tests/structures/00_9default_calculation_param_optional')]
# test_ok = [Path('../rougail-tests/structures/00_7help')]
def idfn(fixture_value):