50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
|
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"
|
||
|
)
|
||
|
parser.add_argument(
|
||
|
"-i",
|
||
|
"--input",
|
||
|
type=Path,
|
||
|
default=None,
|
||
|
help="input to use (override user and test)",
|
||
|
)
|
||
|
parser.add_argument("-y", "--year", type=int, help="year to run", default=2023)
|
||
|
parser.add_argument("day", type=int, help="day to run")
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
verbose: bool = args.verbose
|
||
|
test: bool = args.test
|
||
|
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"
|
||
|
|
||
|
with open(input_path) as fp:
|
||
|
sys.stdin = fp
|
||
|
importlib.import_module(f".{year}.day{day}", __package__)
|
||
|
|
||
|
sys.stdin = sys.__stdin__
|