mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-18 05:04:51 +08:00
set default dir to new
This commit is contained in:
parent
13dd7e22f3
commit
470b2736b7
@ -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 . '</question>');
|
||||
$question = new Question('<question>' . $question . '</question>', $default);
|
||||
$question->setValidator($validator);
|
||||
$this->input->setOption($name, $helper->ask($this->input, $this->output, $question));
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user