From 2397bf9fb057c50f719ce46b05020a44281fd460 Mon Sep 17 00:00:00 2001 From: maddalax Date: Fri, 13 Sep 2024 20:04:15 -0500 Subject: [PATCH] update the runner to be a little bit cleaner --- framework/tooling/downloadtemplate/main.go | 9 +++-- framework/tooling/htmgo/runner.go | 38 +++++++++++++--------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/framework/tooling/downloadtemplate/main.go b/framework/tooling/downloadtemplate/main.go index 556779f..67cc292 100644 --- a/framework/tooling/downloadtemplate/main.go +++ b/framework/tooling/downloadtemplate/main.go @@ -21,20 +21,15 @@ func deleteAllExceptTemplate(outPath string, excludeDir string) { for _, file := range files { // Skip the excluded directory if file.Name() == excludeDir { - fmt.Printf("Skipping directory: %s\n", file.Name()) continue } // Get full path fullPath := filepath.Join(outPath, file.Name()) - // Remove the file or directory - fmt.Printf("Removing: %s\n", fullPath) err := os.RemoveAll(fullPath) if err != nil { fmt.Printf("Error removing %s: %v\n", fullPath, err) - } else { - fmt.Printf("Successfully removed %s\n", fullPath) } } } @@ -73,6 +68,8 @@ func main() { mvCmd := exec.Command("cp", "-vaR", fmt.Sprintf("%s/.", excludeDir), ".") mvCmd.Dir = newDir + mvCmd.Stdout = os.DevNull + mvCmd.Stderr = os.DevNull err = mvCmd.Run() if err != nil { @@ -82,6 +79,8 @@ func main() { rmCmd := exec.Command("rm", "-rf", "starter-template") rmCmd.Dir = newDir + mvCmd.Stdout = os.DevNull + mvCmd.Stderr = os.DevNull err = rmCmd.Run() if err != nil { diff --git a/framework/tooling/htmgo/runner.go b/framework/tooling/htmgo/runner.go index 5372cce..9f49b85 100644 --- a/framework/tooling/htmgo/runner.go +++ b/framework/tooling/htmgo/runner.go @@ -6,21 +6,36 @@ import ( "fmt" "os" "os/exec" + "strings" ) //go:embed Taskfile.yml var taskFile string func main() { - taskFlag := flag.String("task", "", "Specify the task to run (e.g., build, setup). Type -task list to see the list of tasks to run.") + commandMap := make(map[string]*flag.FlagSet) + commands := []string{"template", "run", "build", "setup"} - // Parse the command-line flags - flag.Parse() + for _, command := range commands { + commandMap[command] = flag.NewFlagSet(command, flag.ExitOnError) + } + if len(os.Args) < 2 { + fmt.Println(fmt.Sprintf("Usage: htmgo [%s]", strings.Join(commands, " | "))) + os.Exit(1) + } + + err := commandMap[os.Args[1]].Parse(os.Args[2:]) + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + return + } + + // Install the latest version of Task install := exec.Command("go", "install", "github.com/go-task/task/v3/cmd/task@latest") - install.Stdout = os.Stdout - install.Stderr = os.Stderr - err := install.Run() + + err = install.Run() if err != nil { fmt.Printf("Error installing task: %v\n", err) return @@ -35,17 +50,8 @@ func main() { os.WriteFile(temp.Name(), []byte(taskFile), 0644) - if *taskFlag == "" { - fmt.Println("Please specify a task to run using the -task flag") - return - } - - if *taskFlag == "list" { - *taskFlag = "--list" - } - // Define the command and arguments - cmd := exec.Command("task", "-t", temp.Name(), *taskFlag) + cmd := exec.Command("task", "-t", temp.Name(), os.Args[1]) // Set the standard output and error to be the same as the Go program cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr