Make use of libmutton's new core.PrintError utility function

This commit is contained in:
2025-02-01 21:01:35 -05:00
parent d323f2f75a
commit e2d79d4ce3
7 changed files with 9 additions and 18 deletions
+1 -1
View File
@@ -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
)
+2 -2
View File
@@ -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=
+1 -3
View File
@@ -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":
+1 -4
View File
@@ -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)
+1 -3
View File
@@ -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...)
}
+2 -3
View File
@@ -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)
}
}
+1 -2
View File
@@ -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)
}
}