186 lines
3.7 KiB
Markdown
186 lines
3.7 KiB
Markdown
# Les variables à choix
|
|
|
|
## Une variable à choix
|
|
|
|
Il est possible d'imposer une liste de valeur pour une variable particulière :
|
|
|
|
```xml
|
|
<variable name="my_variable" type="choice">
|
|
<choice>val1</choice>
|
|
<choice>val2</choice>
|
|
<choice>val3</choice>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
type: choice
|
|
choice:
|
|
- text: val1
|
|
- text: val2
|
|
- text: val3
|
|
```
|
|
|
|
Dans ce cas, seules les valeurs proposées sont possibles pour cette variable.
|
|
Cette variable n'est pas obligatoire dont il est possible de mettre la valeur "None".
|
|
|
|
Si la variable est obligatoire ou si une valeur est précisée (la variable passe obligatoire) alors la valeur "None" n'est plus autorisé :
|
|
|
|
```xml
|
|
<variable name="my_variable" type="choice">
|
|
<choice>val1</choice>
|
|
<choice>val2</choice>
|
|
<choice>val3</choice>
|
|
<value>val1</value>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
type: choice
|
|
choice:
|
|
- text: val1
|
|
- text: val2
|
|
- text: val3
|
|
value:
|
|
- text: val1
|
|
```
|
|
|
|
## Un variable à choix typée
|
|
|
|
Par défaut les choix sont de type "string". Il est possible de préciser des nombres, des booléens ou la valeur None :
|
|
|
|
```xml
|
|
<variable name="my_variable" type="choice">
|
|
<choice>val1</choice>
|
|
<choice type="string">val2</choice>
|
|
<choice type="number">3</choice>
|
|
<choice type="boolean">True</choice>
|
|
<choice type="nil"/>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
type: choice
|
|
choice:
|
|
- text: val1
|
|
- type: string
|
|
text: val2
|
|
- type: number
|
|
text: 3
|
|
- type: boolean
|
|
text: true
|
|
- type: 'nil'
|
|
```
|
|
|
|
Comme vu précédement ajouter la valeur None n'est pas utile parce qu'elle est automatiquement ajouté si la variable n'est pas obligatoire.
|
|
|
|
## Ajouter une option à une variable à choix existante
|
|
|
|
Pour ajouter un choix à une variable à choix existante, rien de plus simple, juste redéfinir la variable en ajoutant le choix voulu :
|
|
|
|
```xml
|
|
<variable name="my_variable" redefine="True">
|
|
<choice>val4</choice>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
redefine: true
|
|
choice:
|
|
- text: val4
|
|
```
|
|
|
|
## Redéfinir une option à choix
|
|
|
|
Si on veut supprimer un choix ou redéfinir complètement la liste, il faut redéfinir cette variable et ajouter l'attribut "remove_choice" à "True" :
|
|
|
|
```xml
|
|
<variable name="my_variable" redefine="True" remove_choice="True">
|
|
<choice>val1</choice>
|
|
<choice>val2</choice>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
redefine: true
|
|
remove_choice: true
|
|
choice:
|
|
- text: val1
|
|
- text: val2
|
|
```
|
|
|
|
Dans ce cas toutes les anciens choix ne seront plus possible. Seuls les nouveaux le seront.
|
|
|
|
## Un variable à choix provenant d'une variable
|
|
|
|
Une variable à valeur multiple peut servir de source des choix :
|
|
|
|
```xml
|
|
<variable name="my_variable" type="choice">
|
|
<choice type="variable">other_variable</choice>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
type: choice
|
|
choice:
|
|
- type: variable
|
|
text: other_variable
|
|
```
|
|
|
|
Dans ce cas, toutes les valeurs de la variable seront des choix utilisables par l'utilisateur.
|
|
Seul un choice de type "variable" est possible par variable.
|
|
|
|
## Un variable à choix provenant d'une fonction
|
|
|
|
```xml
|
|
<variable name="my_variable" type="choice">
|
|
<choice type="function" name="range">
|
|
<param type="number">0</param>
|
|
<param type="number">10</param>
|
|
</choice>
|
|
<value type="number">9</value>
|
|
</variable>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
- variable:
|
|
name: my_variable
|
|
type: choice
|
|
choice:
|
|
- type: function
|
|
name: range
|
|
param:
|
|
- type: number
|
|
text: 0
|
|
- type: number
|
|
text: 10
|
|
value:
|
|
- type: number
|
|
text: 9
|
|
```
|