Promote native sync to replace sshyp-based sync on all platforms

This commit is contained in:
2024-05-17 19:49:49 -04:00
parent 1230c8a437
commit bc51f20d41
3 changed files with 8 additions and 22 deletions
+2 -9
View File
@@ -28,14 +28,14 @@ func main() {
// entry reader shortcut (if no other arguments are supplied) // entry reader shortcut (if no other arguments are supplied)
if argsCount == 2 { if argsCount == 2 {
cli.EntryReaderDecrypt(targetLocation, true, false) cli.EntryReaderDecrypt(targetLocation, true)
// perform other operations on the entry (if other arguments are supplied) // perform other operations on the entry (if other arguments are supplied)
} else if argsCount == 3 || (argsCount == 4 && (args[3] == "show" || args[3] == "-s")) { } 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) if argsCount == 3 { // default to "password" if no field is specified (for copy, edit, and add)
switch args[2] { switch args[2] {
case "show", "-s": case "show", "-s":
cli.EntryReaderDecrypt(targetLocation, false, false) cli.EntryReaderDecrypt(targetLocation, false)
case "copy": case "copy":
backend.CopyArgument(targetLocation, 0, args[0]) backend.CopyArgument(targetLocation, 0, args[0])
case "edit": case "edit":
@@ -157,13 +157,6 @@ func main() {
case "clipclear": case "clipclear":
backend.ClipClearArgument() backend.ClipClearArgument()
case "sync": case "sync":
if !backend.Windows {
cli.SshypSync() // TODO Remove after native sync is implemented
} else {
fmt.Println(backend.AnsiError + "\"sync\" is not yet implemented" + backend.AnsiReset)
}
os.Exit(0)
case "synctest": // TODO Remove after native sync is implemented
sync.RunJob(true) sync.RunJob(true)
case "init": case "init":
cli.TempInitCli() cli.TempInitCli()
+6 -5
View File
@@ -2,6 +2,7 @@ package cli
import ( import (
"fmt" "fmt"
"github.com/rwinkhart/MUTN/src/sync"
"os" "os"
"strings" "strings"
@@ -13,7 +14,7 @@ import (
const ansiShownPassword = "\033[38;5;10m" const ansiShownPassword = "\033[38;5;10m"
// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format // EntryReader prints the decrypted contents of a libmutton entry in a human-readable format
func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) { func EntryReader(decryptedEntry []string, hidePassword bool, syncEnabled bool) {
fmt.Println() fmt.Println()
for i := range decryptedEntry { for i := range decryptedEntry {
@@ -57,17 +58,17 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) {
} }
} }
if sync && !backend.IsWindows { if syncEnabled {
SshypSync() // TODO Remove after native sync is implemented sync.RunJob(false)
} }
os.Exit(0) os.Exit(0)
} }
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader // 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) { func EntryReaderDecrypt(targetLocation string, hidePassword bool) {
if isFile, _ := backend.TargetIsFile(targetLocation, true, 2); isFile { if isFile, _ := backend.TargetIsFile(targetLocation, true, 2); isFile {
EntryReader(backend.DecryptGPG(targetLocation), hidePassword, sync) EntryReader(backend.DecryptGPG(targetLocation), hidePassword, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified
} }
// do not exit, as this is the job of EntryReader // do not exit, as this is the job of EntryReader
} }
-8
View File
@@ -6,17 +6,9 @@ import (
"github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/backend"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
"os" "os"
"os/exec"
"strings" "strings"
) )
// TODO remove after native sync is implemented
func SshypSync() {
cmd := exec.Command("sshyp", "sync")
cmd.Stdout = os.Stdout
cmd.Run()
}
// input prompts the user for input and returns the input as a string // input prompts the user for input and returns the input as a string
func input(prompt string) string { func input(prompt string) string {
fmt.Print("\n" + prompt + " ") fmt.Print("\n" + prompt + " ")