import { Command } from "commander"; import { loadConfig } from "./config.js"; import { runUpdate } from "./lib.js"; import { getPaths } from "./utils.js"; const program = new Command(); program .name("ddns") .description("ddns") .version("1.0.0") .option("-c, --config ", "path to config file") .option("-d, --domain ", "domain to update") .option("-k, --api-key ", "porkbun API Key") .option("-s, --secret-api-key ", "porkbun secret API Key") .option( "--ip ", "comma separated list of old IPs to look for (first run)", ) .option("-f, --force", "force update even if IP hasn't changed") .option("--dry-run", "simulate updates without changing records") .option("--show-paths", "show where config and state files are stored") .action(async (options) => { if (options.showPaths) { const paths = getPaths(); console.log("config File:", paths.configFile); console.log("state File: ", paths.stateFile); process.exit(0); } const cliConfig = { apiKey: options.apiKey, secretApiKey: options.secretApiKey, domain: options.domain, initialIps: options.ip ? options.ip.split(",") : undefined, }; const config = await loadConfig(cliConfig, options.config); try { await runUpdate(config, { force: options.force, dryRun: options.dryRun, }); } catch (error) { console.error("error:"); console.error((error as Error).message); process.exit(1); } }); program.parse();