Skip to content

Commit

Permalink
cli: require at least one of output or print
Browse files Browse the repository at this point in the history
  • Loading branch information
Gouvernathor committed May 19, 2024
1 parent 5e529ca commit 4e0dcfd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/parliamentarch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ def main():
SVG code will be printed in the standard output.""",
# TODO: make sure that this argument is optional and defaults to None
)
# whether to print the resulting file's content (when the output file is not given)
# whether to print the resulting file's content (regardless of the output file being given)
parser.add_argument("-p", "--print",
action="store_true",
help="""Pass this to print the SVG code in the standard output even when
an output file is passed.""",
)
# if both are given, do both
# if none are given, only print
# if none are given, raise


args = parser.parse_args()

if not (args.output or args.print):
parser.error("At least one of --output or --print must be passed.")

with args.input as f:
kwparams = json.load(f)
kwparams["attrib"] = {SeatData(**d): n for d in kwparams["attrib"] if (n := d.pop("nseats", 1))}

result = get_svg_from_attribution(**kwparams)

file_output = args.output is not None
if file_output:
if args.output is not None:
with args.output as f:
f.write(result)
if args.print or not file_output:
if args.print:
print(result)


Expand Down

0 comments on commit 4e0dcfd

Please sign in to comment.