Search by

rushphp / contract

stougeiro

Contracts for RUSH - Registry-driven Unified Shell Helper. Interfaces for tools, commands, input/output and configuration.

Package info

github.com/rushphp/contract

pkg:composer/rushphp/contract

Statistics

Installs: 35

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-11-23 16:10 UTC

This package is auto-updated.

Last update: 2026-11-23 18:08:14 UTC


README

English | Português

PHP PHPStan-Level License

RUSH Contract

RUSH — Registry-driven Unified Shell Helper.

Contracts that guide the RUSH manager and every tool built for it. This package contains only interfaces and small value types; it has no runtime dependencies.

Pre-1.0: minor releases may include breaking changes.

✨ Features

  • Registry-ready: every tool exposes a stable key() and commands().
  • Unified commands: one CommandInterface for every CLI command.
  • Standard I/O: InputInterface and OutputInterface keep tools decoupled from any concrete terminal implementation.
  • Configuration export: ProvidesConfigInterface lets tools publish side-effect-free config defaults.
  • Manager boundary: ToolManagerInterface defines the lifecycle the runtime must implement.

📦 Installation

composer require rushphp/contract

Requirements

  • PHP 8.3 or newer.
  • No runtime dependencies.

🧩 Contracts

Contract Purpose
ToolInterface A tool: key, metadata, commands and install layout.
CommandInterface A CLI command: metadata, options and execution.
InputInterface Normalized option/argument access.
OutputInterface Standard line/info/success/warning/error output.
ProvidesConfigInterface Side-effect-free configuration defaults.
ToolManagerInterface Attach, boot, run and terminate tools.
OperatorPolicyInterface Optional: opt a tool out of the operator gate.
Option Command option value type.
ExitCode Stable process exit codes.

Option semantics

  • takesValue defines whether --name value / --name=value is accepted.
  • default is applied by the manager when the option is absent (string, int or bool).
  • required makes the manager reject a missing option.
  • required takes precedence over default.
  • short maps a single-character flag (-n), including clusters (-abc).
  • repeatable collects every occurrence as a list, read via InputInterface::strings().
  • InputInterface::hasValue() tells whether an option is present with a value.
  • OutputInterface::write() writes without a trailing newline.

Tools that do not implement OperatorPolicyInterface require a configured operator for their commands, preserving the default audit behaviour.

Tool requirements

  • Tool classes must be instantiable without constructor arguments.
  • install() is required; return an empty list when the tool has nothing to install.

🛠️ Writing a tool

<?php declare(strict_types=1);

namespace Acme\Tool\Deploy;

use Rush\Contract\CommandInterface;
use Rush\Contract\ToolInterface;

final class DeployTool implements ToolInterface
{
    public function key(): string
    {
        return 'deploy';
    }

    public function name(): string
    {
        return 'Deploy';
    }

    public function description(): string
    {
        return 'Deploys the application.';
    }

    public function version(): string
    {
        return '0.1.0';
    }

    /** @return array<string, CommandInterface> */
    public function commands(string $projectRoot): array
    {
        return [
            'deploy push' => new PushCommand($projectRoot),
        ];
    }

    /** @return list<string> */
    public function install(string $projectRoot): array
    {
        return [];
    }
}

Register the tool class in composer.json:

"extra": {
    "rush": {
        "tool": "Acme\\Tool\\Deploy\\DeployTool"
    }
}

Then enable it in the project's rush.json:

{
    "tools": {
        "deploy": true
    }
}

🤝 Contributions

Contributions are welcome. Open an issue or submit a pull request.

📄 License

MIT. See LICENSE.