A PHP CLI Library Inspired by Rust's CLAP

Maintainers

Package info

github.com/imgurbot12/slap

pkg:composer/imgurbot12/slap

Statistics

Installs: 357

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-01-22 07:45 UTC

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);