upd scaffold

This commit is contained in:
onyx-and-iris 2024-12-05 18:24:29 +00:00
parent 886679a095
commit e67369041e

View File

@ -57,14 +57,135 @@ func main() {
EOT
touch "$name"/solve.go
cat <<EOT >> "$name"/makefile
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(data []byte) (int, int, error) {
return 0, 0, nil
answerOne, err := one.Solve(data)
if err != nil {
return 0, 0, err
}
answerTwo, err := two.Solve(data)
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(data []byte) (int, error) {
r := bytes.NewReader(data)
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(data []byte) (int, error) {
r := bytes.NewReader(data)
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"