From ff4ecf1b811987052504f526dc3f915630bb6ff9 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Tue, 14 Dec 2021 22:06:11 +0800 Subject: [PATCH 1/3] Add default name to commands for lazy loading. Refs: - https://github.com/laravel/framework/pull/34873 - https://github.com/wintercms/winter/pull/148 --- .../Console/ClearCompiledCommand.php | 1 - src/Foundation/Console/KeyGenerateCommand.php | 14 ---------- src/Scaffold/Console/CreateCommand.php | 6 ++--- src/Scaffold/Console/CreateComponent.php | 6 ++--- src/Scaffold/Console/CreateController.php | 6 ++--- src/Scaffold/Console/CreateFormWidget.php | 6 ++--- src/Scaffold/Console/CreateModel.php | 6 ++--- src/Scaffold/Console/CreatePlugin.php | 6 ++--- src/Scaffold/Console/CreateReportWidget.php | 6 ++--- src/Scaffold/Console/CreateSettings.php | 7 +++-- src/Scaffold/Console/CreateTheme.php | 6 ++--- src/Scaffold/ScaffoldServiceProvider.php | 27 +++++++------------ 12 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/Foundation/Console/ClearCompiledCommand.php b/src/Foundation/Console/ClearCompiledCommand.php index 765b8ce9..5348386e 100644 --- a/src/Foundation/Console/ClearCompiledCommand.php +++ b/src/Foundation/Console/ClearCompiledCommand.php @@ -1,6 +1,5 @@ CreateTheme::class, - 'command.create.plugin' => CreatePlugin::class, - 'command.create.model' => CreateModel::class, - 'command.create.settings' => CreateSettings::class, - 'command.create.controller' => CreateController::class, - 'command.create.component' => CreateComponent::class, - 'command.create.formwidget' => CreateFormWidget::class, - 'command.create.reportwidget' => CreateReportWidget::class, - 'command.create.command' => CreateCommand::class, + 'command.create.theme' => \Winter\Storm\Scaffold\Console\CreateTheme::class, + 'command.create.plugin' => \Winter\Storm\Scaffold\Console\CreatePlugin::class, + 'command.create.model' => \Winter\Storm\Scaffold\Console\CreateModel::class, + 'command.create.settings' => \Winter\Storm\Scaffold\Console\CreateSettings::class, + 'command.create.controller' => \Winter\Storm\Scaffold\Console\CreateController::class, + 'command.create.component' => \Winter\Storm\Scaffold\Console\CreateComponent::class, + 'command.create.formwidget' => \Winter\Storm\Scaffold\Console\CreateFormWidget::class, + 'command.create.reportwidget' => \Winter\Storm\Scaffold\Console\CreateReportWidget::class, + 'command.create.command' => \Winter\Storm\Scaffold\Console\CreateCommand::class, ]; /** From e5b778f525e9a1495d47bec3587fc9e4d8976d89 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Thu, 16 Dec 2021 15:19:18 +0800 Subject: [PATCH 2/3] Generate lazy loaded command name with scaffold --- src/Scaffold/Console/command/command.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Scaffold/Console/command/command.stub b/src/Scaffold/Console/command/command.stub index e681b0b9..847e811c 100644 --- a/src/Scaffold/Console/command/command.stub +++ b/src/Scaffold/Console/command/command.stub @@ -9,7 +9,7 @@ class {{studly_name}} extends Command /** * @var string The console command name. */ - protected $name = '{{lower_plugin}}:{{lower_name}}'; + protected static $defaultName = '{{lower_plugin}}:{{lower_name}}'; /** * @var string The console command description. From 43cae951cf01eec7ba210ead86dc6704a581dcc6 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Fri, 17 Dec 2021 10:34:14 +0800 Subject: [PATCH 3/3] Change scaffold commands to use signatures --- src/Scaffold/Console/CreateCommand.php | 39 ++++++--------------- src/Scaffold/Console/CreateComponent.php | 37 ++++++------------- src/Scaffold/Console/CreateController.php | 39 ++++++--------------- src/Scaffold/Console/CreateFormWidget.php | 37 ++++++------------- src/Scaffold/Console/CreateModel.php | 37 ++++++------------- src/Scaffold/Console/CreatePlugin.php | 35 +++++------------- src/Scaffold/Console/CreateReportWidget.php | 37 ++++++------------- src/Scaffold/Console/CreateSettings.php | 24 ++++++------- src/Scaffold/Console/CreateTheme.php | 35 +++++------------- src/Scaffold/GeneratorCommand.php | 24 ------------- 10 files changed, 90 insertions(+), 254 deletions(-) diff --git a/src/Scaffold/Console/CreateCommand.php b/src/Scaffold/Console/CreateCommand.php index 7f2c91fa..401ecaad 100644 --- a/src/Scaffold/Console/CreateCommand.php +++ b/src/Scaffold/Console/CreateCommand.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {command : The name of the command to generate. (eg: create)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -48,7 +56,7 @@ protected function prepareVars() $parts = explode('.', $pluginCode); $plugin = array_pop($parts); $author = array_pop($parts); - $command = $this->argument('command-name'); + $command = $this->argument('command'); return [ 'name' => $command, @@ -56,29 +64,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin. Eg: Winter.Blog'], - ['command-name', InputArgument::REQUIRED, 'The name of the command. Eg: MyCommand'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'] - ]; - } } diff --git a/src/Scaffold/Console/CreateComponent.php b/src/Scaffold/Console/CreateComponent.php index fa47d624..67ffe3b6 100644 --- a/src/Scaffold/Console/CreateComponent.php +++ b/src/Scaffold/Console/CreateComponent.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {component : The name of the component to generate. (eg: Posts)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -57,29 +65,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin to create. Eg: Winter.Blog'], - ['component', InputArgument::REQUIRED, 'The name of the component. Eg: Posts'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'] - ]; - } } diff --git a/src/Scaffold/Console/CreateController.php b/src/Scaffold/Console/CreateController.php index 2cc988d8..81cb8c21 100644 --- a/src/Scaffold/Console/CreateController.php +++ b/src/Scaffold/Console/CreateController.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {controller : The name of the controller to generate. (eg: Posts)} + {--force : Overwrite existing files with generated files.} + {--model= : Defines the model name to use. If not provided, the singular name of the controller is used.}'; + /** * The console command description. * @@ -75,30 +84,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin to create. Eg: Winter.Blog'], - ['controller', InputArgument::REQUIRED, 'The name of the controller. Eg: Posts'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ['model', null, InputOption::VALUE_OPTIONAL, 'Define which model name to use, otherwise the singular controller name is used.'], - ]; - } } diff --git a/src/Scaffold/Console/CreateFormWidget.php b/src/Scaffold/Console/CreateFormWidget.php index e1d259af..75b42e3e 100644 --- a/src/Scaffold/Console/CreateFormWidget.php +++ b/src/Scaffold/Console/CreateFormWidget.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {widget : The name of the form widget to generate. (eg: PostList)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -60,29 +68,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin. Eg: Winter.Blog'], - ['widget', InputArgument::REQUIRED, 'The name of the form widget. Eg: PostList'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ]; - } } diff --git a/src/Scaffold/Console/CreateModel.php b/src/Scaffold/Console/CreateModel.php index a229ad25..b4dcef7f 100644 --- a/src/Scaffold/Console/CreateModel.php +++ b/src/Scaffold/Console/CreateModel.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {model : The name of the model to generate. (eg: Post)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -60,29 +68,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin. Eg: Winter.Blog'], - ['model', InputArgument::REQUIRED, 'The name of the model. Eg: Post'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ]; - } } diff --git a/src/Scaffold/Console/CreatePlugin.php b/src/Scaffold/Console/CreatePlugin.php index 1d92529d..a17bc128 100644 --- a/src/Scaffold/Console/CreatePlugin.php +++ b/src/Scaffold/Console/CreatePlugin.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -65,28 +72,4 @@ protected function prepareVars() 'author' => $authorName, ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin to create. Eg: Winter.Blog'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ]; - } } diff --git a/src/Scaffold/Console/CreateReportWidget.php b/src/Scaffold/Console/CreateReportWidget.php index 063748d4..15c9dcf0 100644 --- a/src/Scaffold/Console/CreateReportWidget.php +++ b/src/Scaffold/Console/CreateReportWidget.php @@ -1,8 +1,6 @@ (eg: Winter.Blog)} + {widget : The name of the report widget to generate. (eg: PostViews)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -58,29 +66,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin. Eg: Winter.Google'], - ['widget', InputArgument::REQUIRED, 'The name of the report widget. Eg: TopPages'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ]; - } } diff --git a/src/Scaffold/Console/CreateSettings.php b/src/Scaffold/Console/CreateSettings.php index 376181ff..25a752c3 100644 --- a/src/Scaffold/Console/CreateSettings.php +++ b/src/Scaffold/Console/CreateSettings.php @@ -1,7 +1,6 @@ (eg: Winter.Blog)} + {settings : The name of the settings model to generate. (eg: BlogSettings)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -56,17 +65,4 @@ protected function prepareVars() 'plugin' => $plugin ]; } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin. Eg: Winter.Blog'], - ['settings', InputArgument::OPTIONAL, 'The name of the settings model. Eg: Settings'], - ]; - } } diff --git a/src/Scaffold/Console/CreateTheme.php b/src/Scaffold/Console/CreateTheme.php index dd97dcca..9a867294 100644 --- a/src/Scaffold/Console/CreateTheme.php +++ b/src/Scaffold/Console/CreateTheme.php @@ -2,8 +2,6 @@ use Exception; use Winter\Storm\Scaffold\GeneratorCommand; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; class CreateTheme extends GeneratorCommand { @@ -14,6 +12,15 @@ class CreateTheme extends GeneratorCommand */ protected static $defaultName = 'create:theme'; + /** + * The name and signature of this command. + * + * @var string + */ + protected $signature = 'create:theme + {theme : The name of the theme to create. (eg: MyTheme)} + {--force : Overwrite existing files with generated files.}'; + /** * The console command description. * @@ -111,28 +118,4 @@ public function makeStub($stubName) $this->files->put($destinationFile, $destinationContent); } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['theme', InputArgument::REQUIRED, 'The code of the theme to create. Eg: example.com'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ]; - } } diff --git a/src/Scaffold/GeneratorCommand.php b/src/Scaffold/GeneratorCommand.php index 6445e452..b0af152c 100644 --- a/src/Scaffold/GeneratorCommand.php +++ b/src/Scaffold/GeneratorCommand.php @@ -234,28 +234,4 @@ protected function getPluginInput() { return $this->argument('plugin'); } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['plugin', InputArgument::REQUIRED, 'The name of the plugin to create. Eg: Winter.Blog'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], - ]; - } }