chore: add day 9
This commit is contained in:
parent
1045fcba4c
commit
b7e576729c
12
tools.go
12
tools.go
|
@ -4,12 +4,13 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
|
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
Log("Usage:", os.Args[0], "FILE")
|
Log("Usage:", filepath.Base(os.Args[0]), "FILE")
|
||||||
os.Exit(22)
|
os.Exit(22)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +24,15 @@ func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
|
||||||
return run(scan)
|
return run(scan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MustResult[T any](result T, err error) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("ERR", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
Log("result", result)
|
||||||
|
}
|
||||||
|
|
||||||
func Log(v ...any) { fmt.Fprintln(os.Stderr, v...) }
|
func Log(v ...any) { fmt.Fprintln(os.Stderr, v...) }
|
||||||
func Logf(format string, v ...any) {
|
func Logf(format string, v ...any) {
|
||||||
if !strings.HasSuffix(format, "\n") {
|
if !strings.HasSuffix(format, "\n") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user