advent-of-code/src/holt59/aoc/__main__.py

60 lines
1.6 KiB
Python
Raw Normal View History

2023-12-19 14:39:10 +00:00
import argparse
import importlib
import os
import sys
from pathlib import Path
def main():
parser = argparse.ArgumentParser("Holt59 Advent-Of-Code Runner")
parser.add_argument("-v", "--verbose", action="store_true", help="verbose mode")
parser.add_argument("-t", "--test", action="store_true", help="test mode")
parser.add_argument(
"-u", "--user", type=str, default="holt59", help="user input to use"
)
2024-01-04 17:36:30 +00:00
parser.add_argument(
"--stdin",
action="store_true",
default=False,
help="use stdin as input",
)
2023-12-19 14:39:10 +00:00
parser.add_argument(
"-i",
"--input",
type=Path,
default=None,
help="input to use (override user and test)",
)
2024-12-01 09:26:02 +00:00
parser.add_argument("-y", "--year", type=int, help="year to run", default=2024)
2023-12-19 14:39:10 +00:00
parser.add_argument("day", type=int, help="day to run")
args = parser.parse_args()
verbose: bool = args.verbose
test: bool = args.test
2024-01-04 17:36:30 +00:00
stdin: bool = args.stdin
2023-12-19 14:39:10 +00:00
user: str = args.user
input_path: Path | None = args.input
year: int = args.year
day: int = args.day
# TODO: change this
if verbose:
os.environ["AOC_VERBOSE"] = "True"
if input_path is None:
input_path = Path(__file__).parent.joinpath(
"inputs", "tests" if test else user, str(year), f"day{day}.txt"
)
assert input_path.exists(), f"{input_path} missing"
2024-01-04 17:36:30 +00:00
if stdin:
2023-12-19 14:39:10 +00:00
importlib.import_module(f".{year}.day{day}", __package__)
2024-01-04 17:36:30 +00:00
else:
with open(input_path) as fp:
sys.stdin = fp
importlib.import_module(f".{year}.day{day}", __package__)
2023-12-19 14:39:10 +00:00
2024-01-04 17:36:30 +00:00
sys.stdin = sys.__stdin__