Skip to content

Commit daabf7b

Browse files
authored
Merge backfill scripts
1 parent 884f042 commit daabf7b

File tree

4 files changed

+71
-85
lines changed

4 files changed

+71
-85
lines changed

bin/aoc_lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ aoc_create_readme() {
8787
url_base="adventofcode.com/${year}/day/${day}"
8888
url="https://${url_base}"
8989

90-
# NOTE remember to run readme_backfill.sh after changing the template below.
90+
# NOTE remember to run backfill_days.sh after changing the template below.
9191
read -rd '' content <<-MD || :
9292
# Advent of Code - ${year} Day ${day}
9393
Here are my solutions to this puzzle.
@@ -114,7 +114,7 @@ aoc_create_instructions_url() {
114114

115115
url="https://adventofcode.com/${year}/day/${day}"
116116

117-
# NOTE remember to run readme_backfill.sh after changing the template below.
117+
# NOTE remember to run backfill_days.sh after changing the template below.
118118
read -rd '' content <<-URL_FILE || :
119119
[InternetShortcut]
120120
URL = ${url}

bin/backfill_days.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
# Backfill boilerplate files for like README.md, instructions.url etc. for a given year and day.
3+
#Run this when changing the template in aoc_create_readme()
4+
5+
set -o nounset
6+
set -o pipefail
7+
[[ "${TRACE-0}" =~ ^1|t|y|true|yes$ ]] && set -o xtrace
8+
9+
SCRIPT_NAME=${0##*/}
10+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
11+
12+
IFS= read -rd '' USAGE <<EOF || :
13+
Backfill boilerplate files like README.md, instructions.url etc for specific or all days. Run this after updating the README.md template.
14+
Usage: $ ${SCRIPT_NAME} -h |[ datefmt ]
15+
16+
Options:
17+
datefmt\t\t yy/d, yy/dd, yyyy/dd. Default: backfill all days.
18+
EOF
19+
20+
21+
backfill_days_all() {
22+
paths=$(find . -maxdepth 2 -type d -regex "\./*[0-9]+/[0-9]+" | sort | sed -e 's|./||')
23+
for path in $paths; do
24+
cd "$path" || exit
25+
IFS="/" read -ra ym <<< "$path"
26+
year=${ym[0]}
27+
day=${ym[1]}
28+
29+
aoc_create_readme "$year" "$day"
30+
aoc_create_instructions_url "$year" "$day"
31+
printf "Backfilled %s\n" "$path"
32+
cd ../..
33+
done
34+
}
35+
36+
37+
backfill_day() {
38+
local year="$1"
39+
local day="$2"
40+
41+
aoc_create_enter "$year" "$day"
42+
aoc_create_readme "$year" "$day"
43+
aoc_create_instructions_url "$year" "$day"
44+
printf "Backfilled %d/%s\n" "$year" "$day" # Print day as %s to preserve leading 0.
45+
}
46+
47+
48+
# shellcheck source=bin/aoc_lib.sh
49+
. "$SCRIPT_DIR/aoc_lib.sh"
50+
aoc_init_script
51+
52+
53+
# Arg parsing
54+
while getopts ":h?" opt; do
55+
case "$opt" in
56+
:) echo "Option -$OPTARG requires an argument." >&2; exit 1;;
57+
h|?|*) echo -e "$USAGE"; exit 0;;
58+
esac
59+
done
60+
shift $((OPTIND - 1))
61+
62+
if [ "$#" -eq 1 ]; then
63+
year=$(aoc_parse_year "$@") || exit
64+
day=$(aoc_parse_day "$@") || exit
65+
66+
backfill_day "$year" "$day"
67+
else
68+
backfill_days_all
69+
fi

bin/readme_backfill.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

bin/readme_create.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)