/** * CLI argument parsing — no external deps, uses Node's parseArgs. */ import { parseArgs as nodeParseArgs } from 'util'; const HELP = ` Usage: delta-backup [options] Commands: run Full backup run (clear PEND, rsync, delta, commit, promote) status Show current state Options: --source SOURCE directory (required) --base Sets --prev, --pend, --deltas as subdirs of base path --prev PREV directory (default: /previous) --pend PEND directory (default: /pending) --deltas DELTAS directory (default: /deltas) --backend Delta backend: zstd (default), xdelta3 --config Load options from JSON config file (flags override) --dry-run Print what would happen, execute nothing --help Show this help `.trim(); export function parseArgs(argv) { const { values, positionals } = nodeParseArgs({ args: argv, options: { source: { type: 'string' }, base: { type: 'string' }, prev: { type: 'string' }, pend: { type: 'string' }, deltas: { type: 'string' }, backend: { type: 'string' }, config: { type: 'string' }, 'dry-run': { type: 'boolean', default: false }, help: { type: 'boolean', default: false }, }, allowPositionals: true, }); if (values.help) { console.log(HELP); process.exit(0); } const command = positionals[0]; if (!command) { console.error('Error: command required (run, status)\n'); console.error(HELP); process.exit(1); } return { ...values, command, dryRun: values['dry-run'] }; }