mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-05 16:47:20 -04:00
Implement errors for copying entry fields that do not exist or are blank
This commit is contained in:
@@ -52,7 +52,7 @@ func main() {
|
|||||||
|
|
||||||
switch args[2] {
|
switch args[2] {
|
||||||
case "copy":
|
case "copy":
|
||||||
var field uint8
|
var field int
|
||||||
switch args[3] {
|
switch args[3] {
|
||||||
case "password", "-p":
|
case "password", "-p":
|
||||||
field = 0
|
field = 0
|
||||||
|
|||||||
@@ -10,13 +10,27 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO Avoid index out of range errors when copying fields that do not exist
|
|
||||||
// TODO Implement support for MacOS via pbcopy, Termux via termux-clipboard-set (in separate files)
|
// TODO Implement support for MacOS via pbcopy, Termux via termux-clipboard-set (in separate files)
|
||||||
|
|
||||||
// CopyField copies a field from an entry to the clipboard
|
// CopyField copies a field from an entry to the clipboard
|
||||||
func CopyField(targetLocation string, field uint8, executableName string) {
|
func CopyField(targetLocation string, field int, executableName string) {
|
||||||
if isFile, _ := TargetIsFile(targetLocation, true); isFile {
|
if isFile, _ := TargetIsFile(targetLocation, true); isFile {
|
||||||
copySubject := DecryptGPG(targetLocation)[field]
|
decryptedEntry := DecryptGPG(targetLocation)
|
||||||
|
var copySubject string // will store data to be copied
|
||||||
|
|
||||||
|
// ensure field exists in entry
|
||||||
|
if len(decryptedEntry) > field {
|
||||||
|
copySubject = decryptedEntry[field]
|
||||||
|
} else {
|
||||||
|
fmt.Println(AnsiError + "Field does not exist in entry" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure field is not blank
|
||||||
|
if copySubject == "" {
|
||||||
|
fmt.Println(AnsiError + "Field is empty" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
var envSet bool // track whether environment variables are set
|
var envSet bool // track whether environment variables are set
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
|
|||||||
+17
-2
@@ -13,9 +13,24 @@ import (
|
|||||||
// TODO Avoid index out of range errors when copying fields that do not exist
|
// TODO Avoid index out of range errors when copying fields that do not exist
|
||||||
|
|
||||||
// CopyField copies a field from an entry to the clipboard
|
// CopyField copies a field from an entry to the clipboard
|
||||||
func CopyField(targetLocation string, field uint8, executableName string) {
|
func CopyField(targetLocation string, field int, executableName string) {
|
||||||
if isFile, _ := TargetIsFile(targetLocation, true); isFile {
|
if isFile, _ := TargetIsFile(targetLocation, true); isFile {
|
||||||
copySubject := DecryptGPG(targetLocation)[field]
|
decryptedEntry := DecryptGPG(targetLocation)
|
||||||
|
var copySubject string // will store data to be copied
|
||||||
|
|
||||||
|
// ensure field exists in entry
|
||||||
|
if len(decryptedEntry) > field {
|
||||||
|
copySubject = decryptedEntry[field]
|
||||||
|
} else {
|
||||||
|
fmt.Println(AnsiError + "Field does not exist in entry" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure field is not blank
|
||||||
|
if copySubject == "" {
|
||||||
|
fmt.Println(AnsiError + "Field is empty" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", copySubject))
|
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", copySubject))
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
|
|||||||
Reference in New Issue
Block a user