├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php └── src ├── Contracts └── DescriberContract.php ├── Describer.php ├── LaravelConsoleSummaryServiceProvider.php └── SummaryCommand.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Nuno Maduro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 |

6 | Static Analysis 7 | Latest Stable Version 8 | License 9 |

10 | 11 | ## About Laravel Console Summary 12 | 13 | Laravel Console Summary was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a replacement for the List Command in Laravel Console Applications. Beautiful Laravel Console Summary for Artisan or Laravel Zero. 14 | 15 | ## Installation 16 | 17 | > **Requires [PHP 8.2+](https://php.net/releases)** 18 | 19 | Require Laravel Console Summary using [Composer](https://getcomposer.org): 20 | 21 | ```bash 22 | composer require nunomaduro/laravel-console-summary 23 | ``` 24 | 25 | ## Configuration 26 | 27 | Publish the configuration 28 | 29 | ```bash 30 | php artisan vendor:publish 31 | ``` 32 | 33 | You may want to clean up the summary screen by hiding some well-known commands from it. Of course, even hidden, they will still be available. 34 | 35 | ```php 36 | // config/laravel-console-summary.php 37 | 38 | return [ 39 | 'hide' => [ 40 | 'make:*', 41 | 'list' 42 | ], 43 | ]; 44 | ``` 45 | 46 | You can also override the binary name that is output in the usage information, by adding a `binary` key to your config. 47 | 48 | ```php 49 | // config/laravel-console-summary.php 50 | 51 | return [ 52 | // ... 53 | 54 | 'binary' => 'custom-name', 55 | ]; 56 | ``` 57 | 58 | ## Contributing 59 | 60 | Thank you for considering to contribute to Laravel Console Summary. All the contribution guidelines are mentioned [here](CONTRIBUTING.md). 61 | 62 | You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates & detailed information about the changes. You can also follow the Twitter account for latest announcements or just come say hi!: [@enunomaduro](https://twitter.com/enunomaduro) 63 | 64 | ## Support the development 65 | 66 | **Do you like this project? Support it by donating** 67 | 68 | - PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L) 69 | - Patreon: [Donate](https://www.patreon.com/nunomaduro) 70 | 71 | ## License 72 | 73 | Laravel Console Summary is an open-sourced software licensed under the [MIT license](LICENSE.md). 74 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nunomaduro/laravel-console-summary", 3 | "description": "A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.", 4 | "keywords": [ 5 | "console", 6 | "command-line", 7 | "php", 8 | "cli", 9 | "laravel-zero", 10 | "laravel", 11 | "artisan", 12 | "symfony" 13 | ], 14 | "license": "MIT", 15 | "support": { 16 | "issues": "https://github.com/nunomaduro/laravel-console-summary/issues", 17 | "source": "https://github.com/nunomaduro/laravel-console-summary" 18 | }, 19 | "authors": [ 20 | { 21 | "name": "Nuno Maduro", 22 | "email": "enunomaduro@gmail.com" 23 | } 24 | ], 25 | "require": { 26 | "php": "^8.2", 27 | "illuminate/console": "^11.4|^12.0", 28 | "illuminate/support": "^11.4|^12.0" 29 | }, 30 | "require-dev": { 31 | "laravel/pint": "^1.21" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "NunoMaduro\\LaravelConsoleSummary\\": "src/" 36 | } 37 | }, 38 | "config": { 39 | "preferred-install": "dist", 40 | "sort-packages": true 41 | }, 42 | "extra": { 43 | "laravel": { 44 | "providers": [ 45 | "NunoMaduro\\LaravelConsoleSummary\\LaravelConsoleSummaryServiceProvider" 46 | ] 47 | } 48 | }, 49 | "minimum-stability": "dev", 50 | "prefer-stable": true 51 | } 52 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'list', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Custom Binary Name 24 | |-------------------------------------------------------------------------- 25 | | 26 | | This option allows to override the Artisan binary name that is used 27 | | in the command usage output. 28 | | 29 | */ 30 | 31 | 'binary' => null, 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /src/Contracts/DescriberContract.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\LaravelConsoleSummary\Contracts; 15 | 16 | use Illuminate\Console\Application; 17 | use Symfony\Component\Console\Output\OutputInterface; 18 | 19 | interface DescriberContract 20 | { 21 | /** 22 | * Describes the provided laravel console application 23 | * using the provided output. 24 | */ 25 | public function describe(Application $application, OutputInterface $output): void; 26 | } 27 | -------------------------------------------------------------------------------- /src/Describer.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\LaravelConsoleSummary; 15 | 16 | use Illuminate\Console\Application; 17 | use Illuminate\Contracts\Config\Repository; 18 | use NunoMaduro\LaravelConsoleSummary\Contracts\DescriberContract; 19 | use Symfony\Component\Console\Output\OutputInterface; 20 | 21 | class Describer implements DescriberContract 22 | { 23 | /** 24 | * The bigger command name width. 25 | */ 26 | private int $width = 0; 27 | 28 | public function __construct(private readonly Repository $config) {} 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function describe(Application $application, OutputInterface $output): void 34 | { 35 | $this->describeTitle($application, $output) 36 | ->describeUsage($output) 37 | ->describeCommands($application, $output); 38 | } 39 | 40 | /** 41 | * Describes the application title. 42 | */ 43 | protected function describeTitle(Application $application, OutputInterface $output): DescriberContract 44 | { 45 | $output->write( 46 | "\n {$application->getName()} {$application->getVersion()}\n\n" 47 | ); 48 | 49 | return $this; 50 | } 51 | 52 | /** 53 | * Describes the application title. 54 | */ 55 | protected function describeUsage(OutputInterface $output): DescriberContract 56 | { 57 | $binary = $this->config->get('laravel-console-summary.binary', ARTISAN_BINARY); 58 | $output->write(" USAGE: {$binary} [options] [arguments]\n"); 59 | 60 | return $this; 61 | } 62 | 63 | /** 64 | * Describes the application commands. 65 | */ 66 | protected function describeCommands(Application $application, OutputInterface $output): DescriberContract 67 | { 68 | $this->width = 0; 69 | 70 | $hide = collect($this->config->get('laravel-console-summary.hide', [])); 71 | 72 | collect($application->all())->filter(fn ($command) => ! $command->isHidden())->filter(function ($command) use ($hide) { 73 | $nameParts = explode(':', $name = $command->getName()); 74 | 75 | $hasExactMatch = $hide->contains($command->getName()); 76 | $hasWildcardMatch = $hide->contains($nameParts[0].':*'); 77 | 78 | return ! $hasExactMatch && ! $hasWildcardMatch; 79 | })->unique(fn ($command) => $command->getName())->groupBy(function ($command) { 80 | $nameParts = explode(':', $name = $command->getName()); 81 | $this->width = max($this->width, mb_strlen($name)); 82 | 83 | return isset($nameParts[1]) ? $nameParts[0] : ''; 84 | })->sortKeys()->each(function ($commands) use ($output) { 85 | $output->write("\n"); 86 | 87 | $commands = $commands->toArray(); 88 | 89 | usort($commands, function ($a, $b) { 90 | return strcmp($a->getName(), $b->getName()); 91 | }); 92 | 93 | foreach ($commands as $command) { 94 | $output->write(sprintf( 95 | " %s%s%s%s\n", 96 | $command->getName(), 97 | str_repeat(' ', $this->width - mb_strlen($command->getName()) + 1), 98 | $command->getAliases() ? '['.implode('|', $command->getAliases()).'] ' : '', 99 | $command->getDescription() 100 | )); 101 | } 102 | })->whenNotEmpty(function () use ($output) { 103 | $output->writeln(''); 104 | }); 105 | 106 | return $this; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/LaravelConsoleSummaryServiceProvider.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\LaravelConsoleSummary; 15 | 16 | use Illuminate\Support\ServiceProvider; 17 | use NunoMaduro\LaravelConsoleSummary\Contracts\DescriberContract; 18 | 19 | class LaravelConsoleSummaryServiceProvider extends ServiceProvider 20 | { 21 | public function boot(): void 22 | { 23 | $this->publishes([ 24 | __DIR__.'/../config/config.php' => config_path('laravel-console-summary.php'), 25 | ], 'laravel-console-summary-config'); 26 | 27 | $this->commands(SummaryCommand::class); 28 | } 29 | 30 | /** {@inheritdoc} */ 31 | public function register(): void 32 | { 33 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-console-summary'); 34 | $this->app->singleton(DescriberContract::class, Describer::class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/SummaryCommand.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\LaravelConsoleSummary; 15 | 16 | use Illuminate\Contracts\Container\Container; 17 | use NunoMaduro\LaravelConsoleSummary\Contracts\DescriberContract; 18 | use Symfony\Component\Console\Command\ListCommand; 19 | use Symfony\Component\Console\Input\InputInterface; 20 | use Symfony\Component\Console\Output\OutputInterface; 21 | 22 | class SummaryCommand extends ListCommand 23 | { 24 | /** 25 | * The supported format. 26 | */ 27 | private const FORMAT = 'txt'; 28 | 29 | /** 30 | * @var \Illuminate\Contracts\Container\Container 31 | */ 32 | protected $container; 33 | 34 | /** 35 | * SummaryCommand constructor. 36 | */ 37 | public function __construct(Container $container) 38 | { 39 | parent::__construct('list'); 40 | 41 | $this->container = $container; 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | protected function execute(InputInterface $input, OutputInterface $output): int 48 | { 49 | if ($input->getOption('format') === static::FORMAT && ! $input->getOption('raw')) { 50 | $this->container[DescriberContract::class]->describe($this->getApplication(), $output); 51 | 52 | return 0; 53 | } 54 | 55 | return parent::execute($input, $output); 56 | } 57 | } 58 | --------------------------------------------------------------------------------