Repository: bridgecrewio/checkov
Pull request: feat(general): add flag for summary position
**By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.**

[//]: # "
    # PR Title
    Be aware that we use the title to create changelog automatically and therefore only allow specific prefixes
    - break:    to indicate a breaking change, this supersedes any of the types
    - feat:     to indicate new features or checks
    - fix:      to indicate a bugfix or handling of edge cases of existing checks
    - docs:     to indicate an update to our documentation
    - chore:    to indicate adjustments to workflow files or dependency updates
    - platform: to indicate a change needed for the platform
    Additionally a scope is needs to be added to the prefix, which indicates the targeted framework, in doubt choose 'general'.
    ex.
    feat(terraform): add CKV_AWS_123 to ensure that VPC Endpoint Service is configured for Manual Acceptance
"

## Description

Fixes https://github.com/bridgecrewio/checkov/issues/3222

### Description
Added a flag to enable changing the summary position within the report. Default behavior didn't change - summary at the top. adding the flag --summary-position-bottom will move it to the bottom.

## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my feature, policy, or fix is effective and works
- [x] New and existing tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules


Problem statement:
Move CLI output summary to the bottom of the output
**Describe the issue**
If you have more than a few failed checks, it can be difficult to scroll to the top to see the summary or in a terminal, it may even be cut off. Can we move the summary to the bottom after the policy violations?

Hints from issue discussion:
Sensational! I love this. 
The relevant part of our code that needs to be refactored:
https://github.com/bridgecrewio/checkov/blob/5fdaf23e404b247f686ce6e07ec8f98032380a2d/checkov/common/output/report.py#L245
Would appreciate a contribution here!
Needs to be a flag, default for bottom, as if you run it in ci you dont want to be scrolling!

Commit message: rerun failed test

Patch to review:
diff --git a/checkov/common/output/report.py b/checkov/common/output/report.py
index ac9870d67b..b9b1e6fd4d 100644
--- a/checkov/common/output/report.py
+++ b/checkov/common/output/report.py
@@ -178,6 +178,7 @@ def print_console(
         created_baseline_path: str | None = None,
         baseline: Baseline | None = None,
         use_bc_ids: bool = False,
+        summary_position_bottom: bool = False
     ) -> str:
         summary = self.get_summary()
         output_data = colored(f"{self.check_type} scan results:\n", "blue")
@@ -193,7 +194,8 @@ def print_console(
                 message = f"\nFailed checks: {summary['failed']}, Skipped checks: {summary['skipped']}\n\n"
             else:
                 message = f"\nPassed checks: {summary['passed']}, Failed checks: {summary['failed']}, Skipped checks: {summary['skipped']}\n\n"
-        output_data += colored(message, "cyan")
+        if not summary_position_bottom:
+            output_data += colored(message, "cyan")
         # output for vulnerabilities is different
         if self.check_type in (CheckType.SCA_PACKAGE, CheckType.SCA_IMAGE):
             if self.failed_checks or self.skipped_checks:
@@ -222,6 +224,8 @@ def print_console(
                 f"Baseline analysis report using {baseline.path} - only new failed checks with respect to the baseline are reported",
                 "blue",
             )
+        if summary_position_bottom:
+            output_data += colored(message, "cyan")
         return output_data
 
     @staticmethod
diff --git a/checkov/common/runners/runner_registry.py b/checkov/common/runners/runner_registry.py
index a4ac0298e4..a093ac8d39 100644
--- a/checkov/common/runners/runner_registry.py
+++ b/checkov/common/runners/runner_registry.py
@@ -249,6 +249,7 @@ def print_reports(
                     created_baseline_path=created_baseline_path,
                     baseline=baseline,
                     use_bc_ids=config.output_bc_ids,
+                    summary_position_bottom=config.summary_position_bottom
                 )
             print(cli_output)
             # Remove colors from the cli output
@@ -269,6 +270,7 @@ def print_reports(
                     created_baseline_path=created_baseline_path,
                     baseline=baseline,
                     use_bc_ids=config.output_bc_ids,
+                    summary_position_bottom=config.summary_position_bottom
                 ))
                 master_report.failed_checks += report.failed_checks
                 master_report.skipped_checks += report.skipped_checks
diff --git a/checkov/main.py b/checkov/main.py
index 97b945a22d..18b1446835 100755
--- a/checkov/main.py
+++ b/checkov/main.py
@@ -574,6 +574,8 @@ def add_parser_args(parser: ArgumentParser) -> None:
                env_var='CKV_SECRETS_SCAN_BLACK_LIST',
                action='append',
                help='black file list to filter out from the secret scanner')
+    parser.add('--summary-position-bottom', action='store_true',
+               help='Change the summary to be appended in the bottom after the policy violations')
 
 
 def get_external_checks_dir(config: Any) -> Any:


Code review comments:
diff_hunk: @@ -574,6 +574,8 @@ def add_parser_args(parser: ArgumentParser) -> None:
                env_var='CKV_SECRETS_SCAN_BLACK_LIST',
                action='append',
                help='black file list to filter out from the secret scanner')
+    parser.add('--summary-position-bottom', action='store_true',
path: checkov/main.py
text: @user1:
```suggestion
    parser.add('--summary-position', choices=["top", "bottom"],
```
we could change it to allow two different choices top or bottom and then set the default to top or bottom. of course define them as constants and then they can be evaluated before printing to console.