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
- Host: GitHub
- URL: https://github.com/php-tui/cli-parser
- Owner: php-tui
- License: mit
- Created: 2024-01-21T20:55:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T21:58:23.000Z (almost 2 years ago)
- Last Synced: 2024-07-30T03:43:51.193Z (almost 2 years ago)
- Language: PHP
- Size: 86.9 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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!