Auto save value
Objectives
A default value is a value that can be recalculated at different times. It can be useful to consider the default value as a modified value.
Prerequisites
We assume that Rougail’s library is installed on your computer.
It is possible to retrieve the current state of the various Rougail files manipulated in this tutorial step by checking out the corresponding tag of the
rougail-tutorialsgit repository. Each tag corresponds to a stage of progress in the tutorial. Of course, you can also decide to copy/paste or download the tutorial files contents while following the tutorial steps.
If you want to follow this tutorial with the help of the corresponding rougail-tutorials git repository, this workshop page corresponds to the tag v1.1_210
git clone https://forge.cloud.silique.fr/stove/rougail-tutorials.git
git switch --detach v1.1_210
The Configuration is loaded into Tiramisu. In this case, the default values are cached upon the first access to the variable. However, sometimes this value will be recalculated. If the default value is random, this can cause problems. Indeed, the value can change over time.
The auto_save property allows you to say that the calculated value will be considered as modified (therefore not recalculated) on the first access to this variable.
Remember, we just performed a random calculation for the variable color:
color.%YAML 1.2
---
version: 1.1
proxies:
description: Proxy configuration
type: sequence
title:
description: Title or Description
mandatory: false
color:
description: Color
regexp: ^#(?:[0-9a-f]{3}){1,2}$
default:
jinja: >-
#{%- for i in range(6) -%}{{- '0123456789abcdef' | random -}}{%- endfor -%}
description: random color value
...
We just need to set the auto_save property to true on this variable:
color.%YAML 1.2
---
version: 1.1
proxies:
description: Proxy configuration
type: sequence
title:
description: Title or Description
mandatory: false
color:
description: Color
regexp: ^#(?:[0-9a-f]{3}){1,2}$
default:
jinja: >-
#{%- for i in range(6) -%}{{- '0123456789abcdef' | random -}}{%- endfor -%}
description: random color value
auto_save: true
...
Test this variable with this Rougail CLI:
We have this output:
╭──────── Caption ────────╮ │ Variable Default value │ │ Modified value │ ╰─────────────────────────╯ Variables: ┣━━ 📂 firefox (Firefox) ┃ ┣━━ 📓 proxy_mode (Configure Proxy Access to the Internet): No proxy ┃ ┗━━ 📂 dns_over_https (DNS over HTTPS) ┃ ┗━━ 📓 enable_dns_over_https (Enable DNS over HTTPS): false ┗━━ 📂 foxyproxy (FoxyProxy) ┗━━ 📂 proxies (Proxy configuration) ┗━━ 📂 title (Title or Description) ┣━━ 📓 title (Title or Description): My company ◀ loaded from the ┃ YAML file "config/02/config.yml" ┗━━ 📓 color (Color): #f3fc4d
As you can see, the value is the color of the modified variables.
Note
We do not save this value. It is therefore stored in memory. When the Rougail CLI closes, this value is forgotten. It will be recalculated if you run the command again.
Key points
We can auto save a variable.