Search by

adachsoft / task-cli

Arkadiusz Adach

Standalone Symfony Console CLI for viewing and copying tasks, sub-tasks and comments via adachsoft/task-contracts.

Package info

gitlab.com/a.adach/task-cli

Issues

pkg:composer/adachsoft/task-cli

Statistics

Installs: 12

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-27 22:50 UTC

This package is auto-updated.

Last update: 2026-11-27 21:51:17 UTC


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 --repository option,
  • 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:show lists 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 by TaskRepositoryRegistry, so an application can expose several independent backends.
  • Copy engine: task:copy copies 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:list and task:backup:restore operate on checksum-validated JSONL archives stored by JsonlBackupStore behind the BackupStoreInterface contract.
  • Pluggable output: TaskOutputRendererRegistry resolves renderers per OutputFormatEnum (text, json); adding a format is a matter of implementing TaskOutputRendererInterface.
  • Task API support: TaskApiRepositoryFactory builds repositories backed by the Task REST API and normalizes base URLs that already end with /api or /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/console
  • symfony/dependency-injection (used for ServiceLocator based wiring)
  • adachsoft/task-contracts
  • a task repository implementation to talk to, for example adachsoft/task-api-repository or 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

CommandDescription
task:show [<id>]Lists tasks, or shows one task with sub-tasks and comments.
task:copyCopies tasks and related data between two repository aliases.
task:repository:listLists configured aliases with their repository classes.
task:backup:createCreates a full or incremental backup archive.
task:backup:listLists 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
OptionDescription
--format=text\|jsonOutput 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
OptionDescription
--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-infoPrints the repository class names for --source and --target without copying.
--limit=<n>Copies at most n source tasks.
--clear-targetDeletes visible target comments, attachments and tasks before copying.
--fail-if-target-not-emptyAborts 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=incremental requires --parent and 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:restore replaces 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 to TaskOutputRendererRegistry.
  • New backup storage: implement BackupStoreInterface (write(), readManifest(), readRecords(), listManifests()) and inject it into TaskBackupService. JsonlBackupStore is 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.