refactor(cli): split into summary and csv subcommands

- Add subparsers for 'summary' and 'csv' replacing the --summary flag
- Extract _add_shared_args(), _resolve_date(), _resolve_rows(), and
  _resolve_project_map() as shared helpers used by both subcommands
- Both subcommands support -o/--output to write to a file instead of stdout
- Update AGENTS.md with new subcommand usage examples
This commit is contained in:
Jef Roosens 2026-05-22 11:01:02 +02:00
parent 615bfe30e0
commit 6915d8d764
Signed by: Jef Roosens
GPG key ID: 119385BCAA005C21
2 changed files with 145 additions and 82 deletions

View file

@ -53,45 +53,41 @@ Do **not** use `pip` or `python` directly.
## CLI usage
The CLI has two subcommands: `summary` and `csv`. Both accept the same arguments.
```sh
# Print CSV to stdout (date defaults to today)
uv run timesheets --input input.md
# Human-readable summary for today (from Joplin)
uv run timesheets summary --joplin
# Specify a day (positional, accepts YYYY-MM-DD, MM-DD, or DD-MM; - or / separator)
uv run timesheets 2026-05-22 --input input.md
uv run timesheets 05-22 --input input.md
# Human-readable summary for a specific day
uv run timesheets summary 2026-05-22 --joplin
uv run timesheets summary yesterday --joplin
uv run timesheets summary 3 days ago --joplin
# Write CSV to a file
uv run timesheets --input input.md -o output.csv
# Export today's entries as CSV to stdout
uv run timesheets csv --joplin
# Override the day (accepts YYYY-MM-DD, MM-DD, or DD-MM; - or / separator)
uv run timesheets --input input.md --day 2026-05-22
uv run timesheets --input input.md --day 05-22
# Export to a file
uv run timesheets csv --joplin -o output.csv
# Use a specific project map file
uv run timesheets --input input.md --map /path/to/project_map.json
# Print a human-readable summary instead of CSV
uv run timesheets --input input.md --summary
# Use a local markdown file instead of Joplin
uv run timesheets summary --input timesheet.md
uv run timesheets csv --input timesheet.md -o output.csv
# Read from stdin
cat input.md | uv run timesheets --input -
cat timesheet.md | uv run timesheets csv --input -
# Fetch today's entries from Joplin (token via env var)
JOPLIN_TOKEN=your_token uv run timesheets --joplin
# Specify a day (positional, accepts YYYY-MM-DD, MM-DD, or DD-MM; - or / separator)
uv run timesheets csv 2026-05-22 --input input.md
uv run timesheets csv 05-22 --input input.md
# Use a specific project map file
uv run timesheets csv --input input.md --map /path/to/project_map.json
# Fetch entries for a specific day from Joplin
uv run timesheets 2026-05-22 --joplin --token your_token
uv run timesheets csv 2026-05-22 --joplin --token your_token
```
The `--joplin` flag and the file `input` argument are mutually exclusive.
When `--joplin` is used, only entries matching the target day (positional arg,
or today) are returned, filtered by the `# ... YYYY-MM-DD` day heading in the note.
The API token can be provided via:
- `--token <token>` CLI flag
- `JOPLIN_TOKEN` environment variable
`project_map.json` is auto-discovered in the current working directory if
`--map` is not provided.