gemini-image-translator/scripts/run.ts

39 lines
1.0 KiB
TypeScript

#!/usr/bin/env bun
function printUsage(): void {
console.error(`Usage:
bun scripts/run.ts translate <image-path> [target-language] [output-path] [--dry-run]
Commands:
translate <image-path> [target-language] [output-path]
Config:
GEMINI_API_KEY=<your-api-key>
`);
}
async function main(): Promise<void> {
const positionals: string[] = [];
let dryRun = false;
for (const arg of process.argv.slice(2)) {
if (arg === '--dry-run') {
dryRun = true;
} else if (arg === '-h' || arg === '--help') {
printUsage(); process.exit(0);
} else {
positionals.push(arg);
}
}
if (positionals.length < 1) { printUsage(); process.exit(1); }
const { run } = await import('../src/index.ts');
const result = await run(positionals[0] as 'translate', positionals.slice(1), dryRun);
console.log(JSON.stringify(result, null, 2));
}
main().catch((err) => {
console.error(JSON.stringify({ status: 'failed', error: err instanceof Error ? err.message : String(err) }, null, 2));
process.exit(1);
});