fenzland / cli
For build cli applications.
0.2.0
2018-04-15 16:24 UTC
Requires
- php: >=7.1
- fenzland/php-helpers: ^1.2
This package is not auto-updated.
Last update: 2024-11-10 06:17:42 UTC
README
A PHP CLI support library.
Basic Usage
1. Improt library by composer.
composer require fenzland/cli
require PROJECT_PATH.'/vendor/autoload.php';
2. Build your commands.
class FooCmd extends \Fenzland\CLI\ACmd { protected function main( \Fenzland\CLI\IArgs$args ):int { # TODO code of your command. } }
3. Build your cli entry.
PlanA: To run a single command.
vim foo.php
#!/usr/bin/env php <?php require PROJECT_PATH.'/vendor/autoload.php'; $cmd= new FooCmd; exit( $cmd->run( $argv ) );
chmod +x foo.php
PlanB: To run dozens of commands.
vim app.php
#!/usr/bin/env php <?php require PROJECT_PATH.'/vendor/autoload.php'; $app= new \Fenzland\CLI\App; $app->regCmd( 'foo', FooCmd::class ); $app->regCmd( 'bar', BarCmd::class ); # ... exit( $app->run( $argv ) );
chmod +x app.php