Neale Pickett
·
2020-10-27
mkcategory
1#! /bin/sh
2
3# This `mkcategory` merges subdirectories of puzzles together,
4# in a dumb way that will break if you have the same point value in two directories.
5# It also makes each puzzle show up a second time, worth 100 points more,
6# to show off what `mkcategory` can do without me having to write more code.
7
8fail () {
9 echo "ERROR: $*" 1>&2
10 exit 1
11}
12
13case $1 in
14 inventory)
15 printf '{"Puzzles":['
16 ls -d */[0-9]* | while read p; do
17 puzzle=${p##*/}
18 printf "%s%d,10%d" "$comma" "$puzzle" "$puzzle"
19 comma=,
20 done
21 printf ']}'
22 ;;
23 puzzle)
24 points=$(($2 % 100))
25 transpile puzzle -dir */$points
26 ;;
27 file)
28 points=$(($2 % 100))
29 transpile file -dir */$points "$3"
30 ;;
31 answer)
32 points=$(($2 % 100))
33 transpile answer -dir */$points -answer="$3"
34 ;;
35 *)
36 fail "What is $1" 1>&2
37 ;;
38esac