MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / cmdCapture

Function cmdCapture

apps/desktop/src/cli/commands/capture.ts:14–40  ·  view source on GitHub ↗
(vault: string, args: ParsedArgs)

Source from the content-addressed store, hash-verified

12import { emitJson, emitLine, emitOk, truncate } from '../format.js'
13
14export 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"

Callers

nothing calls this directly

Calls 11

readStdinFunction · 0.85
getStringFunction · 0.85
getManyFunction · 0.85
deriveTitleFunction · 0.85
getBoolFunction · 0.85
emitJsonFunction · 0.85
emitOkFunction · 0.85
emitLineFunction · 0.85
truncateFunction · 0.85
composeBodyFunction · 0.70
createNoteFunction · 0.50

Tested by

no test coverage detected