feat: tags
This commit is contained in:
parent
360c97c581
commit
4bb50361d5
5 changed files with 152 additions and 1 deletions
|
|
@ -62,6 +62,7 @@ Explained differently, Rougail allows you to easily implement an integration of
|
|||
|
||||
variable
|
||||
family
|
||||
tags
|
||||
fill
|
||||
Value checks <check>
|
||||
condition
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ The Rougail CLI can output a rather complete view of the dataset:
|
|||
:caption: Use library
|
||||
|
||||
parse
|
||||
tags
|
||||
rougailconfig_load_from_cli
|
||||
extra
|
||||
custom_function
|
||||
|
|
|
|||
111
docs/library/tags.rst
Normal file
111
docs/library/tags.rst
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
Use tag informations
|
||||
====================
|
||||
|
||||
When we set tags for a variable, it will add :term:`Tiramisu` properties and informations.
|
||||
|
||||
We can filter those variables easily with tags.
|
||||
|
||||
First of all, create our structural file:
|
||||
|
||||
.. code-block:: yaml
|
||||
:caption: the :file:`dist/00-base.yml` file content
|
||||
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
infra_name: my infra # Name of this infrastructure
|
||||
|
||||
server1: # the first server
|
||||
|
||||
internal_domain:
|
||||
description: Server domaine name
|
||||
type: domainname
|
||||
tags:
|
||||
- internal
|
||||
|
||||
external_domain:
|
||||
description: Domain name to access to this server for Internet
|
||||
type: domainname
|
||||
tags:
|
||||
- external
|
||||
|
||||
server2: # the second server
|
||||
|
||||
address:
|
||||
description: Server domaine name
|
||||
type: domainname
|
||||
tags:
|
||||
- internal
|
||||
...
|
||||
|
||||
Exclude variables with a specific tag
|
||||
-------------------------------------
|
||||
|
||||
To exclude variables with a specific tag is very easy. When the variable has tags, properties with same name are automaticly create.
|
||||
So exclude a tag means exclude variable with a particular property.
|
||||
|
||||
In this example we exclude variable with "internal" tag and display result of "server1" family:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: the :file:`script.py` file content
|
||||
|
||||
from rougail import Rougail, RougailConfig
|
||||
from pprint import pprint
|
||||
|
||||
RougailConfig['main_namespace'] = None
|
||||
RougailConfig['main_structural_directories'] = ['dist']
|
||||
rougail = Rougail()
|
||||
config = rougail.run()
|
||||
print("without filter:")
|
||||
pprint(config.option("server1").value.get())
|
||||
config.property.add('internal')
|
||||
print("with filter:")
|
||||
pprint(config.option("server1").value.get())
|
||||
|
||||
Let's execute `script.py`:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ python3 script.py
|
||||
without filter:
|
||||
{<TiramisuOption path="server1.external_domain">: None,
|
||||
<TiramisuOption path="server1.internal_domain">: None}
|
||||
with filter:
|
||||
{<TiramisuOption path="server1.external_domain">: None}
|
||||
|
||||
Only variable with a specific tag
|
||||
---------------------------------
|
||||
|
||||
It's more difficult to see only variable with a specific tag.
|
||||
|
||||
We have to walk through the configuration and retrieve variable with the selected tag.
|
||||
Tags are in properties but, are in information too.
|
||||
|
||||
Here is a smal script that walk that the configuration and "print" option with "internal" tag:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: the :file:`script.py` file content
|
||||
|
||||
from rougail import Rougail, RougailConfig
|
||||
|
||||
RougailConfig['main_structural_directories'] = ['dist']
|
||||
rougail = Rougail()
|
||||
config = rougail.run()
|
||||
|
||||
def walk(config):
|
||||
for option in config:
|
||||
if option.isoptiondescription():
|
||||
walk(option)
|
||||
elif "internal" in option.information.get('tags', []):
|
||||
print(option.description())
|
||||
|
||||
if __name__ == '__main__':
|
||||
walk(config)
|
||||
|
||||
Let's execute `script.py`:
|
||||
|
||||
.. code-block:: bash
|
||||
$ python3 script.py
|
||||
server1.internal_domain (Server domaine name)
|
||||
server2.address (Server domaine name)
|
||||
34
docs/tags.rst
Normal file
34
docs/tags.rst
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
The variable tags
|
||||
==================
|
||||
|
||||
A tag allows you to specialize a variable.
|
||||
|
||||
A tag can have several functions:
|
||||
|
||||
- Additional information in the documentation
|
||||
- Variable exclusion
|
||||
- Variable selection
|
||||
- ...
|
||||
|
||||
Tags are only available for variable.
|
||||
|
||||
Here is an example:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
internal_domain:
|
||||
description: Server domaine name
|
||||
type: domainname
|
||||
tags:
|
||||
- internal
|
||||
|
||||
external_domain:
|
||||
description: Domain name to access to this server for Internet
|
||||
type: domainname
|
||||
tags:
|
||||
- external
|
||||
...
|
||||
|
|
@ -52,12 +52,16 @@ If you add a comment in the same line of the name, this comment will be used has
|
|||
|
||||
.. code-block:: yaml
|
||||
|
||||
%YAML 1.2
|
||||
---
|
||||
version: '1.1'
|
||||
version: 1.1
|
||||
|
||||
my_variable: 1 # This is a great integer variable
|
||||
|
||||
my_multi_variable: # This is a great multi string variable
|
||||
- value1
|
||||
- value2
|
||||
...
|
||||
|
||||
Parameters
|
||||
-------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue