todo icon indicating copy to clipboard operation
todo copied to clipboard

Add export command to dump tasks in csv/json/md

Open JianuoZhu opened this issue 8 months ago • 0 comments

Description

This pull request introduces a new export command that allows users to dump their task list in three popular formats—CSV, JSON, or Markdown—either to standard output or to a file. This makes it easy to share, archive, or further process your to-do data in other tools.


Changes

  • CLI parser (cli_parser.py)

    • Added an export subcommand with two options:
      • -f, --format (csv ⎼ default, json, or md)
      • -o, --output (path to write output; if omitted, writes to stdout)
    • Registered export in the COMMANDS set.
  • Command handler (todo.py)

    • Imported the standard csv and json modules.
    • Implemented export_tasks(args, daccess), which:
      1. Loads all tasks (including subcontexts) via daccess.todo(path='', recursive=True).
      2. Opens either the specified output file (UTF-8, newline-safe) or uses sys.stdout.
      3. For CSV, writes a header row (ID, Title, Context, Deadline, Start, Period, Priority, Status) and one row per task.
      4. For JSON, dumps the full task list with pretty-printing (indent=2).
      5. For Markdown, emits a GitHub-style table with the same columns.
    • Closes the file handle if an output path was provided.
    • Registered export_tasks under 'export' in the DISPATCHER map.

Usage Examples

# Export to CSV (default) on the terminal:
todo export

# Export to Markdown and save to tasks.md:
todo export -f md -o tasks.md

# Export to JSON and save to all_tasks.json:
todo export -f json -o all_tasks.json

JianuoZhu avatar May 21 '25 13:05 JianuoZhu