Skip to content

feat: add --json output, fix config crash, extract validation utils#21

Open
flaggdavid-source wants to merge 2 commits intoApexOpsStudio:mainfrom
flaggdavid-source:fix/all-three-bounties
Open

feat: add --json output, fix config crash, extract validation utils#21
flaggdavid-source wants to merge 2 commits intoApexOpsStudio:mainfrom
flaggdavid-source:fix/all-three-bounties

Conversation

@flaggdavid-source
Copy link

Summary

Fixes #1, Fixes #2, Fixes #3

Three bounty issues resolved in one cohesive PR since the refactor (#3) is a dependency for clean implementations of the other two.

Changes

Issue #1 ($50) — Add --json output format

  • --json flag added to all subcommands (add, list, done)
  • list --json outputs valid JSON array of tasks
  • add --json and done --json output status confirmation objects
  • Human-readable output unchanged when flag is absent

Issue #2 ($75) — Fix crash when config file missing

  • load_config() now creates default config if ~/.config/task-cli/config.yaml is missing
  • Default values match config.yaml.example
  • Parent directories created automatically via mkdir(parents=True)

Issue #3 ($100) — Extract validation to utils module

  • New commands/utils.py with shared functions: validate_description(), validate_task_id(), get_tasks_file(), load_tasks(), save_tasks()
  • Removed duplicate get_tasks_file() from add.py, list.py, done.py
  • Removed scattered validation from individual command files
  • All commands now import from commands.utils
  • Added .gitignore for __pycache__/

Testing

8 tests, all passing:

test_validate_description        PASSED
test_validate_task_id            PASSED
test_load_config_creates_default PASSED
test_load_config_reads_existing  PASSED
test_list_tasks_json             PASSED
test_list_tasks_json_empty       PASSED
test_list_tasks_human            PASSED
test_save_and_load_tasks         PASSED

Demo

$ python task.py add "Buy groceries"
Added task 1: Buy groceries

$ python task.py list --json
[
  {"id": 1, "description": "Buy groceries", "done": false}
]

$ python task.py done 1 --json
Marked task 1 as done: Buy groceries
{"status": "done", "task_id": 1}

Three bounty fixes in one cohesive change:

**Issue ApexOpsStudio#1 ($50) — Add --json output format**
- Added --json flag to all subcommands (add, list, done)
- list --json outputs valid JSON array of tasks
- add/done --json output status confirmation objects

**Issue ApexOpsStudio#2 ($75) — Fix crash when config file missing**
- load_config() now creates default config if missing instead of crashing
- Default config matches config.yaml.example values
- Parent directories created automatically

**Issue ApexOpsStudio#3 ($100) — Extract validation to utils module**
- Created commands/utils.py with shared functions:
  validate_description(), validate_task_id(), get_tasks_file(),
  load_tasks(), save_tasks()
- Removed duplicated get_tasks_file() from all command modules
- Removed scattered validation functions from individual commands
- All commands now import from utils

Tests: 8 tests covering validation, config creation, JSON output,
and save/load round-trips. All passing.

Fixes ApexOpsStudio#1, Fixes ApexOpsStudio#2, Fixes ApexOpsStudio#3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Extract validation to utils module Fix: Crash when config file missing Add --json output format

1 participant