Merge EditEntryNote into EditEntryField

This commit is contained in:
2024-04-16 11:20:22 -04:00
parent 2cf786b2d7
commit d4360c06ba
2 changed files with 13 additions and 33 deletions
+1 -10
View File
@@ -93,16 +93,7 @@ func main() {
case "url", "-l": case "url", "-l":
field = 2 field = 2
case "note", "-n": case "note", "-n":
if argsCount == 4 { field = 3
cli.EditEntryNote(targetLocation, true)
} else {
switch args[4] {
case "show", "-s":
cli.EditEntryNote(targetLocation, false)
default:
cli.EditEntryNote(targetLocation, true)
}
}
case "rename", "-r": case "rename", "-r":
cli.RenameCli(targetLocation) cli.RenameCli(targetLocation)
default: default:
+3 -14
View File
@@ -35,21 +35,9 @@ func EditEntryField(targetLocation string, hidePassword bool, field int) {
unencryptedEntry[field] = input("Username:") unencryptedEntry[field] = input("Username:")
case 2: case 2:
unencryptedEntry[field] = input("URL:") unencryptedEntry[field] = input("URL:")
} case 3: // edit notes fields
// store note and non-note data separately
// write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hidePassword)
}
// EditEntryNote edits the note of an entry at targetLocation (user input)
func EditEntryNote(targetLocation string, hidePassword bool) {
// fetch old entry data (with all required lines present)
unencryptedEntry := backend.GetOldEntryData(targetLocation, 2)
// store non-note data separately
nonNoteData := unencryptedEntry[:3] nonNoteData := unencryptedEntry[:3]
// store note data separately
noteData := unencryptedEntry[3:] noteData := unencryptedEntry[3:]
// edit the note // edit the note
@@ -59,6 +47,7 @@ func EditEntryNote(targetLocation string, hidePassword bool) {
os.Exit(1) os.Exit(1)
} }
unencryptedEntry = append(nonNoteData, editedNote...) unencryptedEntry = append(nonNoteData, editedNote...)
}
// write and preview the modified entry // write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hidePassword) writeEntryCLI(targetLocation, unencryptedEntry, hidePassword)