Skip to content

Commit 0a75b81

Browse files
author
Joris Conijn
authored
feat(cli): implement multiple sources (#18)
In #16 we implemented the logic to process multiple source reports. In this PR we add the ability to use it via the CLI. Issue: #8
1 parent e0e4c62 commit 0a75b81

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@ the following command(s):
3535
report2junit ./sample-reports/cfn-guard.json
3636

3737
# Or if you want to specify the destination:
38-
report2junit ./sample-reports/cfn-guard.json ./sample-reports/cfn-guard-other-destination.xml
38+
report2junit ./sample-reports/cfn-guard.json --destination-file ./sample-reports/cfn-guard-other-destination.xml
3939
```
4040

4141
Convert an output report from [cfn-nag](https://github.com/stelligent/cfn_nag) using
4242
the following command(s):
4343

4444
```bash
45-
report2juni ./sample-reports/cfn-nag.json
45+
report2junit ./sample-reports/cfn-nag.json
4646

4747
# Or if you want to specify the destination:
48-
report2junit ./sample-reports/cfn-nag.json ./sample-reports/cfn-nag-other-destination.xml
48+
report2junit ./sample-reports/cfn-nag.json --destination-file ./sample-reports/cfn-nag-other-destination.xml
49+
```
50+
51+
Combine both the [cloudformation-guard](https://github.com/aws-cloudformation/cloudformation-guard) and [cfn-nag](https://github.com/stelligent/cfn_nag)
52+
reports into a single output report.
53+
54+
```bash
55+
report2junit ./sample-reports/cfn-nag.json ./sample-reports/cfn-guard.json
56+
57+
# Or if you want to specify the destination:
58+
report2junit ./sample-reports/cfn-nag.json ./sample-reports/cfn-guard.json --destination-file ./sample-reports/junit-other.xml
4959
```

report2junit/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@
1414
type=click.Choice(["cfn-guard", "cfn-nag"], case_sensitive=False),
1515
required=False,
1616
)
17-
@click.argument("source-file")
18-
@click.argument("destination-file", required=False)
17+
@click.argument("source-files", nargs=-1)
18+
@click.option("--destination-file", required=False)
1919
def main(
20-
source_file: str, destination_file: Optional[str], source_type: Optional[str] = None
20+
source_files: str,
21+
destination_file: Optional[str],
22+
source_type: Optional[str] = None,
2123
):
2224
"""
2325
Convert2JUnit
2426
2527
This tool allows you to convert various reports into the JUnit format.
2628
"""
27-
source_file = os.path.abspath(source_file)
28-
2929
if not destination_file:
30-
destination_file = os.path.join(os.path.dirname(source_file), "junit.xml")
30+
destination_file = os.path.join(os.path.dirname(source_files[0]), "junit.xml")
3131

3232
report = JUnitOutput(destination_file)
3333

34-
if not report.apply(source_file):
35-
raise click.ClickException("Could not convert the report")
34+
for source_file in source_files:
35+
source_file = os.path.abspath(source_file)
36+
37+
if not report.apply(source_file):
38+
raise click.ClickException("Could not convert the report")
3639

3740
report.write()
3841

tests/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cfn-guard-skipped-only.json",
1616
],
1717
)
18-
def test_report_conversion(input_file: str, sample_reports_path: str) -> None:
18+
def test_single_report_conversion(input_file: str, sample_reports_path: str) -> None:
1919
runner = CliRunner()
2020
m = mock_open()
2121

@@ -44,6 +44,7 @@ def test_cfn_guard_conversion_explicit_destination(sample_reports_path: str) ->
4444
main,
4545
[
4646
f"{sample_reports_path}/cfn-guard.json",
47+
"--destination-file",
4748
f"{sample_reports_path}/cfn-guard-specific.xml",
4849
],
4950
)

0 commit comments

Comments
 (0)