From d2034b458b702b8f1664bc188c1840040ec0f704 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 29 Dec 2024 19:38:05 -0500 Subject: [PATCH] Export WriteToStdin for use by clients --- core/copyUNIX.go | 2 +- core/gpg.go | 2 +- core/launchClipClearProcessCLIUNIX.go | 2 +- core/utilitiesMisc.go | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/copyUNIX.go b/core/copyUNIX.go index 56d4fd1..2447257 100644 --- a/core/copyUNIX.go +++ b/core/copyUNIX.go @@ -23,7 +23,7 @@ func copyString(continuous bool, copySubject string) { os.Exit(ErrorClipboard) } - writeToStdin(cmdCopy, copySubject) + WriteToStdin(cmdCopy, copySubject) err := cmdCopy.Run() if err != nil { fmt.Println(AnsiError+"Failed to copy to clipboard:", err.Error()+AnsiReset) diff --git a/core/gpg.go b/core/gpg.go index 8828135..edc2a92 100644 --- a/core/gpg.go +++ b/core/gpg.go @@ -29,7 +29,7 @@ func DecryptGPG(targetLocation string) []string { func EncryptGPG(input []string) []byte { gpgCfg, _ := ParseConfig([][2]string{{"LIBMUTTON", "gpgID"}}, "") cmd := exec.Command("gpg", "-q", "-r", gpgCfg[0], "-e") - writeToStdin(cmd, strings.Join(input, "\n")) + WriteToStdin(cmd, strings.Join(input, "\n")) encryptedBytes, err := cmd.Output() if err != nil { fmt.Println(AnsiError + "Failed to encrypt data - Ensure that your GPG key is valid and that you have a valid GPG ID set in libmutton.ini" + AnsiReset) diff --git a/core/launchClipClearProcessCLIUNIX.go b/core/launchClipClearProcessCLIUNIX.go index 5f5545d..345714c 100644 --- a/core/launchClipClearProcessCLIUNIX.go +++ b/core/launchClipClearProcessCLIUNIX.go @@ -14,7 +14,7 @@ import ( func LaunchClipClearProcess(copySubject string, isWayland bool) { executableName := os.Args[0] cmd := exec.Command(executableName, "clipclear", strconv.FormatBool(isWayland)) - writeToStdin(cmd, copySubject) + WriteToStdin(cmd, copySubject) err := cmd.Start() if err != nil { fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - Does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset) diff --git a/core/utilitiesMisc.go b/core/utilitiesMisc.go index 73ec35b..9904154 100644 --- a/core/utilitiesMisc.go +++ b/core/utilitiesMisc.go @@ -56,8 +56,9 @@ func WriteEntry(targetLocation string, entryData []string, verifyEntryDoesNotExi } } -// writeToStdin is a utility function that writes a string to a command's stdin. -func writeToStdin(cmd *exec.Cmd, input string) { +// WriteToStdin is a utility function that writes a string to a command's stdin. +// TODO unexport (import?) after migration off of GPG +func WriteToStdin(cmd *exec.Cmd, input string) { stdin, err := cmd.StdinPipe() if err != nil { fmt.Println(AnsiError+"Failed to access stdin for system command:", err.Error()+AnsiReset)