diff --git a/tools.go b/tools.go index 05f87aa..baae9ed 100644 --- a/tools.go +++ b/tools.go @@ -4,12 +4,13 @@ import ( "bufio" "fmt" "os" + "path/filepath" "strings" ) func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) { if len(os.Args) != 2 { - Log("Usage:", os.Args[0], "FILE") + Log("Usage:", filepath.Base(os.Args[0]), "FILE") os.Exit(22) } @@ -23,6 +24,15 @@ func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) { 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 Logf(format string, v ...any) { if !strings.HasSuffix(format, "\n") {