dirpush 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/cli.ts +24 -5
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -36,6 +36,17 @@ if (first === "--version" || first === "-v") {
|
|
|
36
36
|
process.exit(0);
|
|
37
37
|
}
|
|
38
38
|
if (first === "--help" || first === "-h") process.argv.splice(2, 1, "help");
|
|
39
|
+
// Names people type for the human-facing commands.
|
|
40
|
+
const ALIASES: Record<string, string> = { check: "checks", captchas: "checks", needs: "actions", todos: "actions" };
|
|
41
|
+
if (first && ALIASES[first]) process.argv.splice(2, 1, ALIASES[first]);
|
|
42
|
+
/** Agents read JSON errors; a person at a terminal gets a plain sentence. */
|
|
43
|
+
function fail(error: string, extra: { didYouMean?: string[] } = {}): never {
|
|
44
|
+
if (process.stderr.isTTY) {
|
|
45
|
+
const alts = extra.didYouMean?.map((c) => `dirpush ${c}`).join(", ");
|
|
46
|
+
console.error(`dirpush: ${error}${alts ? `\nDid you mean: ${alts}?` : ""}\nRun 'dirpush help' for every command.`);
|
|
47
|
+
} else console.error(JSON.stringify({ error, ...extra, help: "dirpush help" }));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
39
50
|
|
|
40
51
|
const { values: flags, positionals } = parseArgs({
|
|
41
52
|
allowPositionals: true,
|
|
@@ -733,14 +744,22 @@ if (!cmd || cmd === "help") {
|
|
|
733
744
|
const run = commands[`${cmd} ${sub}`] ?? commands[cmd ?? ""];
|
|
734
745
|
if (!run) {
|
|
735
746
|
const tried = sub ? `${cmd} ${sub}` : cmd;
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
747
|
+
// Typos too: "chek" → checks (edit distance on the first word).
|
|
748
|
+
const dist = (x: string, y: string) => {
|
|
749
|
+
let prev = Array.from({ length: y.length + 1 }, (_, j) => j);
|
|
750
|
+
for (let i = 1; i <= x.length; i++) {
|
|
751
|
+
const row = [i];
|
|
752
|
+
for (let j = 1; j <= y.length; j++) row[j] = Math.min(prev[j]! + 1, row[j - 1]! + 1, prev[j - 1]! + (x[i - 1] === y[j - 1] ? 0 : 1));
|
|
753
|
+
prev = row;
|
|
754
|
+
}
|
|
755
|
+
return prev[y.length]!;
|
|
756
|
+
};
|
|
757
|
+
const close = Object.keys(commands).filter((c) => c.startsWith(cmd) || c.includes(tried) || (sub && c.endsWith(sub)) || dist(c.split(" ")[0] ?? c, cmd ?? "") <= 2);
|
|
758
|
+
fail(`unknown command: ${tried}`, close.length ? { didYouMean: close.slice(0, 5) } : {});
|
|
739
759
|
}
|
|
740
760
|
try {
|
|
741
761
|
const result = await run();
|
|
742
762
|
if (result !== undefined) out(result);
|
|
743
763
|
} catch (e) {
|
|
744
|
-
|
|
745
|
-
process.exit(1);
|
|
764
|
+
fail(e instanceof z.ZodError ? z.prettifyError(e) : (e as Error).message);
|
|
746
765
|
}
|