ordinary / command
用于标准化从shell运行的文件、函数和类结构的库。
2.3.0
2023-05-12 20:55 UTC
Requires
- php: ^8.2
Requires (Dev)
- captainhook/captainhook: ^5.16
- captainhook/plugin-composer: ^5.3
- ordinary/coding-style: ^1.1
- overtrue/phplint: ^9.0
- phpunit/phpunit: ^10.1
- psalm/plugin-phpunit: ^0.18
- roave/security-advisories: dev-latest
- slevomat/coding-standard: ^8.11
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.11
README
入门指南
使用composer进行安装。
composer require ordinary/command
示例
直接在可执行文件中
创建类。
class MyCommand extends \Ordinary\Command\Command { public function run() : int { // do something return 0; // int 0-255 exit status } public function showHelp() : void { fwrite($this->stdout(), <<<HELP My Help Content HELP); } public function beforeExecute() : ?int { // do stuff before help screen and before run return null; // return null to continue or int error status for early exit } }
创建具有执行权限的可执行文件。
#!/usr/bin/env php <?php ## my-cmd.php use Ordinary\Command\CommandExec; use Ordinary\Command\Command; $exec = new CommandExec(); /** @var Command $cmd */ $cmd = new MyCommand(); exit($exec->execute( $cmd->withArgs($_SERVER['argv']) ->withStreams(STDIN, STDOUT, STDERR) ));
运行文件
./my-cmd.php