MCPcopy
hub / github.com/inkeep/open-knowledge / initCommand

Function initCommand

packages/cli/src/commands/init.ts:1507–1637  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1505}
1506
1507export function initCommand(): Command {
1508 return new Command('init')
1509 .description(
1510 `Scaffold ${OK_DIR}/ in the current directory and register the MCP server for your editor(s)`,
1511 )
1512 .option('--mcp', 'Register the MCP server for selected editors (default: true)', true)
1513 .option('--no-mcp', `Scaffold the ${OK_DIR}/ directory but do not touch MCP config`)
1514 .option(
1515 '--dev-mcp',
1516 'Register a local dev MCP entry using node + packages/cli/dist/cli.mjs with debug logging',
1517 )
1518 .option(
1519 '--content-dir <dir>',
1520 `Limit content to <dir> instead of the whole project. <dir> is interpreted relative to your current directory (e.g. "." = the folder you run the command in), then saved to ${OK_DIR}/config.yml as content.dir.`,
1521 )
1522 .option('--json', 'Emit a structured JSON summary to stdout (diagnostics stay on stderr)')
1523 .addOption(
1524 new Option(
1525 '--scope <scope>',
1526 'Write MCP config at user level, project level, or both',
1527 ).choices(['user', 'project', 'both']),
1528 )
1529 .addOption(
1530 new Option(
1531 '--shared',
1532 'Commit OK config alongside content (the default for fresh repos)',
1533 ).conflicts('localOnly'),
1534 )
1535 .addOption(
1536 new Option(
1537 '--local-only',
1538 'Keep OK config out of git via .git/info/exclude (per-clone, not committed)',
1539 ).conflicts('shared'),
1540 )
1541 .action(
1542 async (opts: {
1543 mcp?: boolean;
1544 devMcp?: boolean;
1545 scope?: McpScope;
1546 shared?: boolean;
1547 localOnly?: boolean;
1548 contentDir?: string;
1549 json?: boolean;
1550 }) => {
1551 const cwd = process.cwd();
1552
1553 const sharing: 'shared' | 'local-only' | undefined = opts.shared
1554 ? 'shared'
1555 : opts.localOnly
1556 ? 'local-only'
1557 : undefined;
1558 const restoreConsole = opts.json ? redirectStdoutConsoleToStderr() : null;
1559 try {
1560 let result: InitCommandResult;
1561 try {
1562 result = await runInit({
1563 cwd,
1564 mcp: opts.mcp,

Callers 2

cli.tsFile · 0.90
init.test.tsFile · 0.90

Calls 8

runInitFunction · 0.85
loadConfigFunction · 0.85
previewContentFunction · 0.85
buildInitJsonSummaryFunction · 0.85
formatInitResultFunction · 0.85
writeMethod · 0.65
resolveContentDirFunction · 0.50

Tested by

no test coverage detected