league/climate
League CLImate makes PHP CLI output nicer with easy colored text, formatting, and styled messages. Install via Composer and use a simple API to print red, blue, and more, helping your command-line scripts look clean and readable.
$climate->blue()->bold('Warning')) mirrors Laravel’s Eloquent and Collection APIs, reducing cognitive friction for developers.composer require league/climate, with autoloading compatible with Laravel’s PSR-4 setup.use League\CLImate\CLImate;
use Symfony\Component\Console\Command\Command;
class MyCommand extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
$climate = new CLImate();
$climate->blue('Command executed!')->display();
}
}
Note: For full Artisan integration, consider wrapping CLImate in a service provider to standardize usage.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Terminal Compatibility | Supports Windows/Linux/macOS (fixed in v3.1.1+), but edge cases (e.g., non-ANSI terminals) may require forceAnsiOn(). |
Test on Windows Subsystem for Linux (WSL) and legacy terminals; document fallbacks. |
| Performance Overhead | Minimal (~1–5ms per operation), but progress bars/spinners may add ~10–20ms per update. | Benchmark in Laravel’s artisan workloads; cache heavy operations if needed. |
| API Stability | Actively maintained (PHP 8.4 support), but breaking changes in minor versions (e.g., v3.0.0). | Pin to ^3.10 in composer.json; monitor changelog. |
| Dependency Conflicts | No direct conflicts, but PSR-3 logger may interact with Laravel’s Log facade. |
Use CLImate’s logger only for CLI-specific logs; avoid mixing with HTTP logs. |
Standardization vs. Flexibility:
echo/error_log in Laravel’s CLI tools, or be opt-in for new features (e.g., progress bars)?Artisan Integration Depth:
CLI::blue()) for Laravel consistency, or kept as a direct dependency?// Option A: Direct usage
$climate = new CLImate();
$climate->blue('Hello')->display();
// Option B: Facade (requires custom wrapper)
CLI::blue('Hello');
Interactive Prompts for Non-Dev Users:
confirm()/checkboxes() methods be used to build self-service CLI tools for content managers (e.g., php artisan content:publish)?Progress Bars for Async Tasks:
dispatchSync()) or jobs?$climate->progress()->start();
foreach ($jobs as $job) {
$job->handle();
$climate->progress()->advance();
}
Cross-Platform Testing:
phpunit/phpunit with custom CLI assertions.echo with CLImate for colored output, tables, and progress bars.php artisan db:optimize) with interactive prompts.$climate->progress()->each($tables, ...)).OutputInterface (see #191).| Phase | Action | Tools/Examples |
|---|---|---|
| 1. Pilot Project | Replace echo in one Artisan command (e.g., php artisan migrate) with CLImate. |
Use $climate->yellow()->bold('Migrating...') instead of echo "\033[33mMigrating...\033[0m";. |
| 2. Standardize Output | Create a CLI helper class (e.g., app/Helpers/CLI.php) to wrap CLImate methods. |
Example: CLI::success('Done!') → $climate->green('Done!')->display(). |
| 3. Add Interactive Features | Introduce prompts (e.g., confirm()) in admin-focused CLI tools. |
Example: if ($climate->confirm('Overwrite?')) { ... }. |
| 4. Progress Bars for Async | Integrate with queues/jobs for real-time feedback. | Example: $climate->progress()->each($jobs, fn($job) => $job->handle()). |
| 5. Full Adoption | Deprecate raw echo in CLI tools; enforce CLImate usage via PSR-2 or custom linting. |
Use phpstan/extension-installer to flag violations. |
OutputInterface for hybrid usage:
use League\CLImate\CLImate;
use Symfony\Component\Console\Output\OutputInterface;
class HybridOutput implements OutputInterface {
private CLImate $climate;
public function write(string $messages, bool $newline = false): void {
$this->climate->out($messages)->display();
}
}
$climate->forceAnsiOff().echo in high-visibility commands (e.g., php artisan serve, php artisan migrate).php artisan queue:work --once).php artisan content:publish).error_log() with CLImate’s PSR-3 logger for CLI-specific logs.echo statements via deprecation warnings (use trigger_error()).How can I help you explore Laravel packages today?