From e2d79d4ce3822b096a3bcc4a292b7ca174dd066c Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 1 Feb 2025 21:01:35 -0500 Subject: [PATCH] Make use of libmutton's new core.PrintError utility function --- go.mod | 2 +- go.sum | 4 ++-- mutn.go | 4 +--- src/cli/add.go | 5 +---- src/cli/edit.go | 4 +--- src/cli/init.go | 5 ++--- src/cli/utilitiesMisc.go | 3 +-- 7 files changed, 9 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 8a890df..1cd8658 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514 github.com/charmbracelet/glamour v0.7.0 - github.com/rwinkhart/libmutton v0.2.5-0.20250126231254-eb2b349697ed + github.com/rwinkhart/libmutton v0.2.5-0.20250202014803-e9d0c3704362 golang.org/x/term v0.28.0 ) diff --git a/go.sum b/go.sum index 7320416..a528186 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rwinkhart/convertroman v0.2.0 h1:otUm939eXT77q/Lr31mJtMwVWEw0RjEUB71gO65h9OM= github.com/rwinkhart/convertroman v0.2.0/go.mod h1:Af6HqvX0EIM4Y3HcnNXbbRey1dLasGB7WU0+3Cowgmw= -github.com/rwinkhart/libmutton v0.2.5-0.20250126231254-eb2b349697ed h1:MNCsowWbcO0okuRNF3VDQ/quNju0CUU8shUCzIxQGsk= -github.com/rwinkhart/libmutton v0.2.5-0.20250126231254-eb2b349697ed/go.mod h1:kn7x0901qFyX1/HBxJf287zoySZkxKRMObKigLiI5Ok= +github.com/rwinkhart/libmutton v0.2.5-0.20250202014803-e9d0c3704362 h1:9D8OqhGvh/f7l6z/owPwwgV9FS5SbLCa+CJfnyi27S4= +github.com/rwinkhart/libmutton v0.2.5-0.20250202014803-e9d0c3704362/go.mod h1:kn7x0901qFyX1/HBxJf287zoySZkxKRMObKigLiI5Ok= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/mutn.go b/mutn.go index b7b729c..27f3635 100644 --- a/mutn.go +++ b/mutn.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "strings" @@ -164,8 +163,7 @@ func main() { case "init": cli.TempInitCli() case "tweak": - fmt.Println(core.AnsiError + "\"tweak\" is not yet implemented" + core.AnsiReset) - os.Exit(0) + core.PrintError("\"tweak\" is not yet implemented", 0, true) case "copy": cli.HelpCopy() case "edit": diff --git a/src/cli/add.go b/src/cli/add.go index 28d5258..1c7fc8e 100644 --- a/src/cli/add.go +++ b/src/cli/add.go @@ -1,8 +1,6 @@ package cli import ( - "fmt" - "os" "strings" "github.com/rwinkhart/libmutton/core" @@ -14,8 +12,7 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) { // ensure target location does not already exist _, isAccessible := core.TargetIsFile(targetLocation, false, 0) if isAccessible { - fmt.Println(core.AnsiError + "Target location already exists" + core.AnsiReset) - os.Exit(core.ErrorTargetExists) + core.PrintError("Target location already exists", core.ErrorTargetExists, true) } // ensure target containing directory exists and is a directory (not a file) diff --git a/src/cli/edit.go b/src/cli/edit.go index 72c1cb6..6d910e9 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -2,7 +2,6 @@ package cli import ( "bufio" - "fmt" "os" "os/exec" "reflect" @@ -43,8 +42,7 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) { // edit the note editedNote, noteEdited := editNote(noteData) if !noteEdited { // exit early if the note was not edited - fmt.Println(core.AnsiError + "Entry is unchanged" + core.AnsiReset) - os.Exit(0) + core.PrintError("Entry is unchanged", 0, true) } unencryptedEntry = append(nonNoteData, editedNote...) } diff --git a/src/cli/init.go b/src/cli/init.go index de4a65e..805984b 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -21,8 +21,7 @@ func TempInitCli() { uidSlice := core.GpgUIDListGen() gpgIDInt := inputMenuGen("Select GPG key:", uidSlice) if gpgIDInt == 0 { - fmt.Println(core.AnsiError + "No GPG keys found - please generate one" + core.AnsiReset) - os.Exit(core.ErrorTargetNotFound) + core.PrintError("No GPG keys found - please generate one", core.ErrorTargetNotFound, true) } gpgID = uidSlice[gpgIDInt-1] } @@ -47,7 +46,7 @@ func TempInitCli() { sshKey = cmp.Or(core.ExpandPathWithHome(input("SSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey) sshKeyIsFile, _ = core.TargetIsFile(sshKey, false, 0) if !sshKeyIsFile { - fmt.Println(core.AnsiError+"SSH identity file not found:", sshKey+core.AnsiReset) + fmt.Println(core.AnsiError+"SSH identity file not found:", sshKey+core.AnsiReset) // do not exit after error (allow user to retry) } } diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 8f09e62..f22a653 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -73,8 +73,7 @@ func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets fmt.Println(AnsiBold + "\nEntry Preview:" + core.AnsiReset) EntryReader(unencryptedEntry, hideSecrets, true) } else { - fmt.Println(core.AnsiError + "No data supplied for entry" + core.AnsiReset) - os.Exit(core.ErrorTargetNotFound) + core.PrintError("No data supplied for entry", core.ErrorTargetNotFound, true) } }