Skip to content

Commit

Permalink
feat(cli): Support --files
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-lenormand committed Apr 12, 2024
1 parent 57f4564 commit ae20a7d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions parliament/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def main():
type=argparse.FileType("r"),
default=sys.stdin,
)
parser.add_argument(
"--files",
help="Provide a comma-separated list of policies",
type=str,
)
parser.add_argument(
"--directory", help="Provide a path to directory with policy files", type=str
)
Expand Down Expand Up @@ -217,6 +222,8 @@ def main():
# If I have some stdin to read it should be my policy, file input should indicate stdin
if not sys.stdin.isatty() and args.file.name != "<stdin>":
parser.error("You cannot pass a file with --file and use stdin together")
elif args.file.name != "<stdin>" and args.files:
parser.error("You cannot pass files with both --file and --files together")

# Change the exit status if there are errors
exit_status = 0
Expand Down Expand Up @@ -315,6 +322,18 @@ def main():
config=config,
)
findings.extend(policy.findings)
elif args.files and not args.directory:
for file_path in (stripped_path for path in args.files.split(",") if (stripped_path := path.strip())):
path = Path(file_path)
contents = path.read_text()
policy = analyze_policy_string(
contents,
file_path,
private_auditors_custom_path=args.private_auditors,
include_community_auditors=args.include_community_auditors,
config=config,
)
findings.extend(policy.findings)
elif args.file and not args.directory:
contents = args.file.read()
args.file.close()
Expand Down

0 comments on commit ae20a7d

Please sign in to comment.