From d42424112ae92db20bb19e6a6fff8c42bd04a087 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Fri, 4 Oct 2024 12:10:13 +0200 Subject: [PATCH] split filename at "Legacy" to fix garbage output from osa script --- main.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index bec4b86..7accd6c 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,11 @@ package main import ( "log" "os" + "os/exec" + "strings" + + "github.com/andybrewer/mack" ) -import "github.com/andybrewer/mack" -import "os/exec" func touchFile(path string, filename string) error { cmd := exec.Command("touch", filename) @@ -37,12 +39,34 @@ func main() { // handle the Cancel event os.Exit(2) } else { - newFilename := response.Text + dialogResult := strings.Split(response.Text, "Legacy") + log.Printf("Dialog Result: %s", dialogResult) + log.Printf("Dialog Result Length: %d", len(dialogResult)) + + newFilename := "" + switch len(dialogResult) { + case 0: + log.Printf("No filename provided") + os.Exit(2) + case 1: + log.Printf("Filename provided: %s", dialogResult[0]) + newFilename = strings.TrimSpace(dialogResult[0]) + case 2: + log.Printf("Filename provided: %s", dialogResult[1]) + newFilename = strings.TrimSpace(dialogResult[1]) + case 3: + log.Printf("Filename provided: %s", dialogResult[2]) + newFilename = strings.TrimSpace(dialogResult[2]) + default: + log.Printf("Unknown count for dialog result") + os.Exit(2) + } + err := touchFile(path, newFilename) if err != nil { panic(err) } - log.Printf("File Created: %s",newFilename) + log.Printf("File Created: %s", newFilename) } }