| 8 | import { emitJson, emitLine, emitOk, pad, truncate } from '../format.js' |
| 9 | |
| 10 | export async function cmdTaskList(vault: string, args: ParsedArgs): Promise<void> { |
| 11 | const showAll = getBool(args, 'all') |
| 12 | const onlyUnchecked = getBool(args, 'unchecked') |
| 13 | const tag = getString(args, 'tag')?.replace(/^#/, '').toLowerCase() |
| 14 | |
| 15 | let tasks = await scanAllTasks(vault) |
| 16 | if (!showAll) { |
| 17 | if (onlyUnchecked) tasks = tasks.filter((t) => !t.checked) |
| 18 | else tasks = tasks.filter((t) => !t.checked && !t.waiting) |
| 19 | } |
| 20 | if (tag) tasks = tasks.filter((t) => t.tags.includes(tag)) |
| 21 | |
| 22 | if (getBool(args, 'json')) { |
| 23 | emitJson(tasks) |
| 24 | return |
| 25 | } |
| 26 | if (tasks.length === 0) { |
| 27 | emitLine('No tasks found.') |
| 28 | return |
| 29 | } |
| 30 | for (const t of tasks) { |
| 31 | const box = t.checked ? '[x]' : t.waiting ? '[~]' : '[ ]' |
| 32 | const due = t.due ? ` due:${t.due}` : '' |
| 33 | const pri = t.priority ? ` !${t.priority}` : '' |
| 34 | emitLine(`${box} ${pad(t.id, 40)} ${truncate(t.content, 80)}${due}${pri}`) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export async function cmdTaskToggle(vault: string, args: ParsedArgs): Promise<void> { |
| 39 | const id = getString(args, 'id') ?? args.positionals[0] |