ricardopedias / freep-console
基于PHP的终端命令实现工具包
v1.2.0
2022-06-28 20:00 UTC
Requires
- php: ^8.0.0
- ricardopedias/freep-security: dev-main
Requires (Dev)
- codacy/coverage: dev-master
- phpmd/phpmd: @stable
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: 3.*
README
摘要
此存储库包含在PHP应用程序中轻松实现终端命令管理器的必要功能。
composer require ricardopedias/freep-console
有关详细信息,请参阅 文档摘要。
使用方法
1. 创建命令
基于抽象类 Freep\Console\Command
实现“my-command”命令
class MyCommand extends Command { protected function initialize(): void { $this->setName("my-command"); $this->addOption( new Option('-r', '--read', 'Read a text file', Option::REQUIRED) ); } protected function handle(Arguments $arguments): void { $this->info("Hello"); } }
2. 创建脚本
创建一个文件,例如命名为“myconsole”,并添加以下内容
#!/bin/php <?php include __DIR__ . "/vendor/autoload.php"; array_shift($argv); $terminal = new Freep\Console\Terminal("/root/of/super/application"); $terminal->loadCommandsFrom("/directory/of/commands"); $terminal->run($argv);
3. 运行脚本
./myconsole my-command -r
# will display: Hello
./myconsole my-command --help # will display: # # Command: my-command # Run the 'my-command' command # # How to use: # ./myconsole my-command [options] # # Options: # -h, --help Display command help # -r, --read Read a text file
./myconsole --help # will display: # # How to use: # ./myconsole command [options] [arguments] # # Options: # -h, --help Display command help # # Available commands: # help Display command help # my-command Run the 'my-command' command
特性
- 适用于PHP 8.0或更高版本;
- 采用最佳实践和最高质量编码;
- 文档完善且IDE友好;
- 使用TDD(测试驱动开发)开发;
- 使用PHPUnit实现单元测试;
- 用❤️ & ☕制作。