Skip to content

Commit

Permalink
refactor(parliament.cli): Allow passing custom arguments to main()
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-lenormand committed Apr 17, 2024
1 parent ae20a7d commit 1ba970a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions parliament/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def find_files(directory, exclude_pattern=None, policy_extension=""):
return discovered_files


def main():
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument(
"--aws-managed-policies",
Expand Down Expand Up @@ -200,7 +200,7 @@ def main():
action="version",
version="%(prog)s {version}".format(version=__version__),
)
args = parser.parse_args()
args = parser.parse_args(args=argv[1:])

log_level = logging.ERROR
log_format = "%(message)s"
Expand All @@ -226,7 +226,6 @@ def main():
parser.error("You cannot pass files with both --file and --files together")

# Change the exit status if there are errors
exit_status = 0
findings = []

if args.include_community_auditors:
Expand Down Expand Up @@ -364,7 +363,7 @@ def main():
findings.extend(policy.findings)
else:
parser.print_help()
exit(-1)
return -1

filtered_findings = []
for finding in findings:
Expand All @@ -374,14 +373,18 @@ def main():

if len(filtered_findings) == 0:
# Return with exit code 0 if no findings
return
return 0

for finding in filtered_findings:
print_finding(finding, args.minimal, args.json)

# There were findings, so return with a non-zero exit code
exit(1)
return 1


def cli() -> int:
sys.exit(main(sys.argv))


if __name__ == "__main__":
main()
cli()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_description():
long_description=get_description(),
long_description_content_type="text/markdown",
url="https://github.com/duo-labs/parliament",
entry_points={"console_scripts": "parliament=parliament.cli:main"},
entry_points={"console_scripts": "parliament=parliament.cli:cli"},
test_suite="tests/unit",
tests_require=TESTS_REQUIRE,
extras_require={"dev": TESTS_REQUIRE + ["autoflake", "autopep8", "pylint"]},
Expand Down

0 comments on commit 1ba970a

Please sign in to comment.