summaryrefslogtreecommitdiff
path: root/spool/spool.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-06-01 18:47:44 +0200
committerewy <ewy0@protonmail.com>2026-06-01 18:47:44 +0200
commit46d032cd21b0e8e2c94a32333d3805ec76980cca (patch)
treefbb8aed5c5a501aca1309f62a9d4440ca949ce4c /spool/spool.go
parent7585a488b7b1e1812f7ebf50107139e2fd65f035 (diff)
add man(1) generation
Diffstat (limited to 'spool/spool.go')
-rw-r--r--spool/spool.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/spool/spool.go b/spool/spool.go
index e7b13e9..4335d50 100644
--- a/spool/spool.go
+++ b/spool/spool.go
@@ -3,6 +3,9 @@ package spool
import (
"fmt"
"os"
+ "reflect"
+ "runtime/debug"
+ "strings"
)
var (
@@ -10,6 +13,10 @@ var (
Stdout = os.Stdout
)
+type empty struct{}
+
+const PanicErrorCode = 8
+
var Print = func(format string, values ...any) (any, error) {
return fmt.Fprintf(Stdout, format, values...)
}
@@ -17,3 +24,19 @@ var Print = func(format string, values ...any) (any, error) {
var Warn = func(format string, values ...any) (any, error) {
return fmt.Fprintf(Stderr, format, values...)
}
+
+var Panic = func(code ExitCode, format string, values ...any) (any, error) {
+ pkg := reflect.TypeOf(empty{}).PkgPath()
+ v, err := fmt.Fprintf(Stderr, format, values...)
+ st := strings.Split(string(debug.Stack()), "\n")
+ for i, l := range st {
+ if strings.Contains(l, pkg) {
+ st = st[i:]
+ break
+ }
+ }
+
+ _, _ = Warn("%s\n", strings.Join(st, "\n"))
+ os.Exit(PanicErrorCode)
+ return v, err
+}