-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnew_puzzle.sh
More file actions
executable file
·45 lines (35 loc) · 1.19 KB
/
new_puzzle.sh
File metadata and controls
executable file
·45 lines (35 loc) · 1.19 KB
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
#/bin/bash
# new_puzzle.sh creates a new folder and copies template files for a new day's puzzle
# If the number of arguments is not 2, then print usage instructions and exit
if [[ $# -ne 2 ]]; then
echo "Usage: ./new_puzzle.sh <year> <day>"
exit 1
fi
YEAR=$1
DAY=$2
# If YEAR does not match the regex ^201[5-8]$, print error and exit
if ! [[ $YEAR =~ ^201[5-8]$ ]]; then
echo "Invalid <year>. Must be between 2015 and 2018, inclusive."
exit 1
fi
# If DAY is not an integer between 1 and 31, print error and exit
if ! [[ $DAY =~ ^[12]?[0-9]$ ]] && ! [[ $DAY =~ ^3[01]$ ]]; then
echo "Invalid <day>. Must be between 1 and 31, inclusive."
exit 1
fi
# Create header for new README
README="# [$YEAR Day $DAY:](https://adventofcode.com/$YEAR/day/$DAY)\n\n## Original Brief\n\n"
# If DAY is one digit, left-pad with a zero
if [[ $DAY =~ ^[0-9]$ ]]; then
DAY="0$DAY"
fi
DIR="puzzles/$YEAR/$DAY"
if [[ -d $DIR ]]; then
echo "Error: Directory \"$DIR already exists.\""
exit 1
fi
mkdir -p $DIR
# Copy template files (or variable string) into the new puzzle files
cp template/input.txt.templ $DIR/input.txt
cp template/main.go.templ $DIR/main.go
echo -e $README > $DIR/README.md