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
+18 -18
View File
@@ -2,8 +2,8 @@ package main
import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/cli"
"github.com/rwinkhart/MUTN/src/offline"
"os"
"strings"
)
@@ -23,34 +23,34 @@ func main() {
if strings.HasPrefix(args[1], "/") {
// store location of target entry
targetLocation := offline.TargetLocationFormat(args[1][1:])
targetLocation := backend.TargetLocationFormat(args[1][1:])
// entry reader shortcut (if no other arguments are supplied)
if argsCount == 2 {
cli.EntryReaderShortcut(targetLocation, true, false)
cli.EntryReaderDecrypt(targetLocation, true, false)
// perform other operations on the entry (if other arguments are supplied)
} else if argsCount == 3 || (argsCount == 4 && (args[3] == "show" || args[3] == "-s")) {
if argsCount == 3 { // default to "password" if no field is specified (for copy, edit, and add)
switch args[2] {
case "show", "-s":
cli.EntryReaderShortcut(targetLocation, false, false)
cli.EntryReaderDecrypt(targetLocation, false, false)
case "copy":
offline.CopyArgument(targetLocation, 0, args[0])
backend.CopyArgument(targetLocation, 0, args[0])
case "edit":
cli.EditEntry(targetLocation, true, 0)
cli.EditEntryField(targetLocation, true, 0)
case "gen":
cli.AddEntry(targetLocation, true, 1)
case "add":
cli.AddEntry(targetLocation, true, 0)
case "shear":
offline.Shear(targetLocation)
backend.Shear(targetLocation)
default:
cli.HelpMain()
}
} else { // handle "show" or "-s" argument for gen, edit, and add
switch args[2] {
case "edit":
cli.EditEntry(targetLocation, false, 0)
cli.EditEntryField(targetLocation, false, 0)
case "gen":
cli.AddEntry(targetLocation, false, 1)
case "add":
@@ -82,7 +82,7 @@ func main() {
default:
cli.HelpCopy()
}
offline.CopyArgument(targetLocation, field, args[0])
backend.CopyArgument(targetLocation, field, args[0])
case "edit":
var field int // indicates which field to edit
switch args[3] {
@@ -109,13 +109,13 @@ func main() {
cli.HelpEdit()
}
if argsCount == 4 {
cli.EditEntry(targetLocation, true, field)
cli.EditEntryField(targetLocation, true, field)
} else {
switch args[4] {
case "show", "-s":
cli.EditEntry(targetLocation, false, field)
cli.EditEntryField(targetLocation, false, field)
default:
cli.EditEntry(targetLocation, true, field)
cli.EditEntryField(targetLocation, true, field)
}
}
case "gen":
@@ -151,7 +151,7 @@ func main() {
case "note", "-n":
cli.AddEntry(targetLocation, true, 2)
case "folder", "-f":
offline.AddFolder(targetLocation)
backend.AddFolder(targetLocation)
default:
cli.HelpAdd()
}
@@ -164,20 +164,20 @@ func main() {
} else {
switch args[1] {
case "clipclear":
offline.ClipClearArgument()
backend.ClipClearArgument()
case "sync":
if !offline.Windows {
if !backend.Windows {
cli.SshypSync() // TODO Remove after native sync is implemented
} else {
fmt.Println(offline.AnsiError + "\"sync\" is not yet implemented" + offline.AnsiReset)
fmt.Println(backend.AnsiError + "\"sync\" is not yet implemented" + backend.AnsiReset)
}
os.Exit(0)
case "init":
cli.TempInitCli()
case "tweak":
fmt.Println(offline.AnsiError + "\"tweak\" is not yet implemented" + offline.AnsiReset)
fmt.Println(backend.AnsiError + "\"tweak\" is not yet implemented" + backend.AnsiReset)
os.Exit(0)
// TODO offline.Tweak()
// TODO backend.Tweak()
case "copy":
cli.HelpCopy()
case "edit":