Strengthen types in Args

This commit is contained in:
Skye 2023-12-02 19:02:58 -05:00
parent 1f04a61598
commit 74a49732bd

View file

@ -149,7 +149,7 @@ def get_country_name(
parser = argparse.ArgumentParser(
prog="format", description="format postcards with latex"
)
parser.add_argument("template", help="template to use", nargs="?", default="2card")
parser.add_argument("template", help="template to use", nargs="?", type=Path, default="2card")
parser.add_argument(
"-o", "--origin", help="origin country code", default="us", type=iso_code
)
@ -179,7 +179,7 @@ parser.add_argument(
"-a",
"--address-file",
default="addresses.csv",
type=str,
type=Path,
help="CSV file containing addresses",
)
@ -187,7 +187,7 @@ parser.add_argument(
"-i",
"--content-path",
default="content",
type=str,
type=Path,
help="Directory containing content files",
)
@ -206,13 +206,13 @@ parser.add_argument("-w", "--watch", action="store_true", help="Watch input file
class Args(argparse.Namespace):
template: str
template: Path
origin: IsoCode
language: IsoCode
count: int
skip: int
address_file: str
content_path: str
address_file: Path
content_path: Path
no_content: bool
dont_compile: bool
@ -287,6 +287,11 @@ if args.origin == "us":
serial += 1
imb.write_current_serial(serial)
def serialize_paths(obj: object):
if isinstance(obj, Path):
return str(obj)
raise TypeError("Type not Serializable")
with (root_dir() / "options.json").open("w") as options:
json.dump(
fp=options,
@ -294,6 +299,7 @@ with (root_dir() / "options.json").open("w") as options:
"args": args.__dict__,
"cards": cards,
},
default=serialize_paths
)
if args.dont_compile: