mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Merge EditEntryNote into EditEntryField
This commit is contained in:
@@ -93,16 +93,7 @@ func main() {
|
||||
case "url", "-l":
|
||||
field = 2
|
||||
case "note", "-n":
|
||||
if argsCount == 4 {
|
||||
cli.EditEntryNote(targetLocation, true)
|
||||
} else {
|
||||
switch args[4] {
|
||||
case "show", "-s":
|
||||
cli.EditEntryNote(targetLocation, false)
|
||||
default:
|
||||
cli.EditEntryNote(targetLocation, true)
|
||||
}
|
||||
}
|
||||
field = 3
|
||||
case "rename", "-r":
|
||||
cli.RenameCli(targetLocation)
|
||||
default:
|
||||
|
||||
+12
-23
@@ -35,35 +35,24 @@ func EditEntryField(targetLocation string, hidePassword bool, field int) {
|
||||
unencryptedEntry[field] = input("Username:")
|
||||
case 2:
|
||||
unencryptedEntry[field] = input("URL:")
|
||||
case 3: // edit notes fields
|
||||
// store note and non-note data separately
|
||||
nonNoteData := unencryptedEntry[:3]
|
||||
noteData := unencryptedEntry[3:]
|
||||
|
||||
// edit the note
|
||||
editedNote, noteEdited := editNote(noteData)
|
||||
if !noteEdited { // exit early if the note was not edited
|
||||
fmt.Println(backend.AnsiError + "Entry is unchanged" + backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
unencryptedEntry = append(nonNoteData, editedNote...)
|
||||
}
|
||||
|
||||
// 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]
|
||||
|
||||
// store note data separately
|
||||
noteData := unencryptedEntry[3:]
|
||||
|
||||
// edit the note
|
||||
editedNote, noteEdited := editNote(noteData)
|
||||
if !noteEdited { // exit early if the note was not edited
|
||||
fmt.Println(backend.AnsiError + "Entry is unchanged" + backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
unencryptedEntry = append(nonNoteData, editedNote...)
|
||||
|
||||
// write and preview the modified entry
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hidePassword)
|
||||
}
|
||||
|
||||
// GenUpdate generates a new password for an entry at targetLocation (user input)
|
||||
func GenUpdate(targetLocation string, hidePassword bool) {
|
||||
// fetch old entry data
|
||||
|
||||
Reference in New Issue
Block a user