Skip to content
phatngth-devPublic

About

A small command-line task tracker built with .NET 11, System.CommandLine and ErrorOr. Tasks are persisted in a local JSON file.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Tracker CLI

A small command-line task tracker built with .NET 11, System.CommandLine and ErrorOr. Tasks are persisted in a local JSON file.

Features

  • Add tasks with an auto-generated ID.
  • List all tasks or filter by todo, in-progress, done or not-done.
  • Update a task description.
  • Delete a task.
  • Mark tasks as in progress or done.
  • Friendly validation, not-found, usage and corrupted-JSON errors.
  • Layered design with a railway-oriented application API.
  • Unit and integration test suites.

Requirements

Build

dotnet restore todo-cli.slnx
dotnet build todo-cli.slnx

Run from source:

dotnet run --project src/TaskTracker.Cli -- add "Buy groceries"

Run the built executable:

dotnet src/TaskTracker.Cli/bin/Debug/net11.0/task-cli.dll help

Publish an executable

Framework-dependent publish:

dotnet publish src/TaskTracker.Cli/TaskTracker.Cli.csproj -c Release -o publish
./publish/task-cli help

Self-contained single-file publish (Linux x64 example):

dotnet publish src/TaskTracker.Cli/TaskTracker.Cli.csproj \
  -c Release \
  -r linux-x64 \
  --self-contained true \
  -p:PublishSingleFile=true \
  -o publish/linux-x64
./publish/linux-x64/task-cli help

The published executable is named task-cli.

Usage

Usage:
  task-cli add <description>
  task-cli list [todo|in-progress|done|not-done]
  task-cli update <id> <description>
  task-cli delete <id>
  task-cli mark-in-progress <id>
  task-cli mark-done <id>
  task-cli help

Examples

task-cli add "Buy groceries"
# Task added successfully (ID: 1).

task-cli add "Walk the dog"
# Task added successfully (ID: 2).

task-cli list
# ID  STATUS       CREATED (UTC)        UPDATED (UTC)        DESCRIPTION
# --  -----------  -------------------  -------------------  -------------
# 1   todo         2026-01-01 12:00:00  2026-01-01 12:00:00  Buy groceries
# 2   todo         2026-01-01 12:01:00  2026-01-01 12:01:00  Walk the dog

task-cli mark-in-progress 1
# Task 1 marked as in-progress.

task-cli mark-done 2
# Task 2 marked as done.

task-cli list done
# ID  STATUS  CREATED (UTC)        UPDATED (UTC)        DESCRIPTION
# --  ------  -------------------  -------------------  ------------
# 2   done    2026-01-01 12:01:00  2026-01-01 12:02:00  Walk the dog

task-cli list not-done
# Lists every task whose status is not done.

task-cli update 1 "Buy groceries and cook dinner"
# Task 1 updated.

task-cli delete 2
# Task 2 deleted.

Built-in help

task-cli --help
task-cli add --help
task-cli --version

Data storage

By default the CLI reads and writes tasks.json in the current working directory. Override the path with TASKTRACKER_DATA_FILE:

TASKTRACKER_DATA_FILE=~/task-tracker/tasks.json task-cli list

A missing or empty file is treated as an empty task list. The file is created automatically the first time the CLI accesses it, including a list command. Example:

[
  {
    "id": 1,
    "description": "Buy groceries",
    "status": "in-progress",
    "createdAt": "2026-01-01T12:00:00Z",
    "updatedAt": "2026-01-01T12:05:00Z"
  }
]

Malformed JSON produces a storage error and does not overwrite the file.

Exit codes

Code Meaning
0 Success
1 Validation, not-found or storage failure
2 Invalid usage, such as an unknown status filter

Command-line parse errors (missing arguments, unknown commands, non-numeric IDs) are reported by System.CommandLine with a non-zero exit code and usage text.

Error codes

Error codes use dot-separated segments so each failure is identifiable.

Code Type Meaning
task.description.empty Validation Task description is empty
task.id.invalid Validation Task ID is not positive
task.not_found NotFound Task does not exist
task.id.duplicate Conflict A task with the same ID already exists
usage.status.invalid Custom 400 Unknown list filter
storage.json.invalid Custom 500 Tasks file contains malformed JSON
storage.read.failed Custom 500 Tasks file could not be read
storage.write.failed Custom 500 Tasks file could not be written

Architecture

The codebase is organised as vertical slices. Each feature owns its request handler, validation and business rule; the CLI only parses input, renders output and composes the handlers.

src/
  TaskTracker.Application/                  Business logic
    Features/
      AddTask/AddTaskHandler                Create a task
      ListTasks/ListTasksHandler            List and filter tasks
      UpdateTask/UpdateTaskHandler          Update a task description
      DeleteTask/DeleteTaskHandler          Delete a task
      ChangeTaskStatus/ChangeTaskStatusHandler  Mark in-progress / done
      Shared/                               TaskItem, status, filter, repository contract
    Infrastructure/JsonTaskRepository        JSON persistence adapter
  TaskTracker.Cli/                           Presentation only
    Commands/TaskCommandHandlers              Calls slices, formats output and exit codes
    Commands/TaskFilterParser                 Parses CLI filter names
    Program.cs                                Startup and dependency wiring
    TaskCli.cs                                System.CommandLine command tree
tests/
  TaskTracker.Application.Unit.Tests/         One test class per feature handler
  TaskTracker.Cli.Tests/
  TaskTracker.IntegrationTests/

Responsibilities

Concern Location
Parse commands and read arguments TaskTracker.Cli with System.CommandLine
Show help and display tasks/errors TaskTracker.Cli
Validate description and IDs Each application feature handler
Generate task IDs AddTaskHandler
Create, list, update, delete and change status Feature slices under Feature*/
Define repository interface and models TaskTracker.Application/Features/Shared
Serialize/deserialize JSON TaskTracker.Application/Infrastructure/JsonTaskRepository
Wire dependencies at startup TaskTracker.Cli/Program.cs

Slice handlers return ErrorOr<T> instead of throwing for expected failures. The CLI uses Then/Match to compose and render those results, while unexpected failures are still surfaced as exceptions at the process boundary.

Tests

dotnet test todo-cli.slnx

Test suites:

  • Application unit tests are grouped by feature slice and cover add, list, update, delete and status changes, including validation, ID generation and error propagation.
  • CLI unit tests cover command parsing and routing, output formatting, status parsing and exit codes.
  • Integration tests cover the JSON repository (including empty and malformed files), persistence across handler restarts and full CLI workflows.

License

MIT

About

A small command-line task tracker built with .NET 11, System.CommandLine and ErrorOr. Tasks are persisted in a local JSON file.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors