diff --git a/.github/workflows/struct-on-gha.yaml b/.github/workflows/struct-on-gha.yaml index f94509c..72cea62 100644 --- a/.github/workflows/struct-on-gha.yaml +++ b/.github/workflows/struct-on-gha.yaml @@ -2,9 +2,6 @@ name: stuct-on-gha on: workflow_dispatch: - pull_request: - branches: - - main jobs: run: diff --git a/.github/workflows/test-script.yaml b/.github/workflows/test-script.yaml index 605a542..95e6e9e 100644 --- a/.github/workflows/test-script.yaml +++ b/.github/workflows/test-script.yaml @@ -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() diff --git a/struct_module/commands/generate.py b/struct_module/commands/generate.py index ca2431e..46a0d56 100644 --- a/struct_module/commands/generate.py +++ b/struct_module/commands/generate.py @@ -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 @@ -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) @@ -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: