From 4e0dcfd419c6d48605a5f4d0e5168fa547296f21 Mon Sep 17 00:00:00 2001 From: Asriel Senna Date: Sun, 19 May 2024 17:56:18 +0200 Subject: [PATCH] cli: require at least one of output or print --- src/parliamentarch/__main__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/parliamentarch/__main__.py b/src/parliamentarch/__main__.py index 4eee477..d10b2aa 100644 --- a/src/parliamentarch/__main__.py +++ b/src/parliamentarch/__main__.py @@ -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)