1
+ #! /usr/bin/env bash
2
+
3
+ set -eo pipefail
4
+
5
+ script_root=" $( dirname " $0 " ) "
6
+
7
+ echoerr () {
8
+ printf " %s\n" " $* " >&2
9
+ }
10
+
11
+ usage () {
12
+ echo " Usage: $( basename " $0 " ) <command> [args]"
13
+ echo
14
+ echo " Commands:"
15
+ echo " run Run the main console application."
16
+ echo " test Run the unit tests."
17
+ echo " new <day> Create a new day with template files."
18
+ echo
19
+ echo " Examples:"
20
+ echo " $( basename " $0 " ) run"
21
+ echo " $( basename " $0 " ) test"
22
+ echo " $( basename " $0 " ) new 5"
23
+ }
24
+
25
+ invoke_run () {
26
+ dotnet run \
27
+ -c Debug \
28
+ --project " ${script_root} /src/adventofcode2024.console/adventofcode2024.console.csproj"
29
+ }
30
+
31
+ invoke_test () {
32
+ dotnet run \
33
+ -c Debug \
34
+ --project " ${script_root} /tests/adventofcode2024.UnitTests/adventofcode2024.UnitTests.csproj" \
35
+ --disable-logo
36
+ }
37
+
38
+ invoke_create_from_template () {
39
+ local template_path=" $1 "
40
+ local day=" $2 "
41
+ local target_path
42
+
43
+ target_path=" $( echo " ${template_path} " | sed " s/Day00/Day${day} /" ) "
44
+
45
+ if [[ -e " ${target_path} " ]]; then
46
+ echo " ${target_path} already exists."
47
+ return
48
+ fi
49
+
50
+ if [[ ! -e " ${template_path} " ]]; then
51
+ echoerr " ${template_path} does not exist."
52
+ exit 1
53
+ fi
54
+
55
+ cp " ${template_path} " " ${target_path} "
56
+ sed -i " s/Day00/Day${day} /g" " ${target_path} "
57
+ echo " Created ${target_path} "
58
+ }
59
+
60
+ invoke_new_day () {
61
+ if ! [[ " $1 " =~ ^[0-9]+$ ]]; then
62
+ echoerr " The day argument must be a positive integer."
63
+ exit 1
64
+ fi
65
+
66
+ local day=" $( printf " %02d" " $1 " ) "
67
+ local input_path=" ${script_root} /src/adventofcode2024.console/input/Day00.txt"
68
+ local day_path=" ${script_root} /src/adventofcode2024/Day00.cs"
69
+ local test_path=" ${script_root} /tests/adventofcode2024.UnitTests/Day00Tests.cs"
70
+
71
+ invoke_create_from_template " ${input_path} " " ${day} "
72
+ invoke_create_from_template " ${day_path} " " ${day} "
73
+ invoke_create_from_template " ${test_path} " " ${day} "
74
+ }
75
+
76
+ command=" ${1:- } "
77
+ shift || true
78
+
79
+ case " ${command} " in
80
+ run)
81
+ invoke_run
82
+ ;;
83
+ test)
84
+ invoke_test
85
+ ;;
86
+ new)
87
+ invoke_new_day " $1 "
88
+ ;;
89
+ * )
90
+ echoerr " Invalid or missing command. See usage below."
91
+ usage
92
+ exit 1
93
+ ;;
94
+ esac
0 commit comments