alesinicio / clicommand
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alesinicio/clicommand
Requires
- php: ~8.1
- psr/container: ~1.0.0|~2.0.0
- psr/log: ~2.0.0|~3.0.0
This package is auto-updated.
Last update: 2025-10-28 21:47:26 UTC
README
This repo allows you to create CLI commands/handlers for your application.
It's rather easy: create classes that implement the Alesinicio\CLICommand\Commands\CLICommandInterface, register a command that binds to that class and voila!
Example
//Hello.php
<?php
namespace Your\Namespace;
class Hello implements Alesinicio\CLICommand\Commands\CLICommandInterface {
    public function run(mixed ...$args) : void {
        echo sprintf("Hello %s!\n", $args[0] ?? 'noname');
    }
}
//yourDependencyInjectionRegistry.php
<?php
$commandCollection = new Alesinicio\CLICommand\CommandCollection();
$commandCollection
    ->addCommand('hello', Your\Namespace\Hello::class)
;
//command.php
<?php
global $argc, $argv;
$di = loadYourDependencyInjectionContainer();
try {
	$di->get(Alesinicio\CLICommand\CLICommandHandler::class))->handle($argc, $argv);
} catch (Exception $e) {}
Now you can call your command.php script with the following format:
php command.php <command> <argument0> <argument1> ... <argumentN>`
$ php command.php hello master
Hello master!
Of course, the setup is all yours to make. You can also make the PHP entrypoint executable with a shebang!