mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 06:10:47 +00:00
remove scaffold.sh
add scaffold aoc template
This commit is contained in:
parent
51fed356af
commit
88f082080d
17
.scaffold/aoc/hooks/post_scaffold.sh
Normal file
17
.scaffold/aoc/hooks/post_scaffold.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "{{ .Project }}" || exit 1
|
||||
|
||||
go mod init github.com/onyx-and-iris/aoc{{ .Scaffold.year }}/"{{ .Project }}"
|
||||
go mod tidy
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
day=$(echo "{{ .Project }}" | sed 's/^day-0*//')
|
||||
|
||||
mkdir -p testdata
|
||||
curl "https://adventofcode.com/{{ .Scaffold.year }}/day/$day/input" -H "Cookie: session=$AOC_SESSION" > testdata/input.txt
|
||||
|
||||
|
||||
mkdir -p cmd/cli/testdata && ln testdata/input.txt cmd/cli/testdata/input.txt
|
||||
mkdir -p internal/one/testdata && ln testdata/input.txt internal/one/testdata/input.txt
|
||||
mkdir -p internal/two/testdata && ln testdata/input.txt internal/two/testdata/input.txt
|
16
.scaffold/aoc/scaffold.yml
Normal file
16
.scaffold/aoc/scaffold.yml
Normal file
@ -0,0 +1,16 @@
|
||||
messages:
|
||||
pre: |
|
||||
Use this scaffold to generate a new AOC project.
|
||||
post: |
|
||||
# You've generated a new AOC project!
|
||||
|
||||
You can now run the following commands:
|
||||
|
||||
- `go run ./cmd/cli/` - Runs the main application and supports passing CLI args
|
||||
|
||||
questions:
|
||||
- name: year
|
||||
prompt:
|
||||
message: "What year is this project for?"
|
||||
default: "2024"
|
||||
type: "input"
|
41
.scaffold/aoc/{{ .Project }}/cmd/cli/main.go
Normal file
41
.scaffold/aoc/{{ .Project }}/cmd/cli/main.go
Normal file
@ -0,0 +1,41 @@
|
||||
/********************************************************************************
|
||||
Advent of Code {{ .Scaffold.year }} - {{ .Project }}
|
||||
********************************************************************************/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
problems "github.com/onyx-and-iris/aoc{{ .Scaffold.year }}/{{ .Project }}"
|
||||
)
|
||||
|
||||
//go:embed testdata
|
||||
var files embed.FS
|
||||
|
||||
func main() {
|
||||
filename := flag.String("f", "input.txt", "input file")
|
||||
loglevel := flag.Int("l", int(log.InfoLevel), "log level")
|
||||
flag.Parse()
|
||||
|
||||
if slices.Contains(log.AllLevels, log.Level(*loglevel)) {
|
||||
log.SetLevel(log.Level(*loglevel))
|
||||
}
|
||||
|
||||
data, err := files.ReadFile(fmt.Sprintf("testdata/%s", *filename))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
one, two, err := problems.Solve(data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("solution one: %d\nsolution two: %d\n", one, two)
|
||||
}
|
29
.scaffold/aoc/{{ .Project }}/internal/one/solve.go
Normal file
29
.scaffold/aoc/{{ .Project }}/internal/one/solve.go
Normal file
@ -0,0 +1,29 @@
|
||||
package one
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
func Solve(buf []byte) (int, error) {
|
||||
r := bytes.NewReader(buf)
|
||||
err := parseLines(r)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func parseLines(r io.Reader) error {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package one
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//go:embed testdata/input.txt
|
||||
var data []byte
|
||||
|
||||
func BenchmarkSolve(b *testing.B) {
|
||||
os.Stdout, _ = os.Open(os.DevNull)
|
||||
Solve(data)
|
||||
}
|
18
.scaffold/aoc/{{ .Project }}/internal/one/util.go
Normal file
18
.scaffold/aoc/{{ .Project }}/internal/one/util.go
Normal file
@ -0,0 +1,18 @@
|
||||
package one
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
func parseLines(r io.Reader) error {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
29
.scaffold/aoc/{{ .Project }}/internal/two/solve.go
Normal file
29
.scaffold/aoc/{{ .Project }}/internal/two/solve.go
Normal file
@ -0,0 +1,29 @@
|
||||
package two
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
func Solve(buf []byte) (int, error) {
|
||||
r := bytes.NewReader(buf)
|
||||
err := parseLines(r)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func parseLines(r io.Reader) error {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package two
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//go:embed testdata/input.txt
|
||||
var data []byte
|
||||
|
||||
func BenchmarkSolve(b *testing.B) {
|
||||
os.Stdout, _ = os.Open(os.DevNull)
|
||||
Solve(data)
|
||||
}
|
18
.scaffold/aoc/{{ .Project }}/internal/two/util.go
Normal file
18
.scaffold/aoc/{{ .Project }}/internal/two/util.go
Normal file
@ -0,0 +1,18 @@
|
||||
package two
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
func parseLines(r io.Reader) error {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
33
.scaffold/aoc/{{ .Project }}/makefile
Normal file
33
.scaffold/aoc/{{ .Project }}/makefile
Normal file
@ -0,0 +1,33 @@
|
||||
program = {{ .Project }}
|
||||
|
||||
GO = go
|
||||
SRC_DIR := src
|
||||
BIN_DIR := bin
|
||||
|
||||
EXE := $(BIN_DIR)/$(program)
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
.PHONY: fmt vet build test bench clean
|
||||
fmt:
|
||||
$(GO) fmt ./...
|
||||
|
||||
vet: fmt
|
||||
$(GO) vet ./...
|
||||
|
||||
build: vet | $(BIN_DIR)
|
||||
$(GO) build -o $(EXE) ./$(SRC_DIR)
|
||||
|
||||
test:
|
||||
$(GO) test ./...
|
||||
|
||||
bench:
|
||||
$(GO) test ./internal/one/ -bench=. > internal/one/benchmark
|
||||
$(GO) test ./internal/two/ -bench=. > internal/two/benchmark
|
||||
$(GO) test . -count=10 -bench=. > benchmark
|
||||
|
||||
$(BIN_DIR):
|
||||
@mkdir -p $@
|
||||
|
||||
clean:
|
||||
@rm -rv $(BIN_DIR)
|
20
.scaffold/aoc/{{ .Project }}/solve.go
Normal file
20
.scaffold/aoc/{{ .Project }}/solve.go
Normal file
@ -0,0 +1,20 @@
|
||||
package solutions
|
||||
|
||||
import (
|
||||
"github.com/onyx-and-iris/aoc{{ .Scaffold.year }}/{{ .Project }}/internal/one"
|
||||
"github.com/onyx-and-iris/aoc{{ .Scaffold.year }}/{{ .Project }}/internal/two"
|
||||
)
|
||||
|
||||
func Solve(buf []byte) (int, int, error) {
|
||||
answerOne, err := one.Solve(buf)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
answerTwo, err := two.Solve(buf)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
return answerOne, answerTwo, nil
|
||||
}
|
15
.scaffold/aoc/{{ .Project }}/solve_internal_test.go
Normal file
15
.scaffold/aoc/{{ .Project }}/solve_internal_test.go
Normal file
@ -0,0 +1,15 @@
|
||||
package solutions
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//go:embed testdata/input.txt
|
||||
var data []byte
|
||||
|
||||
func BenchmarkSolve(b *testing.B) {
|
||||
os.Stdout, _ = os.Open(os.DevNull)
|
||||
Solve(data)
|
||||
}
|
194
scaffold.sh
194
scaffold.sh
@ -1,194 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
name=day-"$1"
|
||||
|
||||
if [ -d day-"$name" ]; then
|
||||
echo "program $name already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$name"/cmd/cli/testdata \
|
||||
"$name"/testdata "$name"/internal/one/testdata "$name"/internal/two/testdata
|
||||
touch "$name"/makefile
|
||||
|
||||
cat <<EOT >> "$name"/makefile
|
||||
program = $name
|
||||
|
||||
GO = go
|
||||
SRC_DIR := src
|
||||
BIN_DIR := bin
|
||||
|
||||
EXE := \$(BIN_DIR)/\$(program)
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
.PHONY: fmt vet build bench clean
|
||||
fmt:
|
||||
\$(GO) fmt ./...
|
||||
|
||||
vet: fmt
|
||||
\$(GO) vet ./...
|
||||
|
||||
build: vet | \$(BIN_DIR)
|
||||
\$(GO) build -o \$(EXE) ./\$(SRC_DIR)
|
||||
|
||||
bench:
|
||||
\$(GO) test ./internal/one/ -bench=. > internal/one/benchmark
|
||||
\$(GO) test ./internal/two/ -bench=. > internal/two/benchmark
|
||||
\$(GO) test . -count=10 -bench=. > benchmark
|
||||
|
||||
\$(BIN_DIR):
|
||||
@mkdir -p \$@
|
||||
|
||||
clean:
|
||||
@rm -rv \$(BIN_DIR)
|
||||
EOT
|
||||
|
||||
cat <<EOT >> "$name"/cmd/cli/main.go
|
||||
/********************************************************************************
|
||||
Advent of Code 2024 - $name
|
||||
********************************************************************************/
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
EOT
|
||||
|
||||
touch "$name"/solve.go
|
||||
cat <<EOT >> "$name"/solve.go
|
||||
package name
|
||||
|
||||
import (
|
||||
"github.com/onyx-and-iris/aoc2024/day-$1/internal/one"
|
||||
"github.com/onyx-and-iris/aoc2024/day-$1/internal/two"
|
||||
)
|
||||
|
||||
func Solve(buf []byte) (int, int, error) {
|
||||
answerOne, err := one.Solve(buf)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
answerTwo, err := two.Solve(buf)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
return answerOne, answerTwo, nil
|
||||
}
|
||||
EOT
|
||||
|
||||
touch "$name"/internal/one/solve.go
|
||||
cat <<EOT >> "$name"/internal/one/solve.go
|
||||
package one
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
func Solve(buf []byte) (int, error) {
|
||||
r := bytes.NewReader(buf)
|
||||
err := parseLines(r)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func parseLines(r io.Reader) error {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
EOT
|
||||
|
||||
touch "$name"/internal/one/solve_internal_test.go
|
||||
cat <<EOT >> "$name"/internal/one/solve_internal_test.go
|
||||
package one
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//go:embed testdata/input.txt
|
||||
var data []byte
|
||||
|
||||
func BenchmarkSolve(b *testing.B) {
|
||||
os.Stdout, _ = os.Open(os.DevNull)
|
||||
Solve(data)
|
||||
}
|
||||
EOT
|
||||
|
||||
|
||||
touch "$name"/internal/two/solve.go
|
||||
cat <<EOT >> "$name"/internal/two/solve.go
|
||||
package two
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
func Solve(buf []byte) (int, error) {
|
||||
r := bytes.NewReader(buf)
|
||||
err := parseLines(r)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func parseLines(r io.Reader) error {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
EOT
|
||||
|
||||
touch "$name"/internal/two/solve_internal_test.go
|
||||
cat <<EOT >> "$name"/internal/two/solve_internal_test.go
|
||||
package two
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//go:embed testdata/input.txt
|
||||
var data []byte
|
||||
|
||||
func BenchmarkSolve(b *testing.B) {
|
||||
os.Stdout, _ = os.Open(os.DevNull)
|
||||
Solve(data)
|
||||
}
|
||||
EOT
|
||||
|
||||
|
||||
cd "$name" || exit
|
||||
|
||||
go mod init github.com/onyx-and-iris/aoc2024/"$name"
|
||||
|
||||
MKFILES=../mkfiles.sh
|
||||
[[ -f $MKFILES ]] && ln -s $MKFILES .
|
Loading…
Reference in New Issue
Block a user