update the runner to be a little bit cleaner

This commit is contained in:
maddalax 2024-09-13 20:04:15 -05:00
parent e8972b5688
commit 2397bf9fb0
2 changed files with 26 additions and 21 deletions

View file

@ -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 {

View file

@ -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