### Install laravel-zero-console with Composer Source: https://github.com/jeffersongoncalves/laravel-zero-console/blob/main/README.md Install the package via Composer. Requires PHP ^8.2 and illuminate/console ^11.0|^12.0. ```bash composer require jeffersongoncalves/laravel-zero-console ``` -------------------------------- ### Run tests with Composer Source: https://github.com/jeffersongoncalves/laravel-zero-console/blob/main/README.md Install dependencies and run the test suite. ```bash composer install composer test ``` -------------------------------- ### Customize stateColors mapping Source: https://github.com/jeffersongoncalves/laravel-zero-console/blob/main/README.md Override the stateColors method to customize the state-to-color mapping used by stateColor. The default map includes pull-request and issue-tracker states. ```php protected function stateColors(): array { return [ 'SHIPPED' => 'magenta', 'OPEN' => 'cyan', ]; } ``` -------------------------------- ### Use FormatsOutput trait in a Laravel command Source: https://github.com/jeffersongoncalves/laravel-zero-console/blob/main/README.md Use the FormatsOutput trait inside a Laravel command to render tables, colorize status strings, and format dates. The renderTable method shows an info message when rows are empty; formatDate returns '-' for null or invalid input. ```php use Illuminate\Console\Command; use JeffersonGoncalves\LaravelZero\Console\FormatsOutput; class ListCommand extends Command { use FormatsOutput; public function handle(): int { // Renders a table, or "No results found." when $rows is empty. $this->renderTable(['ID', 'State', 'Updated'], $rows); $this->line($this->colorize('OPEN', $this->stateColor('OPEN'))); // OPEN echo $this->formatDate('2024-01-02 03:04:05'); // 2024-01-02 03:04 echo $this->formatDate(null); // - return self::SUCCESS; } } ``` -------------------------------- ### Resolve paths with ResolvesPath trait Source: https://github.com/jeffersongoncalves/laravel-zero-console/blob/main/README.md Use the ResolvesPath trait to resolve a path argument to its realpath, falling back to the current working directory when the argument is empty. resolveCwd returns the realpath of getcwd(). ```php use JeffersonGoncalves\LaravelZero\Console\ResolvesPath; $path = $this->resolvePath($this->argument('path')); // realpath, or cwd when empty $cwd = $this->resolveCwd(); // realpath of getcwd() ``` -------------------------------- ### Handle API errors with HandlesApiErrors trait Source: https://github.com/jeffersongoncalves/laravel-zero-console/blob/main/README.md Use the HandlesApiErrors trait to wrap a callback that may throw. On success it returns the callback's int result (or SUCCESS if null); on any Throwable it prints the error via components->error() and returns FAILURE. ```php use JeffersonGoncalves\LaravelZero\Console\HandlesApiErrors; class FetchCommand extends Command { use HandlesApiErrors; public function handle(): int { return $this->handleApiErrors(function () { $data = $this->api->fetch(); // may throw any Throwable $this->renderTable(['ID'], $data); return self::SUCCESS; }); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.