UNPKG

@pgsql/cli

Version:

Unified CLI for PostgreSQL AST parsing, deparsing, and code generation

62 lines (61 loc) 2.04 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const minimist_1 = __importDefault(require("minimist")); const chalk_1 = __importDefault(require("chalk")); const parse_1 = require("./commands/parse"); const deparse_1 = require("./commands/deparse"); const proto_gen_1 = require("./commands/proto-gen"); const proto_fetch_1 = require("./commands/proto-fetch"); const runtime_schema_1 = require("./commands/runtime-schema"); const help_1 = require("./utils/help"); const argv = (0, minimist_1.default)(process.argv.slice(2), { alias: { h: 'help', v: 'version', o: 'output', f: 'format' } }); const command = argv._[0]; async function main() { try { if (argv.version) { (0, help_1.showVersion)(); process.exit(0); } if (!command || argv.help) { (0, help_1.showHelp)(command); process.exit(0); } switch (command) { case 'parse': await (0, parse_1.parseCommand)(argv); break; case 'deparse': await (0, deparse_1.deparseCommand)(argv); break; case 'proto-gen': await (0, proto_gen_1.protoGenCommand)(argv); break; case 'proto-fetch': await (0, proto_fetch_1.protoFetchCommand)(argv); break; case 'runtime-schema': await (0, runtime_schema_1.runtimeSchemaCommand)(argv); break; default: console.error(chalk_1.default.red(`Unknown command: ${command}`)); (0, help_1.showHelp)(); process.exit(1); } } catch (error) { console.error(chalk_1.default.red('Error:'), error.message || error); process.exit(1); } } main();