UNPKG

@magic-mustard/sqlsync

Version:

SQLSync simplifies database schema evolution by allowing a declarative approach to table management

57 lines (56 loc) 2.01 kB
"use strict"; // cli/class.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.SqlSyncCli = void 0; const commander_1 = require("commander"); const generate_1 = require("./generate"); class SqlSyncCli { constructor() { this.program = new commander_1.Command(); } /** * Sets up the global CLI options and registers sub-commands. */ initCli() { this.program .name('sqlsync') .description('Declarative SQL state management tool') .version('1.0.0') .option('-c, --config <path>', 'Path to the sqlsync.yaml config file', 'sqlsync.yaml') .option('-d, --debug', 'Enable debug output'); // Register command classes const commands = [ new generate_1.GenerateCommand(), //new SyncCommand(), //new StatusCommand(), //new UndoCommand(), //new MigrationsCommand(), ]; commands.forEach((cmd) => cmd.register(this.program)); } /** * Parses the command line arguments and returns the parsed command and options. * @returns {{ command: string, args: any }} */ parseArgs() { this.program.parse(process.argv); const parsed = this.program.opts(); const command = this.program.args[0]; // If the command is 'generate', extract migrationName and markApplied from command args/options if (command === 'generate') { const migrationName = this.program.args[1]; const markApplied = parsed.markApplied !== false; // default true const config = parsed.config; return { command, args: { migrationName, markApplied, config } }; } return { command, args: Object.assign(Object.assign({}, parsed), { args: this.program.args.slice(1) }) }; } } exports.SqlSyncCli = SqlSyncCli;