feat: undocumented_modes is now a variable

This commit is contained in:
egarette@silique.fr 2025-11-21 08:08:17 +01:00
parent c064f6519d
commit a2f5749d12
3 changed files with 50 additions and 26 deletions

View file

@ -35,8 +35,8 @@ from .__version__ import __version__
class RougailOutputConsole:
variable_hidden_color = "orange1"
variable_advanced_color = "bright_blue"
variable_advanced_and_modified_color = "red1"
variable_undocumented_color = "bright_blue"
variable_undocumented_and_modified_color = "red1"
value_unmodified_color = "gold1"
value_default_color = "green"
@ -54,7 +54,6 @@ class RougailOutputConsole:
) -> None:
if rougailconfig is None:
from rougail import RougailConfig
rougailconfig = RougailConfig
self.rougailconfig = rougailconfig
self.config = config
@ -64,10 +63,14 @@ class RougailOutputConsole:
self.is_mandatory = self.rougailconfig["console.mandatory"]
self.show_secrets = self.rougailconfig["console.show_secrets"]
self.key_is_description = self.rougailconfig["console.key_is_description"]
try:
self.undocumented_modes = set(self.rougailconfig["console.undocumented_modes"])
except Exception:
self.undocumented_modes = set()
self.variable_default_enable = False
self.variable_hidden_enable = False
self.variable_advanced_enable = False
self.variable_advanced_and_modified_enable = False
self.variable_undocumented_enable = False
self.variable_undocumented_and_modified_enable = False
self.value_modified_enable = False
self.value_unmodified_enable = False
self.value_default_enable = False
@ -139,7 +142,8 @@ class RougailOutputConsole:
if self.is_mandatory:
ori_properties = self.config.property.exportation()
self.config.property.read_write()
self.mandatory()
if not self.user_data_errors and not self.errors:
self.mandatory()
self.config.property.importation(ori_properties)
warnings = self.user_data_warnings + self.warnings
if warnings:
@ -218,10 +222,10 @@ class RougailOutputConsole:
caption_line = ""
if self.variable_default_enable:
caption_line += _("Variable") + "\n"
if self.variable_advanced_enable:
caption_line += f'[{self.variable_advanced_color}]{_("Undocumented variable")}[/{self.variable_advanced_color}]\n'
if self.variable_advanced_and_modified_enable:
caption_line += f'[{self.variable_advanced_and_modified_color}]{_("Undocumented but modified variable")}[/{self.variable_advanced_and_modified_color}]\n'
if self.variable_undocumented_enable:
caption_line += f'[{self.variable_undocumented_color}]{_("Undocumented variable")}[/{self.variable_undocumented_color}]\n'
if self.variable_undocumented_and_modified_enable:
caption_line += f'[{self.variable_undocumented_and_modified_color}]{_("Undocumented but modified variable")}[/{self.variable_undocumented_and_modified_color}]\n'
if self.variable_hidden_enable:
caption_line += f'[{self.variable_hidden_color}]{_("Unmodifiable variable")}[/{self.variable_hidden_color}]\n'
header_value = ""
@ -304,6 +308,7 @@ class RougailOutputConsole:
self,
yaml,
self.key_is_description,
self.undocumented_modes,
no_icon=True,
)
return self.output
@ -320,6 +325,7 @@ class OutputFamily:
root,
_yaml,
key_is_description,
undocumented_modes,
*,
is_leader: bool = False,
no_icon: bool = False,
@ -346,6 +352,7 @@ class OutputFamily:
self.root = root
self._yaml = _yaml
self.key_is_description = key_is_description
self.undocumented_modes = undocumented_modes
def add_family(
self,
@ -355,9 +362,9 @@ class OutputFamily:
if "hidden" in properties:
self.root.variable_hidden_enable = True
color = self.root.variable_hidden_color
elif "advanced" in properties:
self.root.variable_advanced_enable = True
color = self.root.variable_advanced_color
elif self.undocumented_modes & properties:
self.root.variable_undocumented_enable = True
color = self.root.variable_undocumented_color
else:
self.root.variable_default_enable = True
color = None
@ -379,6 +386,7 @@ class OutputFamily:
self.root,
self._yaml,
self.key_is_description,
self.undocumented_modes,
)
def add_variable(
@ -388,21 +396,23 @@ class OutputFamily:
properties = option.property.get()
color = None
variable_color = None
advanced = False
undocumented = self.undocumented_modes & properties
hidden = False
if "hidden" in properties:
self.root.variable_hidden_enable = True
variable_color = self.root.variable_hidden_color
elif "advanced" in properties:
# FIXME "advanced should be an properties example!
advanced = True
if undocumented:
self.root.variable_undocumented_enable = True
variable_color = self.root.variable_undocumented_color
else:
self.root.variable_hidden_enable = True
variable_color = self.root.variable_hidden_color
elif undocumented:
self.root.variable_undocumented_and_modified_enable = True
variable_color = self.root.variable_undocumented_and_modified_color
else:
self.root.variable_default_enable = True
values = []
collect_values = []
if not option.owner.isdefault():
if advanced:
self.root.variable_advanced_and_modified_enable = True
variable_color = self.root.variable_advanced_and_modified_color
self.root.value_modified_enable = True
follower_index = option.index()
if follower_index is not None:
@ -450,9 +460,6 @@ class OutputFamily:
else:
self.root.value_default_enable = True
color = self.root.value_default_color
if advanced:
self.root.variable_advanced_enable = True
variable_color = self.root.variable_advanced_color
index = option.index()
parent_option = subconfig.option(option.path(), index)
if is_root_metaconfig:

View file

@ -48,6 +48,23 @@ console:
{{% endif %}}
key_is_description: true # {_("In tree the key is the family or variable description inside of it's name")}
undocumented_modes:
description: {_('Variables with those modes are not documented')}
multi: true
mandatory: false
disabled:
jinja: |
{{% if not modes_level %}}
there is no mode
{{% endif %}}
description: {_('disabled when there is no mode available')}
validators:
- jinja: |
{{% if _.undocumented_modes not in modes_level %}}
this mode is not available
{{% endif %}}
description: {_('verify if disable modes already exists')}
"""
return {
"name": "console",

View file

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