nacosvel / console
Nacosvel 控制台包。
dev-main / 1.x-dev
2024-09-22 12:40 UTC
Requires
- php: >=8.0
- nacosvel/composer: ^1.0
- nacosvel/package: ^1.0
- symfony/console: ^6.0
This package is auto-updated.
Last update: 2024-09-22 12:51:12 UTC
README
需求
- PHP >= 8.0
- Symfony 控制台 ^6.0
安装
您可以通过 Composer 安装此包
composer require nacosvel/console
入门指南
php ns
Nacosvel Console 1.0.0 Usage: command [options] [arguments] Options: -h, --help Display help for the given command. When no command is given display help for the list command -q, --quiet Do not output any message -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: completion Dump the shell completion script help Display help for a command list List commands
快速示例
创建命令类
<?php namespace Nacosvel\Console\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; class DemoCommand extends Command { /** * @var string|null The default command name */ protected static $defaultName = 'demo'; /** * @var string|null The default command description */ protected static $defaultDescription = 'demo description'; protected function handle(): int { $this->line($this->argument('name')); $this->line($this->option('option')); $this->line('line'); $this->newLine(); $this->info('info'); $this->warn('warn'); $this->error('error'); $this->question('question'); $this->comment('comment'); return self::SUCCESS; } /** * Get the console command arguments. * * @return array */ protected function getArguments(): array { return [ ['name', InputArgument::OPTIONAL, 'The name of the class', 'demo'], ]; } /** * Get the console command options. * * @return array */ protected function getOptions(): array { return [ ['option', 'o', InputOption::VALUE_OPTIONAL, 'description', 'default'], ]; } }
注册命令
<?php use Nacosvel\Console; $console = new Console\Kernel(); $console->add(new Console\Command\DemoCommand()); $console->run();
配置命令自动注册
{ // ... "extra": { "nacosvel": { "commands": [ // "Nacosvel\\Console\\Command\\DemoCommand" // Add your custom Command ] } } }
执行命令
php ns demo nacosvel -o console
许可协议
Nacosvel 控制台在 MIT 许可协议(MIT)下提供。请参阅 许可文件 了解更多信息。