summaryrefslogtreecommitdiff
path: root/spool/exit.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/exit.go
parent7585a488b7b1e1812f7ebf50107139e2fd65f035 (diff)
add man(1) generation
Diffstat (limited to 'spool/exit.go')
-rw-r--r--spool/exit.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/spool/exit.go b/spool/exit.go
new file mode 100644
index 0000000..efe9d4e
--- /dev/null
+++ b/spool/exit.go
@@ -0,0 +1,60 @@
+package spool
+
+import (
+ "github.com/ewy1/pik/paths"
+ "os"
+)
+
+type ExitCode struct {
+ Value int
+ Message string
+}
+
+var (
+ Success = New(0, "succesful")
+ Cancelled = New(0, "operation cancelled by user")
+ NotFoundFailure = Cancelled.Next("target not found")
+ FatalReadFailure = NotFoundFailure.Next("fatal failure during initialization")
+ FatalWriteFailure = FatalReadFailure.Next("fatal failure during file write")
+ WorkingDirectoryFailure = FatalWriteFailure.Next("could not get current working directory")
+ OpenRootFailure = WorkingDirectoryFailure.Next("failed to init root directory")
+ RootFsFailure = OpenRootFailure.Next("failed to make fs from root")
+ CacheReadFailure = RootFsFailure.Next("failed to read cache (from " + paths.ContextsFile.String())
+ HydrationFailure = CacheReadFailure.Next("a hydrator failed")
+ MenuFailure = HydrationFailure.Next("error during menu")
+ NoTargetsFailure = MenuFailure.Next("no targets found")
+ NoEditorFailure = NoTargetsFailure.Next("$EDITOR not set")
+ NoDebugInfo = NoEditorFailure.Next("could not read debug info")
+ ManFailure = New(120, "failure to generate manual pages")
+ UnknownShellFailure = New(110, "unable to detect shell type through $SHELL")
+ CompletionAlreadyInstalledFailure = UnknownShellFailure.Next("completion seems already installed")
+ CompletionFailure = CompletionAlreadyInstalledFailure.Next("failed to install completion")
+ ProfilingFailure = CompletionFailure.Next("failed to initialize profiler")
+)
+
+var Codes []ExitCode
+var CodeMap = make(map[int]*ExitCode)
+
+func New(num int, message string) ExitCode {
+ if CodeMap[num] != nil && num != 0 {
+ _, _ = Warn("redefined error code: %v", num)
+ }
+ c := ExitCode{
+ Value: num,
+ Message: message,
+ }
+ Codes = append(Codes, c)
+ CodeMap[num] = &c
+ return c
+}
+
+func (e ExitCode) Exit() {
+ os.Exit(e.Value)
+}
+
+func (e ExitCode) Next(message string) ExitCode {
+ return New(
+ e.Value+1,
+ message,
+ )
+}