Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/struct-on-gha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: stuct-on-gha

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
run:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test-script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ jobs:
shell: bash
run: |
echo "REPORT_FILE=${REPORT_OUTPUT}" >> "$GITHUB_ENV"
pytest -v --md-report --md-report-flavor gfm --md-report-exclude-outcomes passed skipped xpassed --md-report-output "$REPORT_OUTPUT" --pyargs tests
pytest --cov --cov-branch --cov-report=xml -v --md-report --md-report-flavor gfm --md-report-exclude-outcomes passed skipped xpassed --md-report-output "$REPORT_OUTPUT" --pyargs tests

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Output reports to the job summary when tests fail
if: failure()
Expand Down
32 changes: 19 additions & 13 deletions struct_module/commands/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self, parser):
parser.add_argument('--non-interactive', action='store_true', help='Run the command in non-interactive mode')
parser.add_argument('--mappings-file', type=str,
help='Path to a YAML file containing mappings to be used in templates')
parser.add_argument('-o', '--output', type=str,
choices=['console', 'file'], default='file', help='Output mode')
parser.set_defaults(func=self.execute)

def _run_hooks(self, hooks, hook_type="pre"): # helper for running hooks
Expand Down Expand Up @@ -85,7 +87,7 @@ def execute(self, args):
if args.backup and not os.path.exists(args.backup):
os.makedirs(args.backup)

if args.base_path and not os.path.exists(args.base_path):
if args.base_path and not os.path.exists(args.base_path) and "console" not in args.output:
self.logger.info(f"Creating base path: {args.base_path}")
os.makedirs(args.base_path)

Expand Down Expand Up @@ -165,22 +167,26 @@ def _create_structure(self, args, mappings=None):
)
file_item.apply_template_variables(template_vars)

file_item.create(
args.base_path,
args.dry_run or False,
args.backup or None,
args.file_strategy or 'overwrite'
)
# Output mode logic
if hasattr(args, 'output') and args.output == 'console':
# Print the file path and content to the console instead of creating the file
print(f"=== {file_path_to_create} ===")
print(file_item.content)
else:
file_item.create(
args.base_path,
args.dry_run or False,
args.backup or None,
args.file_strategy or 'overwrite'
)

for item in config_folders:
for folder, content in item.items():
folder_path = os.path.join(args.base_path, folder)
if args.dry_run:
self.logger.info(f"[DRY RUN] Would create folder: {folder_path}")
continue
os.makedirs(folder_path, exist_ok=True)
self.logger.info(f"Created folder")
self.logger.info(f" Folder: {folder_path}")
if hasattr(args, 'output') and args.output == 'file':
os.makedirs(folder_path, exist_ok=True)
self.logger.info(f"Created folder")
self.logger.info(f" Folder: {folder_path}")

# check if content has struct value
if 'struct' in content:
Expand Down
Loading