init
This commit is contained in:
57
aoc-cacheclear
Executable file
57
aoc-cacheclear
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
AOC_DIR="${AOC_DIR:-$HOME/.aoc}"
|
||||
CACHE_DIR="$AOC_DIR/cache"
|
||||
|
||||
usage() {
|
||||
pname=$(basename "$0")
|
||||
echo "Usage: $pname <year> <day?>" >&2
|
||||
echo " $pname all"
|
||||
exit 1
|
||||
}
|
||||
|
||||
verify_int() {
|
||||
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||
echo "'$1' is not an integer" >&2
|
||||
usage
|
||||
fi
|
||||
}
|
||||
|
||||
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = all ]; then
|
||||
if [ ! -d "$CACHE_DIR" ]; then
|
||||
echo "No cache present" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Clearing full cache" >&2
|
||||
rm -rf "$CACHE_DIR"
|
||||
exit
|
||||
fi
|
||||
|
||||
year="$1"
|
||||
verify_int "$year"
|
||||
year_cache_dir="$CACHE_DIR/$year"
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
if [ ! -d "$year_cache_dir" ]; then
|
||||
echo "No cache for $year present" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Clearing cache for year $year" >&2
|
||||
rm -rf "$year_cache_dir"
|
||||
exit
|
||||
fi
|
||||
|
||||
day="$2"
|
||||
verify_int "$day"
|
||||
cache_file=$year_cache_dir/d$day.in
|
||||
if [ ! -f "$cache_file" ]; then
|
||||
echo "No cache for $year day $day present"
|
||||
exit 1
|
||||
fi
|
||||
echo "Clearing cache for $year day $day" >&2
|
||||
rm $cache_file
|
||||
Reference in New Issue
Block a user