-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
82 lines (71 loc) · 2.3 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
set shell := ["sh", "-cu"]
set dotenv-load
set positional-arguments
year := "2021"
name := "aoc_{{year}}"
alias di := download_input
alias gen := generate
alias t := test
alias wt := watch_test
alias wr := watch_run
# -> list
@default: list
# List just targets
@list:
just --list --unsorted --list-heading "$(printf 'Targets for {{name}}::\n\r')"
@update_core:
git -C aoc_core pull origin master
test day='all':
#!/usr/bin/env sh
if [[ "{{day}}" = "all" ]]; then
cargo test
else
cargo test --test day_"$(printf '%02d' {{day}})"
fi
generate day:
#!/usr/bin/env sh
DAY="$(printf '%02d' {{day}})"
IMPL_FILE="{{justfile_directory()}}/src/day/day_$DAY.rs"
TEST_FILE="{{justfile_directory()}}/tests/day_$DAY.rs"
IMPL_TEMPLATE="$(cat "{{justfile_directory()}}/templates/day.rs")"
TEST_TEMPLATE="$(cat "{{justfile_directory()}}/templates/test.rs")"
check_file() {
if [ -f "$2" ]; then
echo "$1 for {{year}} day {{day}} exists at $2"
exit 1
fi
}
check_file Implementation "$IMPL_FILE"
check_file Tests "$TEST_FILE"
echo "${IMPL_TEMPLATE//@DAY@/$DAY}" > "$IMPL_FILE"
echo "${TEST_TEMPLATE//@DAY@/$DAY}" > "$TEST_FILE"
echo "Implementation for day {{day}} generated at $IMPL_FILE"
echo "Tests for day {{day}} generated at $TEST_FILE"
download_input day:
#!/usr/bin/env sh
PADDED_DAY="$(printf '%02d' {{day}})"
OUT_FILE="{{justfile_directory()}}/src/input/day_$PADDED_DAY.txt"
if [ -f "$OUT_FILE" ]; then
echo "Input for {{year}} day {{day}} exists at $OUT_FILE"
exit 1
fi
source "{{justfile_directory()}}/.envrc"
if [ -z "$AOC_SESSION" ]; then
echo AOC_SESSION not defined
exit 1
fi
curl -sf -H "Cookie: session=$AOC_SESSION" "https://adventofcode.com/{{year}}/day/{{day}}/input" -o "$OUT_FILE"
if [ -f "$OUT_FILE" ]; then
echo "Downloaded {{year}} day {{day}} input to $OUT_FILE"
else
echo "Unable to download input!"
fi
# Platform info
@info:
echo {{name}} :: {{os()}} {{arch()}}
# Watch for code changes, running against input
@watch_run day:
cargo watch -x 'run -- run -d {{day}}'
# Watch for code changes, running tests for day
@watch_test day:
cargo watch -x "test --test day_$(printf '%02d' {{day}})"