aoc2024/scaffold.sh

73 lines
1.3 KiB
Bash
Raw Normal View History

2024-12-01 17:50:02 +00:00
#!/usr/bin/env bash
name=day-"$1"
if [ -d day-"$name" ]; then
echo "program $name already exists"
exit 1
fi
2024-12-02 02:06:35 +00:00
mkdir -p "$name"/cmd/cli/testdata \
"$name"/testdata "$name"/internal/one/testdata "$name"/internal/two/testdata
2024-12-01 17:50:02 +00:00
touch "$name"/makefile
cat <<EOT >> "$name"/makefile
program = $name
GO = go
SRC_DIR := src
BIN_DIR := bin
EXE := \$(BIN_DIR)/\$(program)
.DEFAULT_GOAL := build
2024-12-01 21:14:30 +00:00
.PHONY: fmt vet build bench clean
2024-12-01 17:50:02 +00:00
fmt:
\$(GO) fmt ./...
vet: fmt
\$(GO) vet ./...
build: vet | \$(BIN_DIR)
\$(GO) build -o \$(EXE) ./\$(SRC_DIR)
2024-12-01 21:14:30 +00:00
bench:
2024-12-02 02:06:35 +00:00
\$(GO) test ./internal/one/ -bench=. > internal/one/benchmark
\$(GO) test ./internal/two/ -bench=. > internal/two/benchmark
\$(GO) test . -count=10 -bench=. > benchmark
2024-12-01 21:14:30 +00:00
2024-12-01 17:50:02 +00:00
\$(BIN_DIR):
@mkdir -p \$@
clean:
@rm -rv \$(BIN_DIR)
EOT
2024-12-02 02:06:35 +00:00
cat <<EOT >> "$name"/cmd/cli/main.go
2024-12-01 17:50:02 +00:00
/********************************************************************************
Advent of Code 2024 - $name
********************************************************************************/
package main
func main() {
}
EOT
2024-12-03 14:42:35 +00:00
touch "$name"/solve.go
cat <<EOT >> "$name"/makefile
package name
func Solve(data []byte) (int, int, error) {
return 0, 0, nil
}
EOT
2024-12-01 17:50:02 +00:00
cd "$name" || exit
2024-12-03 14:42:35 +00:00
go mod init github.com/onyx-and-iris/aoc2024/"$name"
MKFILES=../mkfiles.sh
[[ -f $MKFILES ]] && ln -s $MKFILES .