Skill Tracer
Skills › Archify › archify › recover-output.mjs

recover-output.mjs

41 lines · archify/bin/recover-output.mjs at a406594

1import { recoverRetiredPublication } from '../renderers/shared/atomic-output.mjs';
2
3function usage(stream = process.stderr) {
4 stream.write('Usage: node bin/recover-output.mjs <private-recovery-directory> [--json]\n');
5}
6
7const args = process.argv.slice(2);
8if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
9 usage(process.stdout);
10} else {
11 let json = false;
12 let recoveryDirectory;
13 let invalid = false;
14 for (const argument of args) {
15 if (argument === '--json' && !json) {
16 json = true;
17 } else if (argument.startsWith('-') || recoveryDirectory !== undefined) {
18 invalid = true;
19 } else {
20 recoveryDirectory = argument;
21 }
22 }
24 if (invalid || recoveryDirectory === undefined) {
25 usage();
26 process.exitCode = 64;
27 } else {
28 const result = recoverRetiredPublication(recoveryDirectory);
29 if (json) {
30 process.stdout.write(`${JSON.stringify(result)}\n`);
31 } else {
32 const reason = result.reason?.code || 'publication-recovery-unknown';
33 process.stdout.write(`${result.status}: ${reason}\n`);
34 }
35 // A complete prior recovery is idempotent. A preserved target is a safe,
36 // deliberate non-action that needs the operator to inspect the claimant.
37 process.exitCode = ['recovered', 'absent'].includes(result.status)
38 ? 0
39 : result.status === 'preserved' ? 2 : 1;
40 }