From 7c69ac9557f66e448e64a21a9af47e9b7a11375e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 29 Oct 2024 12:02:27 +0100 Subject: [PATCH] fix: README --- README.md | 37 +++++++++++++++++++------------------ src/rougail/config.py | 8 +++----- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4ef033f3f..debc1d8ae 100644 --- a/README.md +++ b/README.md @@ -28,20 +28,27 @@ Create the file `dict/dictionary.yml`: ```yml --- -version: '1.0' +version: 1.1 # describe a variable my_first_variable # and a family with a variable my_second_variable -my_first_variable: - default: my_value +my_first_variable: my_value my_family: - my_second_variable: - type: number - mandatory: true - value: 1 + my_second_variable: 1 ``` ## Generate variable +### With commandline: + +```bash +# rougail -m dict +Variables: +┣━━ 📓 my_first_variable: my_value +┗━━ 📂 my_family + ┗━━ 📓 my_second_variable: 1 + +``` + ### With default value: Here is a python3 example file: @@ -51,19 +58,16 @@ from rougail import Rougail, RougailConfig from pprint import pprint RougailConfig['dictionaries_dir'] = ['dict'] -RougailConfig['templates_dir'] = ['tmpl'] -RougailConfig['tmp_dir'] = 'tmp' -RougailConfig['destinations_dir'] = 'dest' rougail = Rougail() -config = rougail.get_config() +config = rougail.run() pprint(config.value.get(), sort_dicts=False) ``` The result is: ```json -{'rougail.my_first_variable': 'my_value', - 'rougail.my_family.my_second_variable': 1} +{: {: 'my_value', + : {: 1}}} ``` ### With modified value @@ -76,9 +80,6 @@ from rougail import Rougail, RougailConfig from pprint import pprint RougailConfig['dictionaries_dir'] = ['dict'] -RougailConfig['templates_dir'] = ['tmpl'] -RougailConfig['tmp_dir'] = 'tmp' -RougailConfig['destinations_dir'] = 'dest' rougail = Rougail() config = rougail.get_config() config.option('rougail.my_first_variable').value.set('modified_value') @@ -89,8 +90,8 @@ pprint(config.value.get(), sort_dicts=False) The destination file is generated with new values: ```json -{'rougail.my_first_variable': 'modified_value', - 'rougail.my_family.my_second_variable': 2} +{: {: 'modified_value', + : {: 2}}} ``` # Link diff --git a/src/rougail/config.py b/src/rougail/config.py index 4afec122e..b053048cd 100644 --- a/src/rougail/config.py +++ b/src/rougail/config.py @@ -406,7 +406,7 @@ suffix: disabled: variable: upgrade""" for process in processes: - if processes[process]: + if processes[process] or process == 'output': objects = processes[process] rougail_process += """ {NAME}: @@ -438,10 +438,8 @@ suffix: rougail_process += """ {% if _.output == 'NAME' %} Cannot load user data for NAME output {% endif %} -""".replace( - "NAME", hidden_output - ) - else: +""".replace("NAME", hidden_output) + elif objects: rougail_process += " default: {DEFAULT}".format( DEFAULT=objects[0]["name"] )