From d64b9f78372d0f128833cbc36b129e0269a5105a Mon Sep 17 00:00:00 2001 From: letelete Date: Tue, 17 Dec 2024 12:05:12 +0100 Subject: [PATCH] [aoc.sh] Allow to skip samples --- 2024/aoc.sh | 29 ++++++++++++++++++++--------- 2024/day-runner.js | 9 +++++++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/2024/aoc.sh b/2024/aoc.sh index 34ab40e..8e7d25a 100755 --- a/2024/aoc.sh +++ b/2024/aoc.sh @@ -37,13 +37,14 @@ get_input_path() { echo "$(get_day_path "$1")/$AOC_INPUT_FILE"; } get_sample_input_path() { echo "$(get_day_path "$1")/$AOC_SAMPLE_INPUT_FILE"; } help() { - print $TEXT_INFO "Usage: [-t|--test ] [-r|--run ] [-a|--add ] [-c|--code ] [-s|--stage ] [-l|--list] [-h|--help]" + print $TEXT_INFO "Usage: [-d|--data ] [-t|--test ] [-r|--run ] [-a|--add ] [-c|--code ] [-s|--stage ] [-l|--list] [-h|--help]" local options=( - "-t | --test Executes given AoC day with samples only." - "-r | --run Executes given AoC day." - "-a | --add Adds a new AoC day." - "-c | --code Opens given AoC day in $AOC_EDITOR." - "-s | --stage Git commits given AoC day adding some christmas touch $(get_xmas_emoji)." + "-n | --nosamples Executes given AoC day skipping samples." + "-t | --test Executes given AoC day with samples only." + "-r | --run Executes given AoC day." + "-a | --add Adds a new AoC day." + "-c | --code Opens given AoC day in $AOC_EDITOR." + "-s | --stage Git commits given AoC day adding some christmas touch $(get_xmas_emoji)." "-l | --list Lists all created AoC days." "-h | --help Prints help page." ) @@ -97,13 +98,19 @@ create_input_data() { run_day() { local day_path=$(get_day_path "$1") print $TEXT_INFO "Running day $(get_day_name "$1") at $day_path" - node "$AOC_RUNNER_PATH" "$day_path" "$AOC_DAY_TARGET_FILE" + node "$AOC_RUNNER_PATH" "$day_path" "$AOC_DAY_TARGET_FILE" "$2" +} + +run_day_no_samples() { + local day_path=$(get_day_path "$1") + print $TEXT_INFO "Running day $(get_day_name "$1") at $day_path (no samples)" + node "$AOC_RUNNER_PATH" "$day_path" "$AOC_DAY_TARGET_FILE" --nosamples } test_day() { local day_path=$(get_day_path "$1") print $TEXT_INFO "Running day $(get_day_name "$1") at $day_path (samples only)" - node "$AOC_RUNNER_PATH" "$day_path" "$AOC_DAY_TARGET_FILE" --test + node "$AOC_RUNNER_PATH" "$day_path" "$AOC_DAY_TARGET_FILE" --samples } list_days() { @@ -157,7 +164,7 @@ if ! init_env; then exit 1 fi -VALID_ARGS=$(getopt -a -n $0 -o hla:c:s:r:t: --long help,list,add:,code:,stage:,run:,test: -- "$@") +VALID_ARGS=$(getopt -a -n $0 -o hla:c:s:r:t:n: --long help,list,add:,code:,stage:,run:,test:nosamples: -- "$@") if [ $? -ne 0 ]; then help exit 1 @@ -194,6 +201,10 @@ while :; do test_day "$2" shift 2 ;; + -n | --nosamples) + run_day_no_samples "$2" + shift 2 + ;; --) shift break diff --git a/2024/day-runner.js b/2024/day-runner.js index 4fa812c..bb399fd 100644 --- a/2024/day-runner.js +++ b/2024/day-runner.js @@ -5,6 +5,8 @@ * @argument {dayPath} A relative path to the day the runner executes. * @argument {dayTarget} A filename that the runner imports { parse, part1, part2} from. * Defaults to `main.js`. + * @argument {noSamples} A flag indicating if samples should be omitted. + * @argument {samples} A flag indicating if only samples should be run. */ const fs = require('fs'); const os = require('os'); @@ -14,7 +16,8 @@ const README_FILENAME = `README.md`; const args = process.argv.slice(2); const dayPath = args[0]; const dayTarget = args[1]; -const samplesOnly = args.includes('--test'); +const noSamples = args.includes('--nosamples'); +const samplesOnly = !noSamples && args.includes('--samples'); if (!dayPath) { throw new Error('Missing required argument: relative day path'); } @@ -192,7 +195,9 @@ function withInput(callback) { withInput((data, samples) => { readme.init(); - samples.forEach((sample, index) => run(`sample ${index + 1}`, sample)); + if (!noSamples) { + samples.forEach((sample, index) => run(`sample ${index + 1}`, sample)); + } if (!samplesOnly) { run('answer', data); }