Standardize some variable names; port to latest libmutton development version

This commit is contained in:
2025-05-31 17:54:12 -04:00
parent 1370f5cd80
commit eda08ad9b6
5 changed files with 25 additions and 25 deletions
+5 -5
View File
@@ -15,7 +15,7 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
back.PrintError("Failed to add entry: "+err.Error(), back.ErrorWrite, true)
}
var unencryptedEntry []string
var decryptedEntry []string
if entryType < 2 {
username := front.Input("Username:")
@@ -32,15 +32,15 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
url := front.Input("URL:")
if front.InputBinary("Add a note to this entry?") {
note, _ := editNote([]string{})
unencryptedEntry = append([]string{password, username, totp, url}, note...)
decryptedEntry = append([]string{password, username, totp, url}, note...)
} else {
unencryptedEntry = []string{password, username, totp, url}
decryptedEntry = []string{password, username, totp, url}
}
} else {
note, _ := editNote([]string{})
unencryptedEntry = append([]string{"", "", "", ""}, note...)
decryptedEntry = append([]string{"", "", "", ""}, note...)
}
// write and preview the new entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets)
writeEntryCLI(targetLocation, decryptedEntry, hideSecrets)
}
+13 -13
View File
@@ -28,7 +28,7 @@ func RenameCli(oldLocationIncomplete string) {
// EditEntryField edits a field of an entry at targetLocation (user input).
func EditEntryField(targetLocation string, hideSecrets bool, field int) {
// fetch old entry data (with all required lines present)
unencryptedEntry, err := core.GetOldEntryData(targetLocation, field)
decryptedEntry, err := core.GetOldEntryData(targetLocation, field)
if err != nil {
back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true)
}
@@ -36,43 +36,43 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
// edit the field
switch field {
case 0:
unencryptedEntry[field] = string(front.InputHidden("Password:"))
decryptedEntry[field] = string(front.InputHidden("Password:"))
case 1:
unencryptedEntry[field] = front.Input("Username:")
decryptedEntry[field] = front.Input("Username:")
case 2:
unencryptedEntry[field] = string(front.InputHidden("TOTP secret:"))
decryptedEntry[field] = string(front.InputHidden("TOTP secret:"))
case 3:
unencryptedEntry[field] = front.Input("URL:")
decryptedEntry[field] = front.Input("URL:")
case 4: // edit notes fields
// store note and non-note data separately
nonNoteData := unencryptedEntry[:4]
noteData := unencryptedEntry[4:]
fieldsMain := decryptedEntry[:4]
fieldsNote := decryptedEntry[4:]
// edit the note
editedNote, noteEdited := editNote(noteData)
editedNote, noteEdited := editNote(fieldsNote)
if !noteEdited { // exit early if the note was not edited
back.PrintError("Entry is unchanged", 0, true)
}
unencryptedEntry = append(nonNoteData, editedNote...)
decryptedEntry = append(fieldsMain, editedNote...)
}
// write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets)
writeEntryCLI(targetLocation, decryptedEntry, hideSecrets)
}
// GenUpdate generates a new password for an entry at targetLocation (user input).
func GenUpdate(targetLocation string, hideSecrets bool) {
// fetch old entry data
unencryptedEntry, err := core.GetOldEntryData(targetLocation, 0)
decryptedEntry, err := core.GetOldEntryData(targetLocation, 0)
if err != nil {
back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true)
}
// generate a new password
unencryptedEntry[0] = inputPasswordGen()
decryptedEntry[0] = inputPasswordGen()
// write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets)
writeEntryCLI(targetLocation, decryptedEntry, hideSecrets)
}
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty).
+4 -4
View File
@@ -28,16 +28,16 @@ func inputPasswordGen() string {
}
// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied).
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets bool) {
if core.EntryIsNotEmpty(unencryptedEntry) {
func writeEntryCLI(targetLocation string, decryptedEntry []string, hideSecrets bool) {
if core.EntryIsNotEmpty(decryptedEntry) {
// write the entry to the target location
err := core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n")))
err := core.WriteEntry(targetLocation, []byte(strings.Join(decryptedEntry, "\n")))
if err != nil {
back.PrintError("Failed to write entry: "+err.Error(), back.ErrorWrite, true)
}
// preview the entry
fmt.Println(back.AnsiBold + "\nEntry Preview:" + back.AnsiReset)
EntryReader(unencryptedEntry, hideSecrets, true)
EntryReader(decryptedEntry, hideSecrets, true)
} else {
back.PrintError("No data supplied for entry", back.ErrorTargetNotFound, true)
}