UNPKG

@electric-sql/cli

Version:

ElectricSQL command line interface (CLI).

36 lines 1.1 kB
import { Command } from "commander"; import { spawnSync } from "child_process"; import { getConfig, envFromConfig } from '../config.js'; function makeWithConfigCommand() { return new Command("with-config").description("Run a command with config arguments substituted").arguments("<command>").action(async (command) => { withConfig(command); }); } function withConfig(command, config) { const _config = config || getConfig(); const env = process.env; const re = /\{{([A-Z_]+)}}/g; const cmd = command.replace(re, (match, envVar) => { const value = envVar.startsWith("ELECTRIC_") ? _config[envVar.slice("ELECTRIC_".length)] ?? env[envVar] : env[envVar]; if (value === void 0) { return match; } else if (typeof value === "string") { return value; } else { return value.toString(); } }).split(" "); return spawnSync(cmd[0], cmd.slice(1), { stdio: "inherit", shell: true, env: { ...env, ...envFromConfig(_config) } }); } export { makeWithConfigCommand, withConfig }; //# sourceMappingURL=command-with-config.js.map