|
6 | 6 | "os" |
7 | 7 | "os/exec" |
8 | 8 | "path/filepath" |
| 9 | + "runtime" |
9 | 10 | "strings" |
10 | 11 |
|
11 | 12 | "github.com/pelletier/go-toml" |
@@ -33,7 +34,8 @@ func main() { |
33 | 34 | Description: `🔗 Chainlink's Developer Environment Generator 🔗 |
34 | 35 |
|
35 | 36 | Prerequisites: |
36 | | - We are using Just, please install it first - https://github.com/casey/just |
| 37 | + Just will be automatically installed if not available (via Homebrew on macOS). |
| 38 | + For other platforms, please install it manually: https://github.com/casey/just |
37 | 39 |
|
38 | 40 | Usage: |
39 | 41 |
|
@@ -111,6 +113,11 @@ Usage: |
111 | 113 | fmt.Printf("⬛ Entering the shell..\n") |
112 | 114 | fmt.Println() |
113 | 115 |
|
| 116 | + // Ensure 'just' is installed before proceeding |
| 117 | + if err := ensureJustInstalled(); err != nil { |
| 118 | + return fmt.Errorf("failed to ensure 'just' is installed: %w", err) |
| 119 | + } |
| 120 | + |
114 | 121 | cmd := exec.Command("just", "cli") |
115 | 122 | cmd.Env = os.Environ() |
116 | 123 | cmd.Dir = outputDir |
@@ -467,3 +474,36 @@ func RemoveCacheFiles() error { |
467 | 474 | framework.L.Info().Msg("All cache files has been removed") |
468 | 475 | return nil |
469 | 476 | } |
| 477 | + |
| 478 | +// ensureJustInstalled checks if 'just' is available in PATH, and if not, attempts to install it. |
| 479 | +// On macOS, it tries to install via Homebrew. On other platforms, it provides installation instructions. |
| 480 | +func ensureJustInstalled() error { |
| 481 | + // Check if just is already available |
| 482 | + if _, err := exec.LookPath("just"); err == nil { |
| 483 | + return nil |
| 484 | + } |
| 485 | + |
| 486 | + fmt.Println("⚠️ 'just' command not found in PATH") |
| 487 | + fmt.Println("📦 Attempting to install 'just'...") |
| 488 | + |
| 489 | + // Try to install via Homebrew on macOS |
| 490 | + if runtime.GOOS == "darwin" { |
| 491 | + // Check if Homebrew is available |
| 492 | + if _, err := exec.LookPath("brew"); err == nil { |
| 493 | + fmt.Println("🍺 Installing 'just' via Homebrew...") |
| 494 | + cmd := exec.Command("brew", "install", "just") |
| 495 | + cmd.Stdout = os.Stdout |
| 496 | + cmd.Stderr = os.Stderr |
| 497 | + if err := cmd.Run(); err != nil { |
| 498 | + return fmt.Errorf("failed to install 'just' via Homebrew: %w. Please install manually: brew install just", err) |
| 499 | + } |
| 500 | + fmt.Println("✅ Successfully installed 'just'") |
| 501 | + return nil |
| 502 | + } |
| 503 | + // Homebrew not available, provide instructions |
| 504 | + return fmt.Errorf("'just' is not installed and Homebrew is not available. Please install 'just' manually:\n brew install just\n Or visit: https://github.com/casey/just") |
| 505 | + } |
| 506 | + |
| 507 | + // For non-macOS platforms, provide installation instructions |
| 508 | + return fmt.Errorf("'just' is not installed. Please install it manually:\n Visit: https://github.com/casey/just\n Or use your package manager (e.g., apt install just, pacman -S just)") |
| 509 | +} |
0 commit comments