You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Overview:**
This PR introduces several improvements to the template system and file
handling functionality of the project. It adds new features for working
with template variables, custom Jinja2 filters, and interactive input.
**Changes:**
- Updated both `README.md` and `README.es.md` to reflect the new
interactive and subcommand-based usage for the `struct` script.
- Enhanced support for template variables:
- Introduced the ability to prompt users interactively if template
variables are not provided.
- Added descriptions, types, and default values for template variables.
- New Jinja2 custom filter (`slugify`) introduced to convert strings
into slugs for better identifier handling.
- Replaced the `stringify` filter with the new `slugify` filter across
YAML configuration files, scripts, and tests.
- Updated example structure YAML files with enhanced variable
definitions.
- Added improvements to Kubernetes manifests and Terraform module
templates to use the `slugify` filter.
**Justification:**
These updates improve usability by allowing for interactive input of
template variables and enhancing string handling via the `slugify`
filter. The improvements make the system more flexible and adaptable to
various use cases, while the documentation updates ensure clarity for
users.
**Impact:**
- Increased ease of use with interactive prompts for variables.
- Improved readability and maintainability of file templates through
`slugify`.
- Updated documentation for users to follow the latest features and
options.
Copy file name to clipboardExpand all lines: README.es.md
+58-16Lines changed: 58 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ Está dirigido a desarrolladores, ingenieros DevOps y cualquier persona que quie
35
35
## ✨ Características
36
36
37
37
-**Configuración YAML**: Define la estructura de tu proyecto en un simple archivo YAML.
38
-
-**Variables de Plantilla**: Usa marcadores de posición en tu configuración y reemplázalos con valores reales en tiempo de ejecución.
38
+
-**Variables de Plantilla**: Usa marcadores de posición en tu configuración y reemplázalos con valores reales en tiempo de ejecución. También admite filtros personalizados de Jinja2 y modo interactivo para completar las variables.
39
39
-**Permisos de Archivos Personalizados**: Establece permisos personalizados para tus archivos directamente desde la configuración YAML.
40
40
-**Obtención de Contenido Remoto**: Incluye contenido de archivos remotos especificando sus URLs.
41
41
-**Estrategias de Manejo de Archivos**: Elige entre múltiples estrategias (sobrescribir, omitir, añadir, renombrar, respaldar) para gestionar archivos existentes.
@@ -99,34 +99,38 @@ struct structure.yaml .
99
99
100
100
## 📝 Uso
101
101
102
-
Ejecuta el script con el siguiente comando:
102
+
Ejecuta el script con el siguiente comando usando uno de los siguientes subcomandos:
103
+
104
+
-`generate`: Genera la estructura del proyecto basada en la configuración YAML.
105
+
-`validate`: Valida la configuración YAML para asegurarte de que sea válida.
106
+
-`info`: Muestra información sobre el script y sus dependencias.
107
+
-`list`: Lista las estructuras disponibles.
108
+
109
+
Para más información, ejecuta el script con la opción `-h` o `--help` (esto también está disponible para cada subcomando):
-`--log`: Establece el nivel de registro (DEBUG, INFO, WARNING, ERROR, CRITICAL). El valor predeterminado es INFO.
112
-
-`--dry-run`: Realiza una ejecución en seco sin crear archivos o directorios.
113
-
-`--vars`: Variables de plantilla en el formato `CLAVE1=valor1,CLAVE2=valor2`.
114
-
-`--backup`: Ruta a la carpeta de respaldo.
115
-
-`--file-strategy`: Estrategia para manejar archivos existentes (sobrescribir, omitir, añadir, renombrar, respaldar). El valor predeterminado es sobrescribir.
Puedes usar variables de plantilla en tu archivo de configuración encerrándolas entre `{{@` y `@}}`. Por ejemplo, `{{@ project_name @}}` será reemplazado con el valor de la variable `project_name` en tiempo de ejecución.
169
+
Puedes usar variables de plantilla en tu archivo de configuración encerrándolas entre `{{@` y `@}}`. Por ejemplo, `{{@ project_name @}}` será reemplazado con el valor de la variable `project_name` en tiempo de ejecución. Si las variables no se proporcionan en la línea de comandos, se solicitarán interactivamente.
157
170
158
171
Si necesitas definir bloques, puedes usar la notación de inicio de bloque `{%@` y la notación de final de bloque `%@}`.
159
172
@@ -164,6 +177,22 @@ Para definir comentarios, puedes usar la notación de inicio de comentario `{#@`
164
177
- `file_name`: El nombre del archivo que se está procesando.
165
178
- `file_directory`: El nombre del directorio del archivo que se está procesando.
166
179
180
+
#### Variables de plantilla interactivo
181
+
182
+
Si no proporcionas todas las variables en la línea de comandos, se solicitarán interactivamente.
183
+
184
+
La struct definida debe incluir las variables en una seccion de `variables` con la siguiente estructura:
185
+
186
+
```yaml
187
+
variables:
188
+
- variable_name:
189
+
description: "Descripción de la variable"
190
+
type: string
191
+
default: "Valor predeterminado"
192
+
```
193
+
194
+
como puedes ver, cada variable debe tener una descripción, un tipo y un valor predeterminado (opcional). Este valor predeterminado se usará si no se proporciona la variable en la línea de comandos.
195
+
167
196
#### Filtros personalizados de Jinja2
168
197
169
198
##### `latest_release`
@@ -184,6 +213,19 @@ Si ocurre un error en el proceso, el filtro devolverá `LATEST_RELEASE_ERROR`.
184
213
185
214
NOTA: puedes usar este filtro para obtener la última versión de un proveedor de Terraform. Por ejemplo, para obtener la última versión del proveedor `aws`, puedes usar `{{@ "hashicorp/terraform-provider-aws" | latest_release @}}` o el proveedor de datadog `{{@ "DataDog/terraform-provider-datadog" | latest_release @}}`.
186
215
216
+
##### `slugify`
217
+
218
+
Este filtro convierte una cadena en un slug. Toma un argumento opcional para especificar el carácter separador (el valor predeterminado es `-`).
Copy file name to clipboardExpand all lines: README.md
+52-18Lines changed: 52 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ This is targeted towards developers, DevOps engineers, and anyone who wants to a
34
34
## ✨ Features
35
35
36
36
-**YAML Configuration**: Define your project structure in a simple YAML file.
37
-
-**Template Variables**: Use placeholders in your configuration and replace them with actual values at runtime.
37
+
-**Template Variables**: Use placeholders in your configuration and replace them with actual values at runtime. Also supports custom Jinja2 filters and interactive mode to fill in the variables.
38
38
-**Custom File Permissions**: Set custom permissions for your files directly from the YAML configuration.
39
39
-**Remote Content Fetching**: Include content from remote files by specifying their URLs.
40
40
-**File Handling Strategies**: Choose from multiple strategies (overwrite, skip, append, rename, backup) to manage existing files.
You can use template variables in your configuration file by enclosing them in `{{@` and `@}}`. For example, `{{@ project_name @}}` will be replaced with the value of the `project_name` variable at runtime.
166
+
You can use template variables in your configuration file by enclosing them in `{{@` and `@}}`. For example, `{{@ project_name @}}` will be replaced with the value of the `project_name` variable at runtime. If this are not set when running the script, it will prompt you to enter the value interactively.
162
167
163
168
If you need to define blocks you can use starting block notation `{%@` and end block notation `%@}`.
164
169
@@ -169,6 +174,22 @@ To define comments you can use the comment start notation `{#@` and end comment
169
174
- `file_name`: The name of the file being processed.
170
175
- `file_directory`: The name of the directory of file that is being processed.
171
176
177
+
#### Interactive template variables
178
+
179
+
If you don't provide a default value for a variable, the script will prompt you to enter the value interactively.
180
+
181
+
The struct defined should define the variable on a specific section of the YAML file. For example:
182
+
183
+
```yaml
184
+
variables:
185
+
- author_name:
186
+
description: "The name of the author"
187
+
type: string
188
+
default: "John Doe"
189
+
```
190
+
191
+
as you can see, the `author_name` variable is defined on the `variables` section of the YAML file. it includes a `description`, `type` and `default` value which is used if the user doesn't provide a value interactively.
192
+
172
193
#### Custom Jinja2 filters
173
194
174
195
##### `latest_release`
@@ -189,6 +210,19 @@ If there is an error in the process, the filter will return `LATEST_RELEASE_ERRO
189
210
190
211
NOTE: you can use this filter to get the latest release for a terraform provider. For example, to get the latest release of the `aws` provider, you can use `{{@ "hashicorp/terraform-provider-aws" | latest_release @}}` or datadog provider `{{@ "DataDog/terraform-provider-datadog" | latest_release @}}`.
191
212
213
+
##### `slugify`
214
+
215
+
This filter converts a string into a slug. It takes an optional argument to specify the separator character (default is `-`).
0 commit comments