diff --git a/src/ZM/Command/Plugin/PluginCommand.php b/src/ZM/Command/Plugin/PluginCommand.php
index c139b4cc..94b18812 100644
--- a/src/ZM/Command/Plugin/PluginCommand.php
+++ b/src/ZM/Command/Plugin/PluginCommand.php
@@ -97,11 +97,11 @@ abstract class PluginCommand extends Command
* @param string $question 问题
* @param callable $validator 验证器
*/
- protected function questionWithOption(string $name, string $question, callable $validator): void
+ protected function questionWithOption(string $name, string $question, callable $validator, string $default = null): void
{
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
- $question = new Question('' . $question . '');
+ $question = new Question('' . $question . '', $default);
$question->setValidator($validator);
$this->input->setOption($name, $helper->ask($this->input, $this->output, $question));
}
diff --git a/src/ZM/Command/Plugin/PluginMakeCommand.php b/src/ZM/Command/Plugin/PluginMakeCommand.php
index 3379aa58..6d24d584 100644
--- a/src/ZM/Command/Plugin/PluginMakeCommand.php
+++ b/src/ZM/Command/Plugin/PluginMakeCommand.php
@@ -7,6 +7,7 @@ namespace ZM\Command\Plugin;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
+use ZM\Exception\FileSystemException;
use ZM\Store\FileSystem;
use ZM\Utils\CodeGenerator\PluginGenerator;
@@ -30,6 +31,7 @@ class PluginMakeCommand extends PluginCommand
/**
* {@inheritDoc}
+ * @throws FileSystemException
*/
protected function handle(): int
{
@@ -57,15 +59,16 @@ class PluginMakeCommand extends PluginCommand
if ($this->input->getOption('type') === 'psr4') {
// 询问命名空间
if ($this->input->getOption('namespace') === null) {
- $this->questionWithOption('namespace', '请输入插件命名空间:', [$this, 'validateNamespace']);
+ $default_namespace = explode('/', $this->input->getArgument('name'))[0];
+ $this->questionWithOption('namespace', '请输入插件命名空间,输入则使用自定义,回车默认使用 [' . $default_namespace . ']:', [$this, 'validateNamespace'], $default_namespace);
}
}
$generator = new PluginGenerator($this->input->getArgument('name'), $this->plugin_dir);
- $generator->generate($this->input->getOptions());
+ $dir = $generator->generate($this->input->getOptions());
$this->info('已生成插件:' . $this->input->getArgument('name'));
- $this->info('目录位置:' . zm_dir($this->plugin_dir . '/' . $this->input->getArgument('name')));
+ $this->info('目录位置:' . $dir);
return self::SUCCESS;
}
}
diff --git a/src/ZM/Utils/CodeGenerator/PluginGenerator.php b/src/ZM/Utils/CodeGenerator/PluginGenerator.php
index 76985cac..0e16dd65 100644
--- a/src/ZM/Utils/CodeGenerator/PluginGenerator.php
+++ b/src/ZM/Utils/CodeGenerator/PluginGenerator.php
@@ -23,7 +23,7 @@ class PluginGenerator
* @param array $options 传入的命令行选项
* @throws FileSystemException
*/
- public function generate(array $options): void
+ public function generate(array $options): string
{
// 先检查插件目录是否存在,不存在则创建
FileSystem::createDir($this->plugin_dir);
@@ -87,6 +87,7 @@ class PluginGenerator
}
passthru(PHP_BINARY . ' ' . escapeshellcmd($env) . ' dump-autoload');
chdir(WORKING_DIR);
+ return $plugin_base_dir;
}
/**