import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { logStackTrace, mapLogLevelStringToNumber, setGlobalLogLevel, } from '../utils/log.js'; import { isCLIError } from './cli-error.js'; import { AnalyzeCommandConfig } from './commands/analyze/config.js'; import { runAnalyzeCommand } from './commands/analyze/run-analyze.js'; export function cli(): void { yargs(hideBin(process.argv)) .usage('Usage: $0 [glob..] [options]') .command({ command: ['analyze [glob..]', '$0'], describe: 'Analyzes component metadata.', handler: async config => { setGlobalLogLevel(mapLogLevelStringToNumber(config.logLevel)); try { await runAnalyzeCommand(config); } catch (e) { if (isCLIError(e)) { logStackTrace(e.message, e.stack!); } else { throw e; } } }, }) .example('$ $0 analyze', '') .option('cwd', { string: true, describe: 'The base path to use when emitting files (useful when working inside a monorepo).', default: process.cwd(), }) .option('logLevel', { describe: 'Select logging level.', nArgs: 1, choices: ['silent', 'error', 'warn', 'info', 'verbose'], default: 'info', }) .option('configFile', { string: true, describe: 'The path to your configuration file.', default: './celement.config.ts', }) .alias('v', 'version') .help('h') .wrap(110) .strict() .alias('h', 'help').argv; }