mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-30 13:56:37 -04:00
Port to latest libmutton development version (use go-boilerplate)
This commit is contained in:
+12
-10
@@ -6,6 +6,8 @@ import (
|
||||
"os/exec"
|
||||
"reflect"
|
||||
|
||||
"github.com/rwinkhart/go-boilerplate/back"
|
||||
"github.com/rwinkhart/go-boilerplate/front"
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
)
|
||||
@@ -13,7 +15,7 @@ import (
|
||||
// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server.
|
||||
func RenameCli(oldLocationIncomplete string) {
|
||||
// prompt user for new location and rename
|
||||
newLocationIncomplete := input("New location:")
|
||||
newLocationIncomplete := front.Input("New location:")
|
||||
sync.RenameRemoteFromClient(oldLocationIncomplete, newLocationIncomplete, false)
|
||||
|
||||
// exit is done from sync.RenameRemoteFromClient
|
||||
@@ -27,13 +29,13 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// edit the field
|
||||
switch field {
|
||||
case 0:
|
||||
unencryptedEntry[field] = string(inputHidden("Password:"))
|
||||
unencryptedEntry[field] = string(front.InputHidden("Password:"))
|
||||
case 1:
|
||||
unencryptedEntry[field] = input("Username:")
|
||||
unencryptedEntry[field] = front.Input("Username:")
|
||||
case 2:
|
||||
unencryptedEntry[field] = string(inputHidden("TOTP secret:"))
|
||||
unencryptedEntry[field] = string(front.InputHidden("TOTP secret:"))
|
||||
case 3:
|
||||
unencryptedEntry[field] = input("URL:")
|
||||
unencryptedEntry[field] = front.Input("URL:")
|
||||
case 4: // edit notes fields
|
||||
// store note and non-note data separately
|
||||
nonNoteData := unencryptedEntry[:4]
|
||||
@@ -42,7 +44,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
|
||||
core.PrintError("Entry is unchanged", 0, true)
|
||||
back.PrintError("Entry is unchanged", 0, true)
|
||||
}
|
||||
unencryptedEntry = append(nonNoteData, editedNote...)
|
||||
}
|
||||
@@ -66,7 +68,7 @@ func GenUpdate(targetLocation string, hideSecrets bool) {
|
||||
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty).
|
||||
// Returns the edited note and a boolean indicating whether the note was edited.
|
||||
func editNote(baseNote []string) ([]string, bool) {
|
||||
tempFile := core.CreateTempFile()
|
||||
tempFile := back.CreateTempFile()
|
||||
defer func(name string) {
|
||||
_ = os.Remove(name) // error ignored; if the file could be created, it can probably be removed
|
||||
}(tempFile.Name())
|
||||
@@ -102,13 +104,13 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
panic(core.AnsiError + "Failed to write note with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
panic(back.AnsiError + "Failed to write note with " + editor + back.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
}
|
||||
|
||||
// open the tempFile for reading
|
||||
tempFile, err = os.Open(tempFile.Name())
|
||||
if err != nil {
|
||||
panic(core.AnsiError + "Failed to read note written with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
panic(back.AnsiError + "Failed to read note written with " + editor + back.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
}
|
||||
|
||||
// read the edited note from the tempFile
|
||||
@@ -122,7 +124,7 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
_ = tempFile.Close() // error ignored; if the file could be opened, it can probably be closed
|
||||
|
||||
// remove trailing empty strings from the edited note
|
||||
note = core.RemoveTrailingEmptyStrings(note)
|
||||
note = back.RemoveTrailingEmptyStrings(note)
|
||||
|
||||
// clamp trailing whitespace in each note line
|
||||
core.ClampTrailingWhitespace(note)
|
||||
|
||||
Reference in New Issue
Block a user