mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 21:06:39 -04:00
Port to latest libmutton development version; address JetBrains warnings
This commit is contained in:
+5
-1
@@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/rwinkhart/go-boilerplate/back"
|
||||
"github.com/rwinkhart/go-boilerplate/front"
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
)
|
||||
@@ -9,7 +10,10 @@ import (
|
||||
// Requires: entryType (0 = standard password entry, 1 = auto-generated password entry, 2 = note-only entry).
|
||||
func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
|
||||
// ensure targetLocation is valid
|
||||
core.EntryAddPrecheck(targetLocation)
|
||||
_, err := core.EntryAddPrecheck(targetLocation)
|
||||
if err != nil {
|
||||
back.PrintError("Failed to add entry: "+err.Error(), back.ErrorWrite, true)
|
||||
}
|
||||
|
||||
var unencryptedEntry []string
|
||||
|
||||
|
||||
+12
-3
@@ -17,7 +17,10 @@ import (
|
||||
func RenameCli(oldLocationIncomplete string) {
|
||||
// prompt user for new location and rename
|
||||
newLocationIncomplete := front.Input("New location:")
|
||||
syncclient.RenameRemoteFromClient(oldLocationIncomplete, newLocationIncomplete, false)
|
||||
err := syncclient.RenameRemoteFromClient(oldLocationIncomplete, newLocationIncomplete, false)
|
||||
if err != nil {
|
||||
back.PrintError("Failed to rename entry: "+err.Error(), back.ErrorWrite, true)
|
||||
}
|
||||
|
||||
// exit is done from sync.RenameRemoteFromClient
|
||||
}
|
||||
@@ -25,7 +28,10 @@ func RenameCli(oldLocationIncomplete string) {
|
||||
// EditEntryField edits a field of an entry at targetLocation (user input).
|
||||
func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// fetch old entry data (with all required lines present)
|
||||
unencryptedEntry := core.GetOldEntryData(targetLocation, field)
|
||||
unencryptedEntry, err := core.GetOldEntryData(targetLocation, field)
|
||||
if err != nil {
|
||||
back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true)
|
||||
}
|
||||
|
||||
// edit the field
|
||||
switch field {
|
||||
@@ -57,7 +63,10 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// GenUpdate generates a new password for an entry at targetLocation (user input).
|
||||
func GenUpdate(targetLocation string, hideSecrets bool) {
|
||||
// fetch old entry data
|
||||
unencryptedEntry := core.GetOldEntryData(targetLocation, 0)
|
||||
unencryptedEntry, err := core.GetOldEntryData(targetLocation, 0)
|
||||
if err != nil {
|
||||
back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true)
|
||||
}
|
||||
|
||||
// generate a new password
|
||||
unencryptedEntry[0] = inputPasswordGen()
|
||||
|
||||
@@ -79,7 +79,10 @@ func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlter
|
||||
|
||||
// EntryListGen generates and displays the full libmutton entry list.
|
||||
func EntryListGen() {
|
||||
fileList, dirList := synccommon.WalkEntryDir()
|
||||
fileList, dirList, err := synccommon.WalkEntryDir()
|
||||
if err != nil {
|
||||
back.PrintError("Failed to generate entry list: "+err.Error(), back.ErrorRead, true)
|
||||
}
|
||||
|
||||
// print header bar w/total entry count
|
||||
fmt.Print("\n"+ansiBlackOnWhite, len(fileList), " libmutton entries:"+back.AnsiReset)
|
||||
|
||||
+10
-2
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/rwinkhart/go-boilerplate/back"
|
||||
"github.com/rwinkhart/libmutton/crypt"
|
||||
"github.com/rwinkhart/libmutton/global"
|
||||
"github.com/rwinkhart/libmutton/syncclient"
|
||||
)
|
||||
|
||||
@@ -65,7 +66,10 @@ fieldLoop:
|
||||
}
|
||||
|
||||
if syncEnabled {
|
||||
syncclient.RunJob(false, false)
|
||||
_, err := syncclient.RunJob(false, false)
|
||||
if err != nil {
|
||||
back.PrintError("Failed to sync entries: "+err.Error(), global.ErrorSyncProcess, true)
|
||||
}
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
@@ -74,7 +78,11 @@ fieldLoop:
|
||||
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts an RCW-wrapped file before sending it to EntryReader.
|
||||
func EntryReaderDecrypt(targetLocation string, hideSecrets bool) {
|
||||
if isFile, _ := back.TargetIsFile(targetLocation, true, 2); isFile {
|
||||
EntryReader(crypt.DecryptFileToSlice(targetLocation), hideSecrets, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified
|
||||
decBytes, err := crypt.DecryptFileToSlice(targetLocation)
|
||||
if err != nil {
|
||||
back.PrintError("Failed to decrypt entry: "+err.Error(), global.ErrorDecryption, true)
|
||||
}
|
||||
EntryReader(decBytes, hideSecrets, 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
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
package cli
|
||||
|
||||
const fallbackEditor = "vi" // vi is pre-installed on most UNIX-like systems
|
||||
const FallbackEditor = "vi" // vi is pre-installed on most UNIX-like systems
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
package cli
|
||||
|
||||
const fallbackEditor = "edit" // "edit" is the Microsoft-developed CLI text editor
|
||||
const FallbackEditor = "edit" // "edit" is the Microsoft-developed CLI text editor
|
||||
|
||||
@@ -31,7 +31,10 @@ func inputPasswordGen() string {
|
||||
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets bool) {
|
||||
if core.EntryIsNotEmpty(unencryptedEntry) {
|
||||
// write the entry to the target location
|
||||
core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n")))
|
||||
err := core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n")))
|
||||
if err != nil {
|
||||
back.PrintError("Failed to write entry: "+err.Error(), back.ErrorWrite, true)
|
||||
}
|
||||
// preview the entry
|
||||
fmt.Println(back.AnsiBold + "\nEntry Preview:" + back.AnsiReset)
|
||||
EntryReader(unencryptedEntry, hideSecrets, true)
|
||||
|
||||
Reference in New Issue
Block a user