From 46d032cd21b0e8e2c94a32333d3805ec76980cca Mon Sep 17 00:00:00 2001 From: ewy Date: Mon, 1 Jun 2026 18:47:44 +0200 Subject: add man(1) generation --- spool/exit.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 spool/exit.go (limited to 'spool/exit.go') 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, + ) +} -- cgit v1.3.1