Skip to content

Commit ec63290

Browse files
committed
generator - add bash
1 parent 0e936d0 commit ec63290

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

setup.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ generator:
123123
destination: src/main/rust/AoC{year}_{day:0>2}/src/main.rs
124124
- source: src/main/resources/generator/Cargo.toml
125125
destination: src/main/rust/AoC{year}_{day:0>2}/Cargo.toml
126+
- language: bash
127+
templates:
128+
- source: src/main/resources/generator/template.sh
129+
destination: src/main/bash/AoC{year}_{day:0>2}.sh
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
import os
21
import shutil
2+
from pathlib import Path
33
from string import Template
44

55
if __name__ == "__main__":
6-
from config import config # type:ignore
6+
from config import config # type:ignore[missing-imports]
77
else:
88
from .config import config
99

1010

1111
def main(args: list[str]) -> None:
1212
if len(args) != 3:
13-
raise ValueError(f"Usage: {__name__} <year> <day> <lang>")
13+
msg = f"Usage: {__name__} <year> <day> <lang>"
14+
raise ValueError(msg)
1415

1516
year = args[0]
1617
day = args[1]
1718
day2 = f"{args[1]:0>2}"
1819
conf = config.get_languages()[args[2]]
1920
for template in conf.templates:
20-
destination = template.destination.format(year=year, day=day)
21-
if os.path.exists(destination):
21+
destination = Path(template.destination.format(year=year, day=day))
22+
if destination.exists():
2223
print(f"'{destination}' already exists")
2324
continue
24-
os.makedirs(os.path.dirname(destination), exist_ok=True)
25+
destination.parent.mkdir(parents=True, exist_ok=True)
2526
mappings = {"year": year, "day": day, "day2": day2}
26-
target = shutil.copyfile(template.source, destination)
27-
with open(target, "r", encoding="utf-8") as f:
27+
target = Path(shutil.copyfile(template.source, destination))
28+
with target.open("r", encoding="utf-8") as f:
2829
t = Template(f.read())
2930
s = t.substitute(mappings)
30-
with open(target, "w", encoding="utf-8") as f:
31+
with target.open("w", encoding="utf-8") as f:
3132
f.write(s)
3233
print(f"Generated '{target}'")
33-
return
3434

3535

3636
if __name__ == "__main__":
3737
main(["2018", "1", "python"])
3838
main(["2018", "1", "java"])
3939
main(["2018", "1", "rust"])
40+
main(["2025", "4", "bash"])
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
#
3+
# Advent of Code ${year} Day ${day}
4+
#
5+
6+
year=${year}
7+
day=${day2}
8+
9+
part1() {
10+
echo 0
11+
return 0
12+
}
13+
14+
part2() {
15+
echo 0
16+
return 0
17+
}
18+
19+
tests() {
20+
# shellcheck disable=SC2034
21+
{
22+
sample=("TODO")
23+
}
24+
25+
TEST part1 sample 0
26+
TEST part2 sample 0
27+
}
28+
29+
source "$$(dirname "$$0")/aoc_main.sh"

0 commit comments

Comments
 (0)