(vault: string, args: ParsedArgs)
| 45 | } |
| 46 | |
| 47 | export async function cmdList(vault: string, args: ParsedArgs): Promise<void> { |
| 48 | const folder = parseFolderFlag(getString(args, 'folder')) |
| 49 | const tag = getString(args, 'tag')?.toLowerCase() |
| 50 | const limit = getNumber(args, 'limit') ?? 50 |
| 51 | let notes = await listNotes(vault) |
| 52 | notes = folder |
| 53 | ? notes.filter((n) => n.folder === folder) |
| 54 | : notes.filter((n) => n.folder !== 'trash') |
| 55 | if (tag) { |
| 56 | notes = notes.filter((n) => |
| 57 | n.tags.map((t) => t.toLowerCase()).includes(tag.replace(/^#/, '')) |
| 58 | ) |
| 59 | } |
| 60 | notes.sort((a, b) => b.updatedAt - a.updatedAt) |
| 61 | notes = notes.slice(0, limit) |
| 62 | |
| 63 | if (getBool(args, 'json')) { |
| 64 | emitJson(notes) |
| 65 | return |
| 66 | } |
| 67 | if (notes.length === 0) { |
| 68 | emitLine('No notes found.') |
| 69 | return |
| 70 | } |
| 71 | // Two-column terse layout: "<age> <folder> <path>". |
| 72 | const widestFolder = notes.reduce((w, n) => Math.max(w, n.folder.length), 0) |
| 73 | for (const n of notes) { |
| 74 | emitLine( |
| 75 | `${pad(formatRelativeAge(n.updatedAt), 10)} ${pad(n.folder, widestFolder)} ${n.path}` |
| 76 | ) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | export async function cmdRead(vault: string, args: ParsedArgs): Promise<void> { |
| 81 | const rel = requirePath(args) |
nothing calls this directly
no test coverage detected