Tasker/README.md

73 lines
2.6 KiB
Markdown
Raw Normal View History

# Tasker
A CLI tool manager for the Phred Framework, designed to streamline development tasks and project management.
## Quick Start
### 1. Installation
Tasker is typically installed via Composer as part of the Phred Framework, but can be used as a standalone runner.
```json
{
"require": {
"getphred/tasker": "dev-master"
}
}
```
### 2. Basic Usage
The primary entry point is the `bin/tasker` executable.
```bash
./vendor/bin/tasker list
```
### 3. Command Discovery
Tasker automatically discovers commands defined in your `composer.json` or in any installed package's `composer.json` using the `extra.phred-tasker` key.
```json
{
"extra": {
"phred-tasker": {
"commands": [
"App\\Commands\\MyCustomCommand"
]
}
}
}
```
### 4. Implementing a Command
Commands must implement `Phred\ConsoleContracts\CommandInterface`.
```php
namespace App\Commands;
use Phred\ConsoleContracts\CommandInterface;
use Phred\ConsoleContracts\InputInterface;
use Phred\ConsoleContracts\OutputInterface;
class MyCustomCommand implements CommandInterface
{
public function getName(): string { return 'my:command'; }
public function getDescription(): string { return 'My custom command description'; }
public function getArguments(): array { return ['name' => 'The name to greet']; }
public function getOptions(): array { return []; }
public function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name', 'World');
$output->writeln("<info>Hello, {$name}!</info>");
return 0;
}
}
```
### 5. Dependency Injection
Tasker supports PSR-11 containers. Pass your container to the `Runner` constructor to enable dependency injection for your commands.
```php
use Phred\Tasker\Runner;
$runner = new Runner($myContainer);
$runner->discover();
// ... execute runner
```
## Global Flags
- `-v|-vv|-vvv`: Increase verbosity of output.
- `-q|--quiet`: Suppress all output.
- `-n|--no-interaction`: Do not ask any interactive questions.
- `--no-ansi`: Disable ANSI output.
- `-h|--help`: Display help for the given command.
## Troubleshooting
### Command not found
- Ensure the command class is correctly listed in `composer.json` under `extra.phred-tasker.commands`.
- Run `composer dump-autoload` to ensure the class is discoverable.
- Check if the command class implements `Phred\ConsoleContracts\CommandInterface`.
### Missing dependencies
- If using a container, ensure the command is registered in the container or has a public parameterless constructor if you want Tasker to instantiate it directly.