()
| 113 | } |
| 114 | |
| 115 | function main() { |
| 116 | |
| 117 | const program = new Command(); |
| 118 | |
| 119 | // Version from package.json |
| 120 | const packageJson = JSON.parse( |
| 121 | fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8') |
| 122 | ); |
| 123 | |
| 124 | // Make the version trivial to reach. commander's `.version()` (below) wires up |
| 125 | // `--version` and `-V`; intercept the spellings it can't — lowercase `-v` and |
| 126 | // single-dash `-version` — before any parsing. (commander's version short flag |
| 127 | // is the capital `-V`, and its parser rejects a multi-character single-dash |
| 128 | // flag.) The bare `codegraph version` subcommand is registered further down so |
| 129 | // the affordance also shows up in `codegraph --help`. |
| 130 | const firstArg = process.argv[2]; |
| 131 | if (firstArg === '-v' || firstArg === '-version') { |
| 132 | console.log(packageJson.version); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | // ============================================================================= |
| 137 | // ANSI Color Helpers (avoid chalk ESM issues) |
| 138 | // ============================================================================= |
| 139 | |
| 140 | const colors = { |
| 141 | reset: '\x1b[0m', |
| 142 | bold: '\x1b[1m', |
| 143 | dim: '\x1b[2m', |
| 144 | red: '\x1b[31m', |
| 145 | green: '\x1b[32m', |
| 146 | yellow: '\x1b[33m', |
| 147 | blue: '\x1b[34m', |
| 148 | cyan: '\x1b[36m', |
| 149 | white: '\x1b[37m', |
| 150 | gray: '\x1b[90m', |
| 151 | }; |
| 152 | |
| 153 | const chalk = { |
| 154 | bold: (s: string) => `${colors.bold}${s}${colors.reset}`, |
| 155 | dim: (s: string) => `${colors.dim}${s}${colors.reset}`, |
| 156 | red: (s: string) => `${colors.red}${s}${colors.reset}`, |
| 157 | green: (s: string) => `${colors.green}${s}${colors.reset}`, |
| 158 | yellow: (s: string) => `${colors.yellow}${s}${colors.reset}`, |
| 159 | blue: (s: string) => `${colors.blue}${s}${colors.reset}`, |
| 160 | cyan: (s: string) => `${colors.cyan}${s}${colors.reset}`, |
| 161 | white: (s: string) => `${colors.white}${s}${colors.reset}`, |
| 162 | gray: (s: string) => `${colors.gray}${s}${colors.reset}`, |
| 163 | }; |
| 164 | |
| 165 | program |
| 166 | .name('codegraph') |
| 167 | .description('Code intelligence and knowledge graph for any codebase') |
| 168 | .version(packageJson.version); |
| 169 | |
| 170 | // Anonymous usage telemetry (see TELEMETRY.md): record the invoked subcommand |
| 171 | // NAME only — never arguments or paths. Counts buffer locally; network sends |
| 172 | // piggyback on commands that run long anyway (quick commands only append to |
no test coverage detected