An open API service indexing awesome lists of open source software.

https://github.com/php-tui/cli-parser

Type-safe CLI argument parser
https://github.com/php-tui/cli-parser

Last synced: 4 months ago
JSON representation

Type-safe CLI argument parser

Awesome Lists containing this project

README

          

CLI Parser and Handler
======================

> warning: don't usr this, it's a failed experiment!

Type safe CLI parser and command handler for PHP inspired by [Kong](https://github.com/alecthomas/kong).

Features
--------

- Casts arguments and options into objects.
- Command bus and middleware architecture.
- Parsing
- Command nesting
- Type support for `string`, `int`, `float`, `boolean` and `lists`.
- Repeated arguments
- Optional arguments
- Long and short options
- Boolean options (flags)
- List options

Usage Example
-------------

```php
init = new InitCmd();
$cli->clone = new CloneCmd();

$application = ApplicationBuilder::fromSpecification($cli)
->prependMiddleware(new HelpMiddleware(new AsciiPrinter()))
->addHandler(InitCmd::class, function (Context $ctx) {
echo 'Initializing' . "\n";
return 0;
})
->addHandler(CloneCmd::class, function (Context $ctx) {
echo sprintf('Git cloning %s...', $ctx->command()->repo) . "\n";
if ($ctx->command()->recurseSubModules) {
echo '... and recursing submodules' . "\n";
}
return 0;
})
->build();

exit($application->run($argv));
```

Contribution
------------

Contribute!