zhamao-framework/src/ZM/Command/ReplCommand.php

36 lines
930 B
PHP
Raw Normal View History

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;
use Symfony\Component\Console\Attribute\AsCommand;
2022-08-27 00:53:45 +08:00
use ZM\Framework;
#[AsCommand(name: 'repl', description: '交互式控制台')]
2022-08-27 00:53:45 +08:00
class ReplCommand extends Command
{
public function handle(): int
2022-08-27 00:53:45 +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 {
$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) {
$this->error($e->getMessage());
return self::FAILURE;
2022-08-27 00:53:45 +08:00
}
return self::SUCCESS;
2022-08-27 00:53:45 +08:00
}
}