imgurbot12 / slap
A PHP CLI Library Inspired by Rust's CLAP
0.1.0
2026-01-22 07:45 UTC
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- psalm/phar: ^6.14
This package is auto-updated.
Last update: 2026-03-22 08:12:31 UTC
README
A PHP CLI Library Inspired by Rust's CLAP
Installation
$ composer require imgurbot12/slap
Usage
Slap supports a standard CLI builder mode which returns an untyped array as a result:
use Imgurbot12\Slap\Arg; use Imgurbot12\Slap\Command; use Imgurbot12\Slap\Flag; $app = Command::new('myapp') ->args(Arg::new('foo')->about('foo description')) ->flags(Flag::new('test')->short('t')->default('hello')) ->subcommands( Command::new('bar')->args(Arg::new('baz')->default('world')); $result = $app->parse(); print_r($result);
It also includes a derivation mode similar to clap:
use Imgurbot12\Slap\Derive\Command; use Imgurbot12\Slap\Derive\Flag; use Imgurbot12\Slap\Derive\Parser; use Imgurbot12\Slap\Derive\SubCommands; #[Command(name: 'bar')] class Bar { public string $baz = 'world'; } class Commands extends SubCommands { public Bar $bar; } #[Command(name: 'myapp')] class MyApp extends Parser { /** foo description */ public string $foo; #[Flag(short: 't')] public string $test = 'hello'; public Commands $command; } $result = MyApp::parse(); print_r($result);