diff --git a/README.es.md b/README.es.md index 25b1205..475e751 100644 --- a/README.es.md +++ b/README.es.md @@ -1,4 +1,3 @@ - # 🚀 STRUCT: Generador Automático de Estructuras de Proyectos [![en](https://img.shields.io/badge/lang-en-red.svg)](https://github.com/httpdss/struct/blob/master/README.md) [![es](https://img.shields.io/badge/lang-es-yellow.svg)](https://github.com/httpdss/struct/blob/master/README.es.md) @@ -235,6 +234,22 @@ structure: slugify project_name: {{@ project_name | slugify @}} ``` +### Cláusula `with` + +La cláusula `with` te permite pasar variables adicionales a estructuras anidadas. Estas variables se fusionarán con las variables globales y se pueden usar dentro de la estructura anidada. + +Ejemplo: + +```yaml +folders: + - .devops/modules/mod1: + struct: terraform-module + - .devops/modules/mod2: + struct: terraform-module + with: + module_name: mymod2 +``` + ## 👩‍💻 Desarrollo Para comenzar con el desarrollo, sigue estos pasos: diff --git a/README.md b/README.md index 7ddfaa5..00e855a 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,22 @@ structure: slugify project_name: {{@ project_name | slugify @}} ``` +### `with` Clause + +The `with` clause allows you to pass additional variables to nested structures. These variables will be merged with the global variables and can be used within the nested structure. + +Example: + +```yaml +folders: + - .devops/modules/mod1: + struct: terraform-module + - .devops/modules/mod2: + struct: terraform-module + with: + module_name: mymod2 +``` + ## 👩‍💻 Development To get started with development, follow these steps: diff --git a/example/structure.yaml b/example/structure.yaml index f1ef33c..08f8388 100644 --- a/example/structure.yaml +++ b/example/structure.yaml @@ -27,6 +27,8 @@ folders: struct: terraform-module - .devops/modules/mod2: struct: terraform-module + with: + module_name: mymod2 - ./: struct: - docker-files diff --git a/struct_module/commands/generate.py b/struct_module/commands/generate.py index c3dbc05..7861429 100644 --- a/struct_module/commands/generate.py +++ b/struct_module/commands/generate.py @@ -101,14 +101,25 @@ def _create_structure(self, args): # check if content has struct value if 'struct' in content: self.logger.info(f"Generating structure in folder: {folder} with struct {content['struct']}") - if isinstance(content['struct'], str): + # get vars from with param. this will be a dict of key value pairs + merged_vars = "" + + # dict to comma separated string + if 'with' in content: + if isinstance(content['with'], dict): + merged_vars = ",".join([f"{k}={v}" for k, v in content['with'].items()]) + + if args.vars: + merged_vars = args.vars + "," + merged_vars + + if isinstance(content['struct'], str): self._create_structure({ 'structure_definition': content['struct'], 'base_path': folder_path, 'structures_path': args.structures_path, 'dry_run': args.dry_run, - 'vars': args.vars, + 'vars': merged_vars, 'backup': args.backup, 'file_strategy': args.file_strategy, 'global_system_prompt': args.global_system_prompt, @@ -121,7 +132,7 @@ def _create_structure(self, args): 'base_path': folder_path, 'structures_path': args.structures_path, 'dry_run': args.dry_run, - 'vars': args.vars, + 'vars': merged_vars, 'backup': args.backup, 'file_strategy': args.file_strategy, 'global_system_prompt': args.global_system_prompt,