Export WriteToStdin for use by clients

This commit is contained in:
2024-12-29 19:38:05 -05:00
parent fc2e77d8b8
commit d2034b458b
4 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ func copyString(continuous bool, copySubject string) {
os.Exit(ErrorClipboard) os.Exit(ErrorClipboard)
} }
writeToStdin(cmdCopy, copySubject) WriteToStdin(cmdCopy, copySubject)
err := cmdCopy.Run() err := cmdCopy.Run()
if err != nil { if err != nil {
fmt.Println(AnsiError+"Failed to copy to clipboard:", err.Error()+AnsiReset) fmt.Println(AnsiError+"Failed to copy to clipboard:", err.Error()+AnsiReset)
+1 -1
View File
@@ -29,7 +29,7 @@ func DecryptGPG(targetLocation string) []string {
func EncryptGPG(input []string) []byte { func EncryptGPG(input []string) []byte {
gpgCfg, _ := ParseConfig([][2]string{{"LIBMUTTON", "gpgID"}}, "") gpgCfg, _ := ParseConfig([][2]string{{"LIBMUTTON", "gpgID"}}, "")
cmd := exec.Command("gpg", "-q", "-r", gpgCfg[0], "-e") 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() encryptedBytes, err := cmd.Output()
if err != nil { 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) 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)
+1 -1
View File
@@ -14,7 +14,7 @@ import (
func LaunchClipClearProcess(copySubject string, isWayland bool) { func LaunchClipClearProcess(copySubject string, isWayland bool) {
executableName := os.Args[0] executableName := os.Args[0]
cmd := exec.Command(executableName, "clipclear", strconv.FormatBool(isWayland)) cmd := exec.Command(executableName, "clipclear", strconv.FormatBool(isWayland))
writeToStdin(cmd, copySubject) WriteToStdin(cmd, copySubject)
err := cmd.Start() err := cmd.Start()
if err != nil { if err != nil {
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - Does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset) fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - Does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
+3 -2
View File
@@ -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. // WriteToStdin is a utility function that writes a string to a command's stdin.
func writeToStdin(cmd *exec.Cmd, input string) { // TODO unexport (import?) after migration off of GPG
func WriteToStdin(cmd *exec.Cmd, input string) {
stdin, err := cmd.StdinPipe() stdin, err := cmd.StdinPipe()
if err != nil { if err != nil {
fmt.Println(AnsiError+"Failed to access stdin for system command:", err.Error()+AnsiReset) fmt.Println(AnsiError+"Failed to access stdin for system command:", err.Error()+AnsiReset)