Skip to content

Commit

Permalink
Merge pull request #6 from fcoder-hovilo/go-task-update
Browse files Browse the repository at this point in the history
Go task update
  • Loading branch information
khengyun authored Jan 4, 2024
2 parents 4739a98 + 8a94cca commit 4cd7d71
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ tasks:
run:
desc: Run docker first then start the browser
cmds:
- "sudo docker compose up --build -d"
- "sleep 2"
- "./app/dev/open-browser"
- |
cd app/dev/
go build open-browser.go
./open-browser
39 changes: 38 additions & 1 deletion app/dev/open-browser.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
package main

import (
"fmt"
"os"
"os/exec"
"runtime"
"time"
)

func main() {
url := "http://localhost:5000"

// Check the operating system
switch runtime.GOOS {
case "linux":
dockerCmd := exec.Command("sudo", "docker-compose", "up", "--build", "-d")
if err := runAndWait(dockerCmd); err != nil {
fmt.Println("Error running Docker command:", err)
os.Exit(1)
}
case "darwin":
// Assume macOS uses the same command as Linux
dockerCmd := exec.Command("docker-compose", "up", "--build", "-d")
if err := runAndWait(dockerCmd); err != nil {
fmt.Println("Error running Docker command:", err)
os.Exit(1)
}
case "windows":
dockerCmd := exec.Command("docker-compose", "up", "--build", "-d")
if err := runAndWait(dockerCmd); err != nil {
fmt.Println("Error running Docker command:", err)
os.Exit(1)
}
default:
fmt.Println("Unsupported operating system")
os.Exit(1)
}

// Wait for 10 seconds
time.Sleep(10 * time.Second)

// Open the browser
switch runtime.GOOS {
case "linux":
exec.Command("xdg-open", url).Start()
case "darwin":
exec.Command("open", url).Start()
case "windows":
exec.Command("cmd", "/c", "start", url).Start()
default:
println("Unsupported operating system")
fmt.Println("Unsupported operating system")
os.Exit(1)
}
}

func runAndWait(cmd *exec.Cmd) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

0 comments on commit 4cd7d71

Please sign in to comment.