Add --section flag to add/update commands for structured node content, render sections and inline children in show, and add memory children command.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { Command } from 'commander';
|
|
import chalk from 'chalk';
|
|
import { findNodeByPrefix } from '../../core/store';
|
|
import { getConnections } from '../../core/graph';
|
|
import { NodeKind } from '../../types';
|
|
|
|
export const childrenCommand = new Command('children')
|
|
.argument('<id>', 'Parent node ID (or prefix)')
|
|
.option('--kind <kind>', 'Filter children by kind')
|
|
.option('--format <fmt>', 'Output format: text or json', 'text')
|
|
.description('List child nodes (outgoing "contains" edges)')
|
|
.action(async (idRaw: string, opts) => {
|
|
const node = findNodeByPrefix(idRaw);
|
|
if (!node) {
|
|
console.error(chalk.red(`Node not found: ${idRaw}`));
|
|
process.exit(1);
|
|
}
|
|
|
|
const conns = getConnections(node.id);
|
|
let children = conns.outgoing.filter(c => c.type === 'contains');
|
|
|
|
if (opts.kind) {
|
|
children = children.filter(c => c.node.kind === opts.kind);
|
|
}
|
|
|
|
if (opts.format === 'json') {
|
|
console.log(JSON.stringify(children.map(c => ({
|
|
id: c.node.id,
|
|
kind: c.node.kind,
|
|
title: c.node.title,
|
|
status: c.node.status,
|
|
})), null, 2));
|
|
return;
|
|
}
|
|
|
|
if (children.length === 0) {
|
|
console.log(chalk.dim('No children.'));
|
|
return;
|
|
}
|
|
|
|
console.log(chalk.bold(`Children of [${node.kind}] ${node.title}:`));
|
|
for (const c of children) {
|
|
console.log(` ${c.node.id.slice(0, 8)} [${c.node.kind}] ${c.node.title}`);
|
|
}
|
|
});
|