Skip to content

Commit 68a0b5e

Browse files
committed
feat: auto-install just command if not available
- Add ensureJustInstalled() function to check and install 'just' automatically - On macOS, automatically installs via Homebrew if available - Provides helpful error messages with installation instructions for other platforms - Update documentation to reflect automatic installation capability - Fixes issue where environment generation failed when 'just' was not in PATH
1 parent b9e4448 commit 68a0b5e

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

framework/cmd/main.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011

1112
"github.com/pelletier/go-toml"
@@ -33,7 +34,8 @@ func main() {
3334
Description: `🔗 Chainlink's Developer Environment Generator 🔗
3435
3536
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
3739
3840
Usage:
3941
@@ -111,6 +113,11 @@ Usage:
111113
fmt.Printf("⬛ Entering the shell..\n")
112114
fmt.Println()
113115

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+
114121
cmd := exec.Command("just", "cli")
115122
cmd.Env = os.Environ()
116123
cmd.Dir = outputDir
@@ -467,3 +474,36 @@ func RemoveCacheFiles() error {
467474
framework.L.Info().Msg("All cache files has been removed")
468475
return nil
469476
}
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

Comments
 (0)