diff --git a/mutn.go b/mutn.go index 43d9213..dc7ecae 100644 --- a/mutn.go +++ b/mutn.go @@ -28,14 +28,14 @@ func main() { // entry reader shortcut (if no other arguments are supplied) if argsCount == 2 { - cli.EntryReaderDecrypt(targetLocation, true, false) + cli.EntryReaderDecrypt(targetLocation, true) // 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.EntryReaderDecrypt(targetLocation, false, false) + cli.EntryReaderDecrypt(targetLocation, false) case "copy": backend.CopyArgument(targetLocation, 0, args[0]) case "edit": @@ -157,13 +157,6 @@ func main() { case "clipclear": backend.ClipClearArgument() 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) case "init": cli.TempInitCli() diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 3bbbb52..5196b6e 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/rwinkhart/MUTN/src/sync" "os" "strings" @@ -13,7 +14,7 @@ import ( const ansiShownPassword = "\033[38;5;10m" // 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() for i := range decryptedEntry { @@ -57,17 +58,17 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) { } } - if sync && !backend.IsWindows { - SshypSync() // TODO Remove after native sync is implemented + if syncEnabled { + sync.RunJob(false) } os.Exit(0) } // 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 { - 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 } diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 2ebad10..d4f5dbb 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -6,17 +6,9 @@ import ( "github.com/rwinkhart/MUTN/src/backend" "golang.org/x/crypto/ssh/terminal" "os" - "os/exec" "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 func input(prompt string) string { fmt.Print("\n" + prompt + " ") diff --git a/src/sync/client.go b/src/sync/client.go index 672f7b0..1b5d087 100644 --- a/src/sync/client.go +++ b/src/sync/client.go @@ -151,8 +151,12 @@ func getRemoteDataFromClient(manualSync bool) (map[string]int64, []string, []str // get remote output over SSH clientDeviceID, _ := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices") if len(clientDeviceID) == 0 { - fmt.Println(backend.AnsiError + "Sync failed - No device ID found; run \"mutn init\" to generate a device ID" + backend.AnsiReset) - os.Exit(1) + if manualSync { + fmt.Println(backend.AnsiError + "Sync failed - No device ID found; run \"mutn init\" to generate a device ID" + backend.AnsiReset) + os.Exit(1) + } else { + os.Exit(0) // exit silently if the sync job was called automatically, as the user may just be in offline mode + } } output := GetSSHOutput("libmuttonserver fetch "+clientDeviceID[0].Name()+" "+strconv.FormatBool(backend.IsWindows), manualSync)