change commands definition to attribute

This commit is contained in:
sunxyw
2022-12-17 21:53:08 +08:00
parent c6f877700e
commit 3806983bc2
11 changed files with 36 additions and 73 deletions

View File

@@ -7,20 +7,15 @@ namespace ZM\Command;
use Psy\Configuration;
use Psy\Shell;
use Psy\VersionUpdater\Checker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use ZM\Framework;
#[AsCommand(name: 'repl', description: '交互式控制台')]
class ReplCommand extends Command
{
protected static $defaultName = 'repl';
protected static $defaultDescription = '交互式控制台';
public function execute(InputInterface $input, OutputInterface $output): int
public function handle(): int
{
$config = Configuration::fromInput($input);
$config = Configuration::fromInput($this->input);
$config->setUpdateCheck(Checker::NEVER);
$config->setStartupMessage('你可以使用 "help" 来查看帮助');
@@ -28,13 +23,13 @@ class ReplCommand extends Command
$shell->addCommands([]); // TODO: add some great commands
try {
$output->writeln(sprintf('<fg=blue>Zhamao Repl on Zhamao Framework %s</>', Framework::VERSION));
$this->info(sprintf('<fg=blue>Zhamao Repl on Zhamao Framework %s</>', Framework::VERSION));
$shell->run();
} catch (\Throwable $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return Command::FAILURE;
$this->error($e->getMessage());
return self::FAILURE;
}
return Command::SUCCESS;
return self::SUCCESS;
}
}