3 KiB
3 KiB
Tasker Specification
This document defines the technical specifications for the getphred/tasker runner, the central CLI manager for the Phred Framework.
1. Core Architecture
Tasker is a command runner that orchestrates command discovery, dependency injection, and execution using ConsoleContracts and TaskerBridges.
1.1 Command Discovery
- Discovery Strategy:
- Explicit Registration: Commands registered directly via the Tasker API.
- Composer Discovery: Scans installed packages for the
extra.phred-taskerkey incomposer.json.
- Composer Schema:
"extra": { "phred-tasker": { "commands": [ "Phred\\Library\\Command\\ExampleCommand" ] } }
1.2 Dependency Injection
- Tasker must be initialized with a PSR-11
ContainerInterface. - All commands are resolved from the container to support constructor injection.
2. Runner Behavior
2.1 Argument & Option Parsing
- Tasker will implement a basic
argvparser to support standard flags:-v,-vv,-vvv,-q(Verbosity)-nor--no-interaction(Non-interactive)--no-ansi(Color/Decoration)-h,--help(Help information)
2.2 Execution Lifecycle
- Initialize Runner: Boot with a PSR-11 container.
- Discover Commands: Resolve commands from container and/or
composer.json. - Parse Input: Detect the target command and global flags.
- Resolve Command: Retrieve the
CommandInterfaceinstance from the container. - Orchestrate Middleware: Apply any registered
ConsoleMiddlewareInterfaceinstances. - Execute: Call
execute()on the command (or middleware chain). - Handle Output & Errors: Capture exit codes and map exceptions to
sysexits.hstandards.
2.3 Middleware Execution
- Middleware Resolution: Retrieve registered middleware from the PSR-11 container.
- Execution Chain: Construct a callable chain where each middleware can inspect/modify the
Command,Input, andOutputbefore passing control to the next layer. - Command Execution: The final layer of the chain executes the command's
execute()method.
3. Global Commands
Tasker provides the following built-in commands:
list: Lists all registered commands.help: Displays help for a specific command, including arguments and options.
4. Middleware Stack
Tasker implements a standard middleware runner:
- Middleware is resolved from the DI container.
- Middleware handles cross-cutting concerns (logging, locking, etc.).
- The execution chain is wrapped in a top-level
try/catchto ensure clean exit codes.
5. Exit Code Standards
Tasker follows the sysexits.h standard. The runner will capture any \Throwable and map it as follows:
Phred\ConsoleContracts\ConsoleExceptionInterface-> Mapped according to internal implementation.\InvalidArgumentException->ExitCode::USAGE(64)\RuntimeException->ExitCode::SOFTWARE(70)- All other exceptions ->
ExitCode::SOFTWARE(70)