omp-config-crypt 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +34 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -750,23 +750,28 @@ export async function pullHttp(url, pass, root = configRoot(), token = envToken(
|
|
|
750
750
|
}
|
|
751
751
|
|
|
752
752
|
export function parseSpec(spec) {
|
|
753
|
-
const s = spec.trim();
|
|
754
|
-
if (s.startsWith("gist:")) return { kind: "gist", id: s.slice(5) || "new" };
|
|
755
|
-
if (/^https
|
|
753
|
+
const s = String(spec || "").trim();
|
|
754
|
+
if (s.startsWith("gist:")) return { kind: "gist", id: s.slice(5).split(/\s+/)[0] || "new" };
|
|
755
|
+
if (/^https?:\/\/\S+$/.test(s)) return { kind: "http", url: s };
|
|
756
756
|
throw new Error("expected gist:<id|new> or an https URL");
|
|
757
757
|
}
|
|
758
758
|
|
|
759
759
|
export function extractDryRun(str) {
|
|
760
760
|
const raw = String(str || "").trim();
|
|
761
|
-
if (!raw) return { dryRun: false, clean: "" };
|
|
762
|
-
const
|
|
763
|
-
const re = /"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(\S+)/g;
|
|
761
|
+
if (!raw) return { dryRun: false, force: false, strategy: null, clean: "" };
|
|
762
|
+
const re = /"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^"\\]*)*)'|(\S+)/g;
|
|
764
763
|
let match;
|
|
765
764
|
let dryRun = false;
|
|
766
765
|
let force = false;
|
|
766
|
+
let strategy = null;
|
|
767
767
|
const kept = [];
|
|
768
|
+
const tokens = [];
|
|
768
769
|
while ((match = re.exec(raw))) {
|
|
769
770
|
const token = match[1] !== undefined ? match[1] : match[2] !== undefined ? match[2] : match[3];
|
|
771
|
+
tokens.push(token);
|
|
772
|
+
}
|
|
773
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
774
|
+
const token = tokens[i];
|
|
770
775
|
if (token === "--dry-run" || token === "-d") {
|
|
771
776
|
dryRun = true;
|
|
772
777
|
continue;
|
|
@@ -775,11 +780,24 @@ export function extractDryRun(str) {
|
|
|
775
780
|
force = true;
|
|
776
781
|
continue;
|
|
777
782
|
}
|
|
783
|
+
if (token === "--strategy") {
|
|
784
|
+
const value = tokens[++i];
|
|
785
|
+
if (value === undefined || value.startsWith("-")) {
|
|
786
|
+
throw new Error("--strategy requires a value: prefer-remote | prefer-local");
|
|
787
|
+
}
|
|
788
|
+
strategy = value;
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
if (token.startsWith("--strategy=")) {
|
|
792
|
+
strategy = token.slice(11);
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
if (token.startsWith("-") && token !== "-") {
|
|
796
|
+
throw new Error(`unknown flag: ${token}`);
|
|
797
|
+
}
|
|
778
798
|
kept.push(token);
|
|
779
799
|
}
|
|
780
|
-
|
|
781
|
-
if (force) result.force = true;
|
|
782
|
-
return result;
|
|
800
|
+
return { dryRun, force, strategy, clean: kept.join(" ") };
|
|
783
801
|
}
|
|
784
802
|
|
|
785
803
|
export function formatSyncReport(result = {}) {
|
|
@@ -1017,14 +1035,14 @@ export default function (pi) {
|
|
|
1017
1035
|
pi.registerCommand("config-import", {
|
|
1018
1036
|
description: "Decrypt and restore an omp config archive (--dry-run to preview)",
|
|
1019
1037
|
handler: async (args, ctx) => {
|
|
1020
|
-
const { dryRun, clean: src } = extractDryRun(args || "");
|
|
1038
|
+
const { dryRun, strategy, clean: src } = extractDryRun(args || "");
|
|
1021
1039
|
if (!src) {
|
|
1022
|
-
ctx.ui.notify("usage: /config-import <file.enc> [--dry-run]", "error");
|
|
1040
|
+
ctx.ui.notify("usage: /config-import <file.enc> [--dry-run] [--strategy prefer-remote|prefer-local]", "error");
|
|
1023
1041
|
return;
|
|
1024
1042
|
}
|
|
1025
1043
|
try {
|
|
1026
1044
|
const pass = await askPass(ctx, "Import passphrase");
|
|
1027
|
-
const r = importEncrypted(src, pass, configRoot(), { dryRun });
|
|
1045
|
+
const r = importEncrypted(src, pass, configRoot(), { dryRun, strategy });
|
|
1028
1046
|
if (r.adaptedFile) {
|
|
1029
1047
|
ctx.ui.notify(`[import] incompatible v${r.legacy?.from}; adapted -> ${r.adaptedFile}`, "info");
|
|
1030
1048
|
}
|
|
@@ -1076,9 +1094,9 @@ export default function (pi) {
|
|
|
1076
1094
|
const sel = await selectPublicResources(ctx, root);
|
|
1077
1095
|
if (sel === null) return;
|
|
1078
1096
|
}
|
|
1079
|
-
const { dryRun, force, clean: spec } = extractDryRun(args || "");
|
|
1097
|
+
const { dryRun, force, strategy, clean: spec } = extractDryRun(args || "");
|
|
1080
1098
|
if (!spec) {
|
|
1081
|
-
ctx.ui.notify("usage: /config-pull gist:<id> | https://… [--dry-run] [--force]", "error");
|
|
1099
|
+
ctx.ui.notify("usage: /config-pull gist:<id> | https://… [--dry-run] [--force] [--strategy prefer-remote|prefer-local]", "error");
|
|
1082
1100
|
return;
|
|
1083
1101
|
}
|
|
1084
1102
|
try {
|
|
@@ -1086,8 +1104,8 @@ export default function (pi) {
|
|
|
1086
1104
|
const pass = await askPass(ctx, "Pull passphrase");
|
|
1087
1105
|
const token = await askToken(ctx, "Cloud token", target.kind === "gist");
|
|
1088
1106
|
const r = target.kind === "gist"
|
|
1089
|
-
? await pullGist(target.id, pass, configRoot(), token, { dryRun, force })
|
|
1090
|
-
: await pullHttp(target.url, pass, configRoot(), token, { dryRun, force });
|
|
1107
|
+
? await pullGist(target.id, pass, configRoot(), token, { dryRun, force, strategy })
|
|
1108
|
+
: await pullHttp(target.url, pass, configRoot(), token, { dryRun, force, strategy });
|
|
1091
1109
|
if (r.adoptedNamespace) {
|
|
1092
1110
|
ctx.ui.notify(`[pull] adopted remote namespace ${r.adoptedNamespace}; prior policy/state saved as .bak`, "info");
|
|
1093
1111
|
}
|