2022-08-27 00:53:45 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace ZM\Command;
|
|
|
|
|
|
|
|
|
|
use Psy\Configuration;
|
|
|
|
|
use Psy\Shell;
|
|
|
|
|
use Psy\VersionUpdater\Checker;
|
2022-12-17 21:53:08 +08:00
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
2022-08-27 00:53:45 +08:00
|
|
|
use ZM\Framework;
|
|
|
|
|
|
2022-12-17 21:53:08 +08:00
|
|
|
#[AsCommand(name: 'repl', description: '交互式控制台')]
|
2022-08-27 00:53:45 +08:00
|
|
|
class ReplCommand extends Command
|
|
|
|
|
{
|
2022-12-17 21:53:08 +08:00
|
|
|
public function handle(): int
|
2022-08-27 00:53:45 +08:00
|
|
|
{
|
2022-12-17 21:53:08 +08:00
|
|
|
$config = Configuration::fromInput($this->input);
|
2022-08-27 00:53:45 +08:00
|
|
|
$config->setUpdateCheck(Checker::NEVER);
|
|
|
|
|
$config->setStartupMessage('你可以使用 "help" 来查看帮助');
|
|
|
|
|
|
|
|
|
|
$shell = new Shell($config);
|
|
|
|
|
$shell->addCommands([]); // TODO: add some great commands
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-17 21:53:08 +08:00
|
|
|
$this->info(sprintf('<fg=blue>Zhamao Repl on Zhamao Framework %s</>', Framework::VERSION));
|
2022-08-27 00:53:45 +08:00
|
|
|
$shell->run();
|
|
|
|
|
} catch (\Throwable $e) {
|
2022-12-17 21:53:08 +08:00
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
return self::FAILURE;
|
2022-08-27 00:53:45 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-17 21:53:08 +08:00
|
|
|
return self::SUCCESS;
|
2022-08-27 00:53:45 +08:00
|
|
|
}
|
|
|
|
|
}
|