(vault: string, args: ParsedArgs)
| 12 | import { emitJson, emitLine, emitOk, truncate } from '../format.js' |
| 13 | |
| 14 | export async function cmdCapture(vault: string, args: ParsedArgs): Promise<void> { |
| 15 | const positional = args.positionals.join(' ').trim() |
| 16 | const stdin = process.stdin.isTTY ? '' : await readStdin() |
| 17 | const body = positional || stdin.trim() |
| 18 | if (!body) { |
| 19 | throw new Error( |
| 20 | 'zn capture needs text. Pass it as a positional argument or pipe via stdin.' |
| 21 | ) |
| 22 | } |
| 23 | const folder = (getString(args, 'folder') as 'inbox' | 'quick' | 'archive' | undefined) ?? 'inbox' |
| 24 | if (folder !== 'inbox' && folder !== 'quick' && folder !== 'archive') { |
| 25 | throw new Error('zn capture --folder must be inbox, quick, or archive.') |
| 26 | } |
| 27 | const tags = getMany(args, 'tag').map((t) => t.replace(/^#/, '')) |
| 28 | |
| 29 | const titleOverride = getString(args, 'title') |
| 30 | const title = titleOverride ?? deriveTitle(body) |
| 31 | const composed = composeBody(title, body, tags) |
| 32 | const meta = await createNote(vault, folder, title, '', composed) |
| 33 | |
| 34 | if (getBool(args, 'json')) { |
| 35 | emitJson(meta) |
| 36 | return |
| 37 | } |
| 38 | emitOk(`Captured ${meta.path}`) |
| 39 | emitLine(` ${truncate(body.replace(/\s+/g, ' ').trim(), 80)}`) |
| 40 | } |
| 41 | |
| 42 | /** First non-empty line, stripped of its leading marker and capped at 60 |
| 43 | * chars. So a captured task `- [ ] buy milk` titles the note "buy milk" |
nothing calls this directly
no test coverage detected