()
| 160 | } |
| 161 | |
| 162 | function main() { |
| 163 | |
| 164 | const program = new Command(); |
| 165 | |
| 166 | // Version from package.json |
| 167 | const packageJson = JSON.parse( |
| 168 | fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8') |
| 169 | ); |
| 170 | |
| 171 | // Make the version trivial to reach. commander's `.version()` (below) wires up |
| 172 | // `--version` and `-V`; intercept the spellings it can't — lowercase `-v` and |
| 173 | // single-dash `-version` — before any parsing. (commander's version short flag |
| 174 | // is the capital `-V`, and its parser rejects a multi-character single-dash |
| 175 | // flag.) The bare `codegraph version` subcommand is registered further down so |
| 176 | // the affordance also shows up in `codegraph --help`. |
| 177 | const firstArg = process.argv[2]; |
| 178 | if (firstArg === '-v' || firstArg === '-version') { |
| 179 | console.log(packageJson.version); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | // ============================================================================= |
| 184 | // ANSI Color Helpers (avoid chalk ESM issues) |
| 185 | // ============================================================================= |
| 186 | |
| 187 | // `--color` / `--no-color` are global and position-independent — they were |
| 188 | // already read by ansiColorsEnabled() at module load, so strip them before |
| 189 | // commander parses (a subcommand would otherwise reject the unknown flag). |
| 190 | process.argv = process.argv.filter((a) => a !== '--color' && a !== '--no-color'); |
| 191 | |
| 192 | const colors = COLORS_ENABLED |
| 193 | ? { |
| 194 | reset: '\x1b[0m', |
| 195 | bold: '\x1b[1m', |
| 196 | dim: '\x1b[2m', |
| 197 | red: '\x1b[31m', |
| 198 | green: '\x1b[32m', |
| 199 | yellow: '\x1b[33m', |
| 200 | blue: '\x1b[34m', |
| 201 | cyan: '\x1b[36m', |
| 202 | white: '\x1b[37m', |
| 203 | gray: '\x1b[90m', |
| 204 | } |
| 205 | : { |
| 206 | reset: '', |
| 207 | bold: '', |
| 208 | dim: '', |
| 209 | red: '', |
| 210 | green: '', |
| 211 | yellow: '', |
| 212 | blue: '', |
| 213 | cyan: '', |
| 214 | white: '', |
| 215 | gray: '', |
| 216 | }; |
| 217 | |
| 218 | const chalk = { |
| 219 | bold: (s: string) => `${colors.bold}${s}${colors.reset}`, |
no test coverage detected