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
0 commit comments