Skip to content

Commit 0d7acd7

Browse files
committed
CLI wrapper
1 parent 6ec2e7d commit 0d7acd7

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

scripts/aoc.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import os
66
import subprocess
7-
import typing as t
7+
import sys
88
from dataclasses import dataclass
99
from pathlib import Path
1010

@@ -173,7 +173,10 @@ def aoc_clippy(ctx: click.Context):
173173
if cwd == ctx.obj.aoc_root:
174174
for year in sorted(cwd.glob("*")):
175175
if year.name.isdigit() and int(year.name) >= 2015:
176-
print(f"Year {year.name}")
176+
print("--------------------------------")
177+
print(f"| Year {year.name}")
178+
print("--------------------------------")
179+
sys.stdout.flush()
177180
ctx.obj.pass_thru("lint_rust.sh", [], cwd=year)
178181
else:
179182

@@ -182,6 +185,29 @@ def aoc_clippy(ctx: click.Context):
182185
ctx.obj.pass_thru("lint_rust.sh", [])
183186

184187

188+
@aoc.command(name="test")
189+
@click.pass_context
190+
def aoc_test(ctx: click.Context):
191+
"""
192+
Run cargo test.
193+
"""
194+
cwd = Path(os.getcwd())
195+
196+
if cwd == ctx.obj.aoc_root:
197+
for year in sorted(cwd.glob("*")):
198+
if year.name.isdigit() and int(year.name) >= 2015:
199+
print("--------------------------------")
200+
print(f"| Year {year.name}")
201+
print("--------------------------------")
202+
sys.stdout.flush()
203+
subprocess.call(["cargo", "test"], cwd=year)
204+
else:
205+
206+
if not (cwd / "Cargo.toml").is_file():
207+
raise click.ClickException("need a Cargo.toml file")
208+
subprocess.call(["cargo", "test"])
209+
210+
185211
@aoc.command(name="answers", context_settings=dict(ignore_unknown_options=True, allow_extra_args=True))
186212
@click.pass_context
187213
def aoc_answers(ctx: click.Context):

0 commit comments

Comments
 (0)