rushphp / contract
Contracts for RUSH - Registry-driven Unified Shell Helper. Interfaces for tools, commands, input/output and configuration.
Requires
- php: ^8.3
Requires (Dev)
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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()andcommands(). - Unified commands: one
CommandInterfacefor every CLI command. - Standard I/O:
InputInterfaceandOutputInterfacekeep tools decoupled from any concrete terminal implementation. - Configuration export:
ProvidesConfigInterfacelets tools publish side-effect-free config defaults. - Manager boundary:
ToolManagerInterfacedefines 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
takesValuedefines whether--name value/--name=valueis accepted.defaultis applied by the manager when the option is absent (string, int or bool).requiredmakes the manager reject a missing option.requiredtakes precedence overdefault.shortmaps a single-character flag (-n), including clusters (-abc).repeatablecollects every occurrence as a list, read viaInputInterface::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.