From: alex <> Date: Tue, 2 Dec 2025 12:47:45 +0000 (+0100) Subject: tool to perform recurrent actions X-Git-Url: https://aoc.elinar.fr/?a=commitdiff_plain;h=1f591a15e4b2f5e9ccca488df4d6acc601ae0bb5;p=aoc_2025 tool to perform recurrent actions --- diff --git a/aoc b/aoc new file mode 100755 index 0000000..964beb4 --- /dev/null +++ b/aoc @@ -0,0 +1,74 @@ +#!/bin/bash + +usage() { + cat <... + +Options: + --run run the solution for the given (default) + --test run the tests for the given + --input retrieve the input file for the given (default) + --html retrieve the writeup for a given + --help print this help and exit +EOF +} + +read_cookie() { + [ ! -f .cookie ] && echo "Missing .cookie file" && exit 1 + COOKIE=$(cat .cookie) + [ -z "$COOKIE" ] && echo "Cookie file is empty" && exit 1 +} + +get_input() { + [ -f input/$DAY.txt ] && return + read_cookie + curl -o input/$DAY.txt \ + -H "Cookie: session=$COOKIE" \ + "https://adventofcode.com/2025/day/$(printf "%d" ${DAY/day/})/input" +} + +get_html() { + read_cookie + curl -o html/$DAY.html \ + -H "Cookie: session=$COOKIE" \ + "https://adventofcode.com/2025/day/$(printf "%d" ${DAY/day/})" +} + +do_test() { + cargo test $DAY::tests +} + +do_run() { + cargo run --release $DAY input/$DAY.txt +} + +COOKIE="" + +DAY="" +DO_RUN=1 +DO_TEST=0 +DO_INPUT=1 +DO_HTML=0 + +while [ $# -ge 1 ]; do + case $1 in + "--run") DO_RUN=1; DO_TEST=0 ;; + "--test") DO_RUN=0; DO_TEST=1; DO_INPUT=0 ;; + "--input") DO_INPUT=1; DO_RUN=0 ;; + "--html") DO_HTML=1; DO_RUN=0 ;; + "--help"|"-h") usage && exit 0 ;; + -*) echo "Unknown or missing option: $1" && usage && exit 1 ;; + *) break ;; + esac + shift +done + +while [ $# -ge 1 ]; do + DAY=$1 + echo "day: $DAY" + [ $DO_HTML -eq 1 ] && get_html + [ $DO_INPUT -eq 1 ] && get_input + [ $DO_RUN -eq 1 ] && do_run + [ $DO_TEST -eq 1 ] && do_test + shift +done