Skip to content

Commit 1cc6007

Browse files
authored
Add skip property to file_item.py to support conditional file creation (#20)
### Overview This PR introduces a `skip` property to the `file_item.py` module, enabling the option to bypass file creation based on conditional settings. ### Changes - **Added `skip` property**: The constructor now initializes the `skip` property based on input properties, defaulting to `False` if not specified. - **Conditional file creation**: Modified the `create` method to check the `skip` property. When set to `True`, the process logs that file creation is skipped and exits early. ### Justification The ability to conditionally skip file creation is essential for workflows that require selective file management. This update allows greater control over file generation without altering existing logic. ### Impact This enhancement reduces unnecessary file creation, optimizing resource use, especially in large projects or in cases where specific files are conditionally excluded. No breaking changes are introduced, ensuring compatibility with existing workflows.
1 parent 8579e59 commit 1cc6007

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

example/structure.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
structure:
22
- README.md:
3+
skip: true
34
content: |
45
# {{@ project_name @}}
56
This is a template repository.

struct_module/commands/validate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _validate_folders_config(self, folders):
4646
raise ValueError(f"The content of '{name}' must be a dictionary.")
4747
if 'struct' not in content:
4848
raise ValueError(f"Dictionary item '{name}' must contain a 'struct' key.")
49-
if not isinstance(content['struct'], str):
49+
if not isinstance(content['struct'], str) and not isinstance(content['struct'], list):
5050
raise ValueError(f"The 'struct' value for '{name}' must be a string.")
5151

5252

@@ -104,7 +104,8 @@ def _validate_structure_config(self, structure):
104104
# Check if 'prompt' key is present and its value is a string
105105
if 'prompt' in content and not isinstance(content['prompt'], str):
106106
raise ValueError(f"The 'prompt' value for '{name}' must be a string.")
107-
# Check if 'prompt' key is present but no OpenAI API key is found
107+
if 'skip' in content and not isinstance(content['skip'], bool):
108+
raise ValueError(f"The 'skip' value for '{name}' must be a string.")
108109
elif not isinstance(content, str):
109110
raise ValueError(f"The content of '{name}' must be a string or dictionary.")
110111
self.logger.info("Configuration validation passed.")

struct_module/file_item.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, properties):
2323
self.content_location = properties.get("file")
2424
self.permissions = properties.get("permissions")
2525
self.input_store = properties.get("input_store")
26+
self.skip = properties.get("skip", False)
2627

2728
self.system_prompt = properties.get("system_prompt") or properties.get("global_system_prompt")
2829
self.user_prompt = properties.get("user_prompt")
@@ -118,6 +119,11 @@ def apply_template_variables(self, template_vars):
118119

119120
def create(self, base_path, dry_run=False, backup_path=None, file_strategy='overwrite'):
120121
file_path = os.path.join(base_path, self.name)
122+
123+
if self.skip:
124+
self.logger.info(f"Skipping file creation: {file_path}")
125+
return
126+
121127
if dry_run:
122128
self.logger.info(f"[DRY RUN] Would create file: {file_path} with content: \n\n{self.content}")
123129
return

0 commit comments

Comments
 (0)