|
| 1 | +#!/usr/bin/env tsx |
| 2 | + |
| 3 | +import { Command } from 'commander'; |
| 4 | +import { scanLinks } from './scan-link.ts'; |
| 5 | + |
| 6 | +const program = new Command(); |
| 7 | + |
| 8 | +program.name('wener-cli').description("Wener's note management CLI tools").version('1.0.0'); |
| 9 | + |
| 10 | +program |
| 11 | + .command('scan-links') |
| 12 | + .description('Scan markdown files for links and generate JSON output') |
| 13 | + .option('-s, --scan-dir <dir...>', 'Directory to scan for markdown files (can be used multiple times)', [ |
| 14 | + 'notes', |
| 15 | + 'story', |
| 16 | + ]) |
| 17 | + .option('-o, --output <file>', 'Output file for links.json', 'local/links.json') |
| 18 | + .option('-m, --output-meta <file>', 'Output file for links.meta.json', 'local/links.meta.json') |
| 19 | + .action(async (options) => { |
| 20 | + try { |
| 21 | + // Handle multiple scan directories - commander collects multiple values into an array |
| 22 | + let scanDirs = options.scanDir; |
| 23 | + if (!Array.isArray(scanDirs)) { |
| 24 | + scanDirs = scanDirs ? [scanDirs] : []; |
| 25 | + } |
| 26 | + |
| 27 | + console.log(`🔍 Scanning directories: ${scanDirs.join(', ')}`); |
| 28 | + console.log(`📄 Output files:`); |
| 29 | + console.log(` - Links: ${options.output}`); |
| 30 | + console.log(` - Meta: ${options.outputMeta}`); |
| 31 | + |
| 32 | + await scanLinks({ |
| 33 | + scanDirs, |
| 34 | + outputFile: options.output, |
| 35 | + outputMetaFile: options.outputMeta, |
| 36 | + }); |
| 37 | + } catch (error) { |
| 38 | + console.error('❌ Error:', error); |
| 39 | + process.exit(1); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | +// Parse command line arguments |
| 44 | +program.parse(); |
0 commit comments