adachsoft / task-cli
Standalone Symfony Console CLI for viewing and copying tasks, sub-tasks and comments via adachsoft/task-contracts.
Requires
- php: >=8.3
- adachsoft/task-api-repository: ^0.2
- adachsoft/task-contracts: ^3.0
- psr/container: ^2.0
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/service-contracts: ^3.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.4
- rector/rector: ^2.9
- symfony/config: ^7.3
- symfony/yaml: ^7.3
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Standalone Symfony Console command set for reading and copying task data exposed through
adachsoft/task-contracts.
The package does not ship a ready-made binary. It provides production-ready console commands, renderers, repository routing and backup services that you register in your own Symfony Console application (or in any PSR-11 based container).
Purpose
task-cli gives you a thin, framework-agnostic command layer on top of task repositories:
- list tasks, sub-tasks and comments,
- inspect a single task with its status, hierarchy and comments,
- copy tasks, dependencies, comments and attachments between two configured repositories,
- create, list and restore full or incremental JSONL backups,
- switch the active repository at runtime with a
--repositoryoption, - render results as human-readable text tables or as JSON.
All persistence is delegated to contracts from adachsoft/task-contracts; this package only
orchestrates them.
Features
- Task overview:
task:showlists tasks (id - description), filters by status or parent task, and renders a full task detail with sub-tasks and comments when an identifier is given. - Repository aware: every command works against aliases (for example
json,api) resolved byTaskRepositoryRegistry, so an application can expose several independent backends. - Copy engine:
task:copycopies tasks, parent relations, dependencies, comments and attachments between aliases with explicit policies (--limit,--clear-target,--fail-if-target-not-empty). - Backups:
task:backup:create,task:backup:listandtask:backup:restoreoperate on checksum-validated JSONL archives stored byJsonlBackupStorebehind theBackupStoreInterfacecontract. - Pluggable output:
TaskOutputRendererRegistryresolves renderers perOutputFormatEnum(text,json); adding a format is a matter of implementingTaskOutputRendererInterface. - Task API support:
TaskApiRepositoryFactorybuilds repositories backed by the Task REST API and normalizes base URLs that already end with/apior/api/v1. - Typed and strict:
declare(strict_types=1)everywhere, readonly services, final classes, enums for formats and backup modes.
Requirements
- PHP 8.3 or newer
symfony/consolesymfony/dependency-injection(used forServiceLocatorbased wiring)adachsoft/task-contracts- a task repository implementation to talk to, for example
adachsoft/task-api-repositoryor your own in-memory/JSON repository
Installation
composer require adachsoft/task-cli
Integration
1. Provide repositories
Register one task repository, one comment repository and (optionally) attachment repositories per
alias. Repositories must implement the corresponding adachsoft/task-contracts interfaces.
<?php
declare(strict_types=1);
use AdachSoft\TaskCli\Factory\TaskApiRepositoryFactory;
$apiBaseUrl = 'https://tasks.example.com/api/v1';
$apiKey = getenv('TASK_API_KEY') ?: '';
$apiTasks = TaskApiRepositoryFactory::createTaskRepository($apiBaseUrl, $apiKey);
$apiComments = TaskApiRepositoryFactory::createCommentRepository($apiBaseUrl, $apiKey);
2. Build the registry and routing repositories
<?php
declare(strict_types=1);
use AdachSoft\TaskCli\Repository\RoutingCommentRepository;
use AdachSoft\TaskCli\Repository\RoutingTaskRepository;
use AdachSoft\TaskCli\Repository\TaskRepositoryContext;
use AdachSoft\TaskCli\Repository\TaskRepositoryRegistry;
use Symfony\Component\DependencyInjection\ServiceLocator;
$taskRepositories = new ServiceLocator([
'json' => static fn (): object => $jsonTaskRepository,
'api' => static fn (): object => $apiTasks,
]);
$commentRepositories = new ServiceLocator([
'json' => static fn (): object => $jsonCommentRepository,
'api' => static fn (): object => $apiComments,
]);
$context = new TaskRepositoryContext();
$registry = new TaskRepositoryRegistry(
taskRepositories: $taskRepositories,
commentRepositories: $commentRepositories,
defaultAlias: 'json',
);
// Repositories used by the read services delegate to the alias selected by --repository.
$routingTaskRepository = new RoutingTaskRepository($registry, $context);
$routingCommentRepository = new RoutingCommentRepository($registry, $context);
TaskRepositoryRegistry accepts additional optional locators for attachment repositories,
attachment content storages, workflow definition repositories and task type definition
repositories. Aliases are discovered from ServiceProviderInterface locators or taken from the
explicit configuredAliases list; an alias is only exposed when both its task and comment
repository exist.
3. Register the commands
<?php
declare(strict_types=1);
use AdachSoft\TaskCli\Command\TaskBackupCreateCommand;
use AdachSoft\TaskCli\Command\TaskBackupListCommand;
use AdachSoft\TaskCli\Command\TaskBackupRestoreCommand;
use AdachSoft\TaskCli\Command\TaskCopyCommand;
use AdachSoft\TaskCli\Command\TaskRepositoryListCommand;
use AdachSoft\TaskCli\Command\TaskShowCommand;
use AdachSoft\TaskCli\Backup\JsonlBackupStore;
use AdachSoft\TaskCli\Backup\TaskBackupService;
use AdachSoft\TaskCli\Renderer\JsonTaskOutputRenderer;
use AdachSoft\TaskCli\Renderer\Table\AsciiBorderTableRenderer;
use AdachSoft\TaskCli\Renderer\TaskOutputRendererRegistry;
use AdachSoft\TaskCli\Renderer\TextTaskOutputRenderer;
use AdachSoft\TaskCli\Service\TaskDetailAssembler;
use AdachSoft\TaskCli\Service\TaskListAssembler;
use AdachSoft\TaskCli\Service\TaskRepositoryCopyService;
use Symfony\Component\Console\Application;
$renderers = new TaskOutputRendererRegistry([
new TextTaskOutputRenderer(new AsciiBorderTableRenderer()),
new JsonTaskOutputRenderer(),
]);
$backupStore = new JsonlBackupStore(__DIR__ . '/var/task-backups');
$backupService = new TaskBackupService(
$backupStore,
$routingTaskRepository,
$routingCommentRepository,
);
$application = new Application('task-cli');
$application->add(new TaskShowCommand(
new TaskListAssembler($routingTaskRepository, $routingCommentRepository),
new TaskDetailAssembler($routingTaskRepository, $routingCommentRepository),
$renderers,
$registry,
$context,
));
$application->add(new TaskCopyCommand(new TaskRepositoryCopyService($registry)));
$application->add(new TaskRepositoryListCommand($registry));
$application->add(new TaskBackupCreateCommand($backupService, $registry, $context));
$application->add(new TaskBackupListCommand($backupService));
$application->add(new TaskBackupRestoreCommand($backupService, $registry, $context));
$application->run();
With a Symfony DI container the same graph is expressed as service definitions; a YAML example is
available in docs/examples/repository-aliases.md.
Commands
| Command | Description |
|---|---|
task:show [<id>] | Lists tasks, or shows one task with sub-tasks and comments. |
task:copy | Copies tasks and related data between two repository aliases. |
task:repository:list | Lists configured aliases with their repository classes. |
task:backup:create | Creates a full or incremental backup archive. |
task:backup:list | Lists backup archives, newest first. |
task:backup:restore <backup-id> | Restores an archive as the authoritative repository state. |
task:show
php bin/console task:show
php bin/console task:show --status=in_progress
php bin/console task:show --parent-id=task42
php bin/console task:show task42
php bin/console task:show task42 --format=json
php bin/console task:show --repository=api
| Option | Description |
|---|---|
--format=text\|json | Output format, text by default. |
--status=<id> | Filters the list by status identifier. Ignored when an id argument is given. |
--parent-id=<id> | Lists direct children of the given task instead of all tasks. |
--repository=<alias> | Reads from the given alias instead of the default one. |
task:copy
php bin/console task:copy --count=json
php bin/console task:copy --source=json --target=api
php bin/console task:copy --source=api --target=json --clear-target
php bin/console task:copy --source=json --target=api --limit=100
php bin/console task:copy --source=json --target=api --repository-info
| Option | Description |
|---|---|
--source=<alias> | Alias of the source repository pair. |
--target=<alias> | Alias of the target repository pair. |
--count=<alias> | Prints the number of tasks in the given alias and exits. |
--repository-info | Prints the repository class names for --source and --target without copying. |
--limit=<n> | Copies at most n source tasks. |
--clear-target | Deletes visible target comments, attachments and tasks before copying. |
--fail-if-target-not-empty | Aborts when the target already contains data. |
The copy engine validates the whole operation before the first write: alias pairs must exist, source
parent/dependency references must be resolvable, the --limit value must be a non-negative
integer, and identifier collisions with a non-empty target are rejected. Attachments are copied
only when both aliases expose an attachment repository and content storage; otherwise the command
prints a warning and copies tasks and comments only.
task:repository:list
php bin/console task:repository:list
php bin/console task:repository:list --format=json
Prints alias, default marker, task repository class and comment repository class for every configured alias.
Backups
php bin/console task:backup:create --mode=full
php bin/console task:backup:create --mode=incremental --parent=<backup-id>
php bin/console task:backup:list --limit=25 --offset=0
php bin/console task:backup:restore <backup-id> --confirm
--mode=incrementalrequires--parentand stores only the delta against the parent archive.- Archives are written atomically and validated on read (line format, record count, checksum, size limits).
task:backup:restorereplaces the state of the active repositories and therefore requires--confirm.
Output formats
text renders ASCII tables (AsciiBorderTableRenderer) and a detail view with sub-tasks and
comments. json renders the same data as a JSON document, which is convenient for scripting and
for piping into other tools.
Examples
Step-by-step examples live in docs/examples/:
basic-usage.md— listing and inspecting tasks, JSON output, exit codes.repository-aliases.md— alias wiring, Symfony DI definitions, copying data between aliases.backups.md— full and incremental archives, listing, restore and the enforced format limits.
Extending
- New output format: implement
TaskOutputRendererInterface(format(),renderTaskList(),renderTaskDetail()) and pass the renderer toTaskOutputRendererRegistry. - New backup storage: implement
BackupStoreInterface(write(),readManifest(),readRecords(),listManifests()) and inject it intoTaskBackupService.JsonlBackupStoreis the reference implementation. - New backend: expose another alias in the registry; no command needs to change.
Development
composer install
vendor/bin/phpunit --configuration phpunit.xml
vendor/bin/phpstan analyse
vendor/bin/rector process src tests
vendor/bin/php-cs-fixer fix
License
MIT. See composer.json.