Assign error-specific exit codes to constants

This commit is contained in:
2024-08-13 20:48:20 -04:00
parent a1c9827c04
commit 4c54349b39
17 changed files with 90 additions and 92 deletions
+6 -6
View File
@@ -21,14 +21,14 @@ func copyField(executableName, copySubject string) {
cmd = exec.Command("xclip", "-sel", "c")
} else {
fmt.Println(AnsiError + "Clipboard platform could not be determined - Note that the clipboard does not function in a raw TTY" + AnsiReset)
os.Exit(110)
os.Exit(ErrorClipboard)
}
writeToStdin(cmd, copySubject)
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError+"Failed to copy to clipboard:", err.Error()+AnsiReset)
os.Exit(110)
os.Exit(ErrorClipboard)
}
// launch clipboard clearing process if executableName is provided
@@ -38,7 +38,7 @@ func copyField(executableName, copySubject string) {
err = cmd.Start()
if err != nil {
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - Does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
os.Exit(110)
os.Exit(ErrorClipboard)
}
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
}
@@ -59,14 +59,14 @@ func clipClear(oldContents string) {
cmdPaste = exec.Command("xclip", "-o", "-sel", "c")
} else {
fmt.Println(AnsiError + "Clipboard platform could not be determined - Neither $WAYLAND_DISPLAY nor $DISPLAY are set" + AnsiReset)
os.Exit(110)
os.Exit(ErrorClipboard)
}
// read current clipboard contents
newContents, err := cmdPaste.Output()
if err != nil {
fmt.Println(AnsiError+"Failed to read clipboard contents:", err.Error()+AnsiReset)
os.Exit(110)
os.Exit(ErrorClipboard)
}
// clear clipboard if contents have not been modified
@@ -74,7 +74,7 @@ func clipClear(oldContents string) {
err = cmdClear.Run()
if err != nil {
fmt.Println(AnsiError+"Failed to clear clipboard:", err.Error()+AnsiReset)
os.Exit(110)
os.Exit(ErrorClipboard)
}
}
os.Exit(0) // use os.Exit instead of core.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)