From 18973eb5999b0d620a25e687b3c26c74e60bc241 Mon Sep 17 00:00:00 2001 From: lukeraymonddowning Date: Mon, 15 Jan 2024 16:00:12 +0000 Subject: [PATCH 1/3] [10.x] Allows specifying the name of the stubs to be published --- src/Illuminate/Foundation/Console/StubPublishCommand.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Foundation/Console/StubPublishCommand.php b/src/Illuminate/Foundation/Console/StubPublishCommand.php index e2a293d489db..7c7ad9abbace 100644 --- a/src/Illuminate/Foundation/Console/StubPublishCommand.php +++ b/src/Illuminate/Foundation/Console/StubPublishCommand.php @@ -16,6 +16,7 @@ class StubPublishCommand extends Command * @var string */ protected $signature = 'stub:publish + {name? : Published stubs will be limited to files that start with this name} {--existing : Publish and overwrite only the files that have already been published} {--force : Overwrite any existing files}'; @@ -83,6 +84,13 @@ public function handle() realpath(__DIR__.'/../../Routing/Console/stubs/middleware.stub') => 'middleware.stub', ]; + if ($this->hasArgument('name')) { + $stubs = array_filter( + $stubs, + fn ($name) => str_starts_with($name, strtolower($this->argument('name'))), + ); + } + $this->laravel['events']->dispatch($event = new PublishingStubs($stubs)); foreach ($event->stubs as $from => $to) { From ab4aaf4baa84b0260ff035055373726437a3d2a7 Mon Sep 17 00:00:00 2001 From: lukeraymonddowning Date: Mon, 15 Jan 2024 16:07:21 +0000 Subject: [PATCH 2/3] [10.x] Allows specifying the name of the stubs to be published --- src/Illuminate/Foundation/Console/StubPublishCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Illuminate/Foundation/Console/StubPublishCommand.php b/src/Illuminate/Foundation/Console/StubPublishCommand.php index 7c7ad9abbace..621733681e2c 100644 --- a/src/Illuminate/Foundation/Console/StubPublishCommand.php +++ b/src/Illuminate/Foundation/Console/StubPublishCommand.php @@ -91,6 +91,12 @@ public function handle() ); } + if (count($stubs) === 0) { + $this->components->error('No stubs matched the given name.'); + + return self::FAILURE; + } + $this->laravel['events']->dispatch($event = new PublishingStubs($stubs)); foreach ($event->stubs as $from => $to) { From 7850652f694bc70e720c30e1d5efe817a0628c4c Mon Sep 17 00:00:00 2001 From: lukeraymonddowning Date: Mon, 15 Jan 2024 16:17:52 +0000 Subject: [PATCH 3/3] Adds `only` option. --- .../Foundation/Console/StubPublishCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Console/StubPublishCommand.php b/src/Illuminate/Foundation/Console/StubPublishCommand.php index 621733681e2c..554d81609fe7 100644 --- a/src/Illuminate/Foundation/Console/StubPublishCommand.php +++ b/src/Illuminate/Foundation/Console/StubPublishCommand.php @@ -16,9 +16,9 @@ class StubPublishCommand extends Command * @var string */ protected $signature = 'stub:publish - {name? : Published stubs will be limited to files that start with this name} {--existing : Publish and overwrite only the files that have already been published} - {--force : Overwrite any existing files}'; + {--force : Overwrite any existing files} + {--only= : Published stubs will be limited to files that start with the given value}'; /** * The console command description. @@ -84,15 +84,15 @@ public function handle() realpath(__DIR__.'/../../Routing/Console/stubs/middleware.stub') => 'middleware.stub', ]; - if ($this->hasArgument('name')) { + if ($this->option('only')) { $stubs = array_filter( $stubs, - fn ($name) => str_starts_with($name, strtolower($this->argument('name'))), + fn ($name) => str_starts_with($name, strtolower($this->option('only'))), ); } if (count($stubs) === 0) { - $this->components->error('No stubs matched the given name.'); + $this->components->error('No stubs matched the given options.'); return self::FAILURE; }