Search by

raxos / terminal

basmilius

Base classes for custom terminals with command support.

3.2.0 2026-10-02 17:11 UTC

README

Bas Milius

Raxos Terminal

Build command-line applications with command attributes, typed input and console output.

Documentation | Packagist | Raxos

  • Named commands with positional arguments and options.
  • Generated help, middleware and optional container injection.
  • A printer for messages, tables and interactive input.
  • Argument parsing that preserves shell token boundaries and the -- separator.

Installation

Requires PHP 8.5 or later. Enable the mbstring PHP extension. Composer checks the remaining package and extension dependencies declared in composer.json.

composer require "raxos/terminal:^3.2"

Usage

<?php
declare(strict_types=1);

use Raxos\Contract\Terminal\CommandInterface;
use Raxos\Contract\Terminal\TerminalInterface;
use Raxos\Terminal\Attribute\Argument;
use Raxos\Terminal\Attribute\Command;
use Raxos\Terminal\Printer;
use Raxos\Terminal\Terminal;

require __DIR__ . '/vendor/autoload.php';

#[Command(name: 'greet', description: 'Print a greeting.')]
final readonly class GreetCommand implements CommandInterface
{
    public function __construct(#[Argument] public string $name = 'World') {}

    public function execute(TerminalInterface $terminal, Printer $printer): void
    {
        $printer->out("Hello {$this->name}");
    }
}

$terminal = new Terminal();
$terminal->register(GreetCommand::class);
$terminal->execute();

Save the example as console.php in your application root and run php console.php greet Ada. Run php console.php help to list commands. Declare positional arguments before options. Class or interface constructor dependencies require a container passed to the terminal.

Documentation

Testing

Run this library's Pest suite from the Raxos workspace:

git clone --recurse-submodules https://github.com/basmilius/raxos.git
cd raxos
composer install
vendor/bin/pest --testsuite=terminal

See Testing Raxos for PHP extensions, integration services and coverage commands. The library's Tests workflow also runs in GitHub Actions.

License

MIT. Copyright (c) 2017 - present Bas Milius.