1688-logistics-scraper/scripts/run.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-03-14 02:35:01 +00:00
#!/usr/bin/env bun
import type { Command } from '../src/index.ts';
import { run } from '../src/index.ts';
function printUsage(): void {
console.error(`Usage:
bun scripts/run.ts [--api-base=<url>] <command> [args...] [--dry-run]
Commands:
run <arg>
Config: ~/.openclaw/.env (API_BASE)
2026-03-14 02:35:01 +00:00
`);
}
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.startsWith('--api-base=')) {
process.env.API_BASE = arg.slice('--api-base='.length).trim();
} else if (arg === '-h' || arg === '--help') {
printUsage(); process.exit(0);
} else {
positionals.push(arg);
}
}
if (positionals.length < 1) { printUsage(); process.exit(1); }
const result = await run(positionals[0] as Command, 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);
});