56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
/**
|
|
* CLI argument parsing — no external deps, uses Node's parseArgs.
|
|
*/
|
|
import { parseArgs as nodeParseArgs } from 'util';
|
|
|
|
const HELP = `
|
|
Usage: delta-backup [options] <command>
|
|
|
|
Commands:
|
|
run Full backup run (clear PEND, rsync, delta, commit, promote)
|
|
status Show current state
|
|
|
|
Options:
|
|
--source <path> SOURCE directory (required)
|
|
--base <path> Sets --prev, --pend, --deltas as subdirs of base path
|
|
--prev <path> PREV directory (default: <base>/previous)
|
|
--pend <path> PEND directory (default: <base>/pending)
|
|
--deltas <path> DELTAS directory (default: <base>/deltas)
|
|
--backend <name> Delta backend: zstd (default), xdelta3
|
|
--config <file> 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'] };
|
|
}
|