import { Command } from 'commander'; import chalk from 'chalk'; import { importObsidian } from '../../core/import/obsidian'; import { importMarkdown } from '../../core/import/markdown'; export const importCommand = new Command('import') .description('Import data from external sources') .argument('', 'Source type: obsidian, markdown') .argument('', 'Path to import from') .option('-t, --tags ', 'Additional tags (comma-separated)') .option('-k, --kind ', 'Node kind (default: memory)') .option('--hierarchy', 'Create folder hierarchy (obsidian only)') .option('--dry-run', 'Preview import without making changes') .action(async (source: string, inputPath: string, opts) => { try { const tags = opts.tags?.split(',').map((t: string) => t.trim()); switch (source.toLowerCase()) { case 'obsidian': { console.log(chalk.cyan(`Importing Obsidian vault from ${inputPath}...`)); const result = await importObsidian(inputPath, { kind: opts.kind, hierarchy: opts.hierarchy, dryRun: opts.dryRun, }); if (opts.dryRun) { console.log(chalk.yellow(`Dry run: would import ${result.imported} notes`)); console.log(chalk.dim(` Would create ${result.edges} edges from wikilinks`)); } else { console.log(chalk.green(`✓ Imported ${result.imported} notes`)); if (result.edges > 0) { console.log(chalk.dim(` Created ${result.edges} edges from wikilinks`)); } if (result.skipped > 0) { console.log(chalk.yellow(` Skipped ${result.skipped} files (already exist)`)); } } break; } case 'markdown': case 'md': { console.log(chalk.cyan(`Importing markdown files from ${inputPath}...`)); const result = await importMarkdown(inputPath, { kind: opts.kind as any, tags, dryRun: opts.dryRun, }); if (opts.dryRun) { console.log(chalk.yellow(`Dry run: would import ${result.imported} files`)); } else { console.log(chalk.green(`✓ Imported ${result.imported} files`)); } break; } default: console.error(chalk.red(`Unknown source type: ${source}`)); console.log(chalk.dim('Supported: obsidian, markdown')); process.exit(1); } } catch (err: any) { console.error(chalk.red(`Error: ${err.message}`)); process.exit(1); } });