Skip to content

Commit

Permalink
[aoc.sh] Allow to skip samples
Browse files Browse the repository at this point in the history
  • Loading branch information
letelete committed Dec 17, 2024
1 parent 5973214 commit d64b9f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
29 changes: 20 additions & 9 deletions 2024/aoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <arg>] [-r|--run <arg>] [-a|--add <arg>] [-c|--code <arg>] [-s|--stage <arg>] [-l|--list] [-h|--help]"
print $TEXT_INFO "Usage: [-d|--data <arg>] [-t|--test <arg>] [-r|--run <arg>] [-a|--add <arg>] [-c|--code <arg>] [-s|--stage <arg>] [-l|--list] [-h|--help]"
local options=(
"-t | --test <DAY_NUMBER> Executes given AoC day with samples only."
"-r | --run <DAY_NUMBER> Executes given AoC day."
"-a | --add <DAY_NUMBER> Adds a new AoC day."
"-c | --code <DAY_NUMBER> Opens given AoC day in $AOC_EDITOR."
"-s | --stage <DAY_NUMBER> Git commits given AoC day adding some christmas touch $(get_xmas_emoji)."
"-n | --nosamples <DAY_NUMBER> Executes given AoC day skipping samples."
"-t | --test <DAY_NUMBER> Executes given AoC day with samples only."
"-r | --run <DAY_NUMBER> Executes given AoC day."
"-a | --add <DAY_NUMBER> Adds a new AoC day."
"-c | --code <DAY_NUMBER> Opens given AoC day in $AOC_EDITOR."
"-s | --stage <DAY_NUMBER> Git commits given AoC day adding some christmas touch $(get_xmas_emoji)."
"-l | --list Lists all created AoC days."
"-h | --help Prints help page."
)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -194,6 +201,10 @@ while :; do
test_day "$2"
shift 2
;;
-n | --nosamples)
run_day_no_samples "$2"
shift 2
;;
--)
shift
break
Expand Down
9 changes: 7 additions & 2 deletions 2024/day-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d64b9f7

Please sign in to comment.