Refactor for better modularity (share more code among edit functions, rename "offline" package to "backend"

This commit is contained in:
2024-04-15 18:16:05 -04:00
parent b784fd8bd7
commit 2cf786b2d7
31 changed files with 156 additions and 156 deletions
+11 -11
View File
@@ -5,7 +5,7 @@ import (
"os"
"strings"
"github.com/rwinkhart/MUTN/src/offline"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/charmbracelet/glamour"
)
@@ -22,24 +22,24 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) {
// if the first field (password) is not empty, print it
if decryptedEntry[0] != "" {
if !hidePassword {
fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + offline.AnsiReset + "\n\n")
fmt.Print(ansiDirectoryHeader + "Password:" + backend.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + backend.AnsiReset + "\n\n")
} else {
fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + offline.AnsiReset + "\n\n")
fmt.Print(ansiDirectoryHeader + "Password:" + backend.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + backend.AnsiReset + "\n\n")
}
}
case 1:
// if the second field (username) is not empty, print it
if decryptedEntry[1] != "" {
fmt.Print(ansiDirectoryHeader + "Username:" + offline.AnsiReset + "\n" + decryptedEntry[1] + "\n\n")
fmt.Print(ansiDirectoryHeader + "Username:" + backend.AnsiReset + "\n" + decryptedEntry[1] + "\n\n")
}
case 2:
// if the third field (url) is not empty, print it
if decryptedEntry[2] != "" {
fmt.Print(ansiDirectoryHeader + "URL:" + offline.AnsiReset + "\n" + decryptedEntry[2] + "\n\n")
fmt.Print(ansiDirectoryHeader + "URL:" + backend.AnsiReset + "\n" + decryptedEntry[2] + "\n\n")
}
case 3:
// print the notes header
fmt.Println(ansiDirectoryHeader + "Notes:" + offline.AnsiReset)
fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset)
// combine remaining fields into a single string (for markdown rendering)
var markdownNotes []string
@@ -57,17 +57,17 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) {
}
}
if sync && !offline.Windows {
if sync && !backend.Windows {
SshypSync() // TODO Remove after native sync is implemented
}
os.Exit(0)
}
// EntryReaderShortcut is a shortcut for EntryReader that decrypts a GPG-encrypted file and prints the contents
func EntryReaderShortcut(targetLocation string, hidePassword bool, sync bool) {
if isFile, _ := offline.TargetIsFile(targetLocation, true, 2); isFile {
EntryReader(offline.DecryptGPG(targetLocation), hidePassword, sync)
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader
func EntryReaderDecrypt(targetLocation string, hidePassword bool, sync bool) {
if isFile, _ := backend.TargetIsFile(targetLocation, true, 2); isFile {
EntryReader(backend.DecryptGPG(targetLocation), hidePassword, sync)
}
// do not exit, as this is the job of EntryReader
}