mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
10849d4822
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
30 lines
1015 B
TypeScript
30 lines
1015 B
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { explainCommand, formatCommandExplanation } from '../src/commands/command-explain.ts';
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, '..');
|
|
const args = process.argv.slice(2);
|
|
const json = args.includes('--json');
|
|
const query = args.find((arg) => arg !== '--json');
|
|
|
|
if (!query) {
|
|
process.stderr.write('Usage: pnpm explain:command <command-or-catalog-key> [--json]\n');
|
|
process.exitCode = 1;
|
|
} else {
|
|
const result = explainCommand(query, {
|
|
fileExists: (file) => fs.existsSync(path.join(repoRoot, file)),
|
|
});
|
|
if (!result.found) {
|
|
const suffix =
|
|
result.suggestions.length === 0 ? '' : ` Did you mean: ${result.suggestions.join(', ')}?`;
|
|
process.stderr.write(`Unknown command "${result.query}".${suffix}\n`);
|
|
process.exitCode = 1;
|
|
} else {
|
|
process.stdout.write(
|
|
json
|
|
? `${JSON.stringify(result.explanation, null, 2)}\n`
|
|
: `${formatCommandExplanation(result.explanation)}\n`,
|
|
);
|
|
}
|
|
}
|