bob-core 3.0.0-beta.4 → 3.0.0-beta.6
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/README.md +3 -3
- package/dist/cjs/{src/Cli.d.ts → Cli.d.ts} +20 -0
- package/dist/cjs/Command.d.ts +91 -0
- package/dist/cjs/CommandParser.d.ts +122 -0
- package/dist/cjs/{src/CommandRegistry.d.ts → CommandRegistry.d.ts} +12 -0
- package/dist/cjs/ExceptionHandler.d.ts +14 -0
- package/dist/cjs/HelpFlag.d.ts +27 -0
- package/dist/cjs/StringSimilarity.d.ts +31 -0
- package/dist/cjs/args/index.d.ts +131 -0
- package/dist/{esm/src → cjs}/errors/BadCommandArgument.d.ts +4 -2
- package/dist/cjs/{src/errors → errors}/BadCommandFlag.d.ts +4 -2
- package/dist/cjs/errors/BobError.d.ts +13 -0
- package/dist/cjs/errors/CommandNotFoundError.d.ts +9 -0
- package/dist/{esm/src → cjs}/errors/InvalidFlag.d.ts +4 -2
- package/dist/cjs/errors/MissingRequiredArgumentValue.d.ts +9 -0
- package/dist/cjs/errors/MissingRequiredFlagValue.d.ts +9 -0
- package/dist/cjs/errors/TooManyArguments.d.ts +10 -0
- package/dist/cjs/errors/ValidationError.d.ts +10 -0
- package/dist/{esm/src → cjs}/errors/renderError.d.ts +2 -2
- package/dist/cjs/flags/boolean.d.ts +20 -0
- package/dist/cjs/flags/custom.d.ts +12 -0
- package/dist/cjs/flags/directory.d.ts +27 -0
- package/dist/cjs/flags/file.d.ts +27 -0
- package/dist/cjs/flags/helpers.d.ts +9 -0
- package/dist/cjs/flags/index.d.ts +160 -0
- package/dist/cjs/flags/number.d.ts +32 -0
- package/dist/cjs/flags/option.d.ts +8 -0
- package/dist/cjs/flags/string.d.ts +19 -0
- package/dist/cjs/flags/url.d.ts +19 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/{src/lib → lib}/helpers.d.ts +1 -1
- package/dist/cjs/lib/types.d.ts +99 -0
- package/dist/cjs/shared/ask-helpers.d.ts +7 -0
- package/dist/cjs/shared/flagsUtils.d.ts +5 -0
- package/dist/cjs/ux/askForConfirmation.d.ts +10 -0
- package/dist/cjs/{src/ux → ux}/askForToggle.d.ts +5 -1
- package/dist/cjs/ux/helpers.d.ts +6 -0
- package/dist/{esm/src → cjs}/ux/index.d.ts +30 -2
- package/dist/esm/{src/Cli.d.ts → Cli.d.ts} +20 -0
- package/dist/esm/Command.d.ts +91 -0
- package/dist/esm/CommandParser.d.ts +122 -0
- package/dist/esm/{src/CommandRegistry.d.ts → CommandRegistry.d.ts} +12 -0
- package/dist/esm/ExceptionHandler.d.ts +14 -0
- package/dist/esm/HelpFlag.d.ts +27 -0
- package/dist/esm/StringSimilarity.d.ts +31 -0
- package/dist/esm/args/index.d.ts +131 -0
- package/dist/{cjs/src → esm}/errors/BadCommandArgument.d.ts +4 -2
- package/dist/esm/{src/errors → errors}/BadCommandFlag.d.ts +4 -2
- package/dist/esm/errors/BobError.d.ts +13 -0
- package/dist/esm/errors/CommandNotFoundError.d.ts +9 -0
- package/dist/{cjs/src → esm}/errors/InvalidFlag.d.ts +4 -2
- package/dist/esm/errors/MissingRequiredArgumentValue.d.ts +9 -0
- package/dist/esm/errors/MissingRequiredFlagValue.d.ts +9 -0
- package/dist/esm/errors/TooManyArguments.d.ts +10 -0
- package/dist/esm/errors/ValidationError.d.ts +10 -0
- package/dist/{cjs/src → esm}/errors/renderError.d.ts +2 -2
- package/dist/esm/flags/boolean.d.ts +20 -0
- package/dist/esm/flags/custom.d.ts +12 -0
- package/dist/esm/flags/directory.d.ts +27 -0
- package/dist/esm/flags/file.d.ts +27 -0
- package/dist/esm/flags/helpers.d.ts +9 -0
- package/dist/esm/flags/index.d.ts +160 -0
- package/dist/esm/flags/number.d.ts +32 -0
- package/dist/esm/flags/option.d.ts +8 -0
- package/dist/esm/flags/string.d.ts +19 -0
- package/dist/esm/flags/url.d.ts +19 -0
- package/dist/esm/{src/index.js → index.js} +346 -267
- package/dist/esm/{src/lib → lib}/helpers.d.ts +1 -1
- package/dist/esm/lib/types.d.ts +99 -0
- package/dist/esm/shared/ask-helpers.d.ts +7 -0
- package/dist/esm/shared/flagsUtils.d.ts +5 -0
- package/dist/esm/ux/askForConfirmation.d.ts +10 -0
- package/dist/esm/{src/ux → ux}/askForToggle.d.ts +5 -1
- package/dist/esm/ux/helpers.d.ts +6 -0
- package/dist/{cjs/src → esm}/ux/index.d.ts +30 -2
- package/package.json +1 -1
- package/dist/cjs/package-BYPkkzPN.cjs +0 -1
- package/dist/cjs/src/Command.d.ts +0 -48
- package/dist/cjs/src/CommandParser.d.ts +0 -110
- package/dist/cjs/src/ExceptionHandler.d.ts +0 -6
- package/dist/cjs/src/HelpFlag.d.ts +0 -12
- package/dist/cjs/src/StringSimilarity.d.ts +0 -26
- package/dist/cjs/src/args/index.d.ts +0 -67
- package/dist/cjs/src/errors/BobError.d.ts +0 -5
- package/dist/cjs/src/errors/CommandNotFoundError.d.ts +0 -7
- package/dist/cjs/src/errors/MissingRequiredArgumentValue.d.ts +0 -7
- package/dist/cjs/src/errors/MissingRequiredFlagValue.d.ts +0 -7
- package/dist/cjs/src/errors/TooManyArguments.d.ts +0 -8
- package/dist/cjs/src/errors/ValidationError.d.ts +0 -3
- package/dist/cjs/src/flags/boolean.d.ts +0 -9
- package/dist/cjs/src/flags/custom.d.ts +0 -9
- package/dist/cjs/src/flags/directory.d.ts +0 -14
- package/dist/cjs/src/flags/file.d.ts +0 -14
- package/dist/cjs/src/flags/helpers.d.ts +0 -3
- package/dist/cjs/src/flags/index.d.ts +0 -76
- package/dist/cjs/src/flags/number.d.ts +0 -17
- package/dist/cjs/src/flags/option.d.ts +0 -6
- package/dist/cjs/src/flags/string.d.ts +0 -8
- package/dist/cjs/src/flags/url.d.ts +0 -8
- package/dist/cjs/src/index.js +0 -10
- package/dist/cjs/src/lib/types.d.ts +0 -59
- package/dist/cjs/src/shared/ask-helpers.d.ts +0 -7
- package/dist/cjs/src/ux/askForConfirmation.d.ts +0 -5
- package/dist/cjs/src/ux/helpers.d.ts +0 -1
- package/dist/esm/package-LkysKcR6.js +0 -60
- package/dist/esm/src/Command.d.ts +0 -48
- package/dist/esm/src/CommandParser.d.ts +0 -110
- package/dist/esm/src/ExceptionHandler.d.ts +0 -6
- package/dist/esm/src/HelpFlag.d.ts +0 -12
- package/dist/esm/src/StringSimilarity.d.ts +0 -26
- package/dist/esm/src/args/index.d.ts +0 -67
- package/dist/esm/src/errors/BobError.d.ts +0 -5
- package/dist/esm/src/errors/CommandNotFoundError.d.ts +0 -7
- package/dist/esm/src/errors/MissingRequiredArgumentValue.d.ts +0 -7
- package/dist/esm/src/errors/MissingRequiredFlagValue.d.ts +0 -7
- package/dist/esm/src/errors/TooManyArguments.d.ts +0 -8
- package/dist/esm/src/errors/ValidationError.d.ts +0 -3
- package/dist/esm/src/flags/boolean.d.ts +0 -9
- package/dist/esm/src/flags/custom.d.ts +0 -9
- package/dist/esm/src/flags/directory.d.ts +0 -14
- package/dist/esm/src/flags/file.d.ts +0 -14
- package/dist/esm/src/flags/helpers.d.ts +0 -3
- package/dist/esm/src/flags/index.d.ts +0 -76
- package/dist/esm/src/flags/number.d.ts +0 -17
- package/dist/esm/src/flags/option.d.ts +0 -6
- package/dist/esm/src/flags/string.d.ts +0 -8
- package/dist/esm/src/flags/url.d.ts +0 -8
- package/dist/esm/src/lib/types.d.ts +0 -59
- package/dist/esm/src/shared/ask-helpers.d.ts +0 -7
- package/dist/esm/src/ux/askForConfirmation.d.ts +0 -5
- package/dist/esm/src/ux/helpers.d.ts +0 -1
- /package/dist/cjs/{src/CommandSignatureParser.d.ts → CommandSignatureParser.d.ts} +0 -0
- /package/dist/cjs/{src/CommandWithSignature.d.ts → CommandWithSignature.d.ts} +0 -0
- /package/dist/cjs/{src/Logger.d.ts → Logger.d.ts} +0 -0
- /package/dist/cjs/{src/commands → commands}/HelpCommand.d.ts +0 -0
- /package/dist/cjs/{src/contracts → contracts}/LoggerContract.d.ts +0 -0
- /package/dist/cjs/{src/contracts → contracts}/index.d.ts +0 -0
- /package/dist/cjs/{src/errors → errors}/index.d.ts +0 -0
- /package/dist/cjs/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/cjs/{src/lib → lib}/string.d.ts +0 -0
- /package/dist/cjs/{src/shared → shared}/parsers.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForCheckbox.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForEditor.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForExpand.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForFileSelector.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForInput.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForList.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForNumber.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForPassword.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForRawList.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForSearch.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/askForSelect.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/keyValue.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/loader.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/progressBar.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/table.d.ts +0 -0
- /package/dist/cjs/{src/ux → ux}/types.d.ts +0 -0
- /package/dist/esm/{src/CommandSignatureParser.d.ts → CommandSignatureParser.d.ts} +0 -0
- /package/dist/esm/{src/CommandWithSignature.d.ts → CommandWithSignature.d.ts} +0 -0
- /package/dist/esm/{src/Logger.d.ts → Logger.d.ts} +0 -0
- /package/dist/esm/{src/commands → commands}/HelpCommand.d.ts +0 -0
- /package/dist/esm/{src/contracts → contracts}/LoggerContract.d.ts +0 -0
- /package/dist/esm/{src/contracts → contracts}/index.d.ts +0 -0
- /package/dist/esm/{src/errors → errors}/index.d.ts +0 -0
- /package/dist/esm/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/esm/{src/lib → lib}/string.d.ts +0 -0
- /package/dist/esm/{src/shared → shared}/parsers.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForCheckbox.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForEditor.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForExpand.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForFileSelector.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForInput.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForList.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForNumber.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForPassword.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForRawList.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForSearch.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/askForSelect.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/keyValue.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/loader.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/progressBar.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/table.d.ts +0 -0
- /package/dist/esm/{src/ux → ux}/types.d.ts +0 -0
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import e from "chalk";
|
|
2
|
-
import t from "node:fs";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { checkbox as
|
|
6
|
-
import { fileSelector as
|
|
7
|
-
//#region
|
|
8
|
-
var
|
|
2
|
+
import t, { readFileSync as n } from "node:fs";
|
|
3
|
+
import r from "node:path";
|
|
4
|
+
import i from "minimist";
|
|
5
|
+
import { checkbox as a, confirm as o, editor as s, expand as c, input as l, number as u, password as d, rawlist as f, search as p, select as ee } from "@inquirer/prompts";
|
|
6
|
+
import { fileSelector as te } from "inquirer-file-selector";
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var ne = Object.create, re = Object.defineProperty, ie = Object.getOwnPropertyDescriptor, ae = Object.getOwnPropertyNames, oe = Object.getPrototypeOf, se = Object.prototype.hasOwnProperty, ce = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), le = (e, t, n, r) => {
|
|
9
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = ae(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !se.call(e, s) && s !== n && re(e, s, {
|
|
10
|
+
get: ((e) => t[e]).bind(null, s),
|
|
11
|
+
enumerable: !(r = ie(t, s)) || r.enumerable
|
|
12
|
+
});
|
|
13
|
+
return e;
|
|
14
|
+
}, ue = (e, t, n) => (n = e == null ? {} : ne(oe(e)), le(t || !e || !e.__esModule ? re(n, "default", {
|
|
15
|
+
value: e,
|
|
16
|
+
enumerable: !0
|
|
17
|
+
}) : n, e)), m = class {
|
|
9
18
|
level;
|
|
10
19
|
constructor(e = {}) {
|
|
11
20
|
this.level = e.level ?? "info";
|
|
@@ -40,18 +49,35 @@ var m = class {
|
|
|
40
49
|
debug(...e) {
|
|
41
50
|
this.shouldLog("debug") && console.log(...e);
|
|
42
51
|
}
|
|
43
|
-
}, h = class {
|
|
44
|
-
getBigrams(e) {
|
|
45
|
-
let t = [], n = e.toLowerCase();
|
|
46
|
-
for (let e = 0; e < n.length - 1; e++) t.push(n.slice(e, e + 2));
|
|
47
|
-
return t;
|
|
48
|
-
}
|
|
52
|
+
}, de = .1, fe = 4, h = .5, g = class {
|
|
49
53
|
calculateSimilarity(e, t) {
|
|
50
54
|
if (e === t) return 1;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
let n = e.toLowerCase(), r = t.toLowerCase();
|
|
56
|
+
if (n === r) return 1;
|
|
57
|
+
if (n.length === 0 || r.length === 0) return 0;
|
|
58
|
+
let i = this.jaro(n, r);
|
|
59
|
+
if (i === 0) return 0;
|
|
60
|
+
let a = 0, o = Math.min(fe, n.length, r.length);
|
|
61
|
+
for (; a < o && n[a] === r[a];) a++;
|
|
62
|
+
let s = i + a * de * (1 - i), c = Math.min(n.length, r.length) / Math.max(n.length, r.length);
|
|
63
|
+
return s * (c < h ? c / h : 1);
|
|
64
|
+
}
|
|
65
|
+
jaro(e, t) {
|
|
66
|
+
let n = Math.max(0, Math.floor(Math.max(e.length, t.length) / 2) - 1), r = Array(e.length).fill(!1), i = Array(t.length).fill(!1), a = 0;
|
|
67
|
+
for (let o = 0; o < e.length; o++) {
|
|
68
|
+
let s = Math.max(0, o - n), c = Math.min(o + n + 1, t.length);
|
|
69
|
+
for (let n = s; n < c; n++) if (!i[n] && e[o] === t[n]) {
|
|
70
|
+
r[o] = !0, i[n] = !0, a++;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (a === 0) return 0;
|
|
75
|
+
let o = 0, s = 0;
|
|
76
|
+
for (let n = 0; n < e.length; n++) if (r[n]) {
|
|
77
|
+
for (; !i[s];) s++;
|
|
78
|
+
e[n] !== t[s] && o++, s++;
|
|
79
|
+
}
|
|
80
|
+
return o /= 2, (a / e.length + a / t.length + (a - o) / a) / 3;
|
|
55
81
|
}
|
|
56
82
|
findBestMatch(e, t) {
|
|
57
83
|
let n = t.map((t) => ({
|
|
@@ -65,23 +91,21 @@ var m = class {
|
|
|
65
91
|
bestMatchIndex: r
|
|
66
92
|
};
|
|
67
93
|
}
|
|
68
|
-
},
|
|
69
|
-
$type = "BobError";
|
|
70
|
-
};
|
|
94
|
+
}, _ = class extends Error {};
|
|
71
95
|
//#endregion
|
|
72
96
|
//#region src/errors/renderError.ts
|
|
73
|
-
function
|
|
97
|
+
function v(t) {
|
|
74
98
|
return e.bold.yellow(`'${t}'`);
|
|
75
99
|
}
|
|
76
|
-
var
|
|
77
|
-
function
|
|
78
|
-
return e.replace(
|
|
100
|
+
var pe = /\x1b\[[0-9;]*m/g;
|
|
101
|
+
function me(e) {
|
|
102
|
+
return e.replace(pe, "").length;
|
|
79
103
|
}
|
|
80
|
-
function
|
|
104
|
+
function y(t, n) {
|
|
81
105
|
let { title: r, details: i, hint: a } = n, o = i && i.length > 0 || a != null, s = e.dim("│"), c = e.dim("└─");
|
|
82
106
|
if (t.log(""), t.log(` ${e.red("error:")} ${r}`), o) {
|
|
83
107
|
if (t.log(` ${s}`), i && i.length > 0) {
|
|
84
|
-
let e = i.map(([e]) =>
|
|
108
|
+
let e = i.map(([e]) => me(e)), n = Math.max(...e);
|
|
85
109
|
for (let r = 0; r < i.length; r++) {
|
|
86
110
|
let [a, o] = i[r], c = " ".repeat(n - e[r]);
|
|
87
111
|
t.log(` ${s} ${a}${c} ${o}`);
|
|
@@ -93,92 +117,107 @@ function v(t, n) {
|
|
|
93
117
|
}
|
|
94
118
|
//#endregion
|
|
95
119
|
//#region src/errors/CommandNotFoundError.ts
|
|
96
|
-
var
|
|
120
|
+
var he = class extends _ {
|
|
121
|
+
$type = "CommandNotFoundError";
|
|
97
122
|
constructor(e) {
|
|
98
123
|
super(`Command "${e}" not found.`), this.command = e;
|
|
99
124
|
}
|
|
100
125
|
pretty(e) {
|
|
101
|
-
|
|
126
|
+
y(e, { title: `command ${v(this.command)} not found` });
|
|
102
127
|
}
|
|
103
128
|
};
|
|
104
129
|
//#endregion
|
|
105
130
|
//#region src/flags/helpers.ts
|
|
106
131
|
function b(t, n) {
|
|
107
|
-
let r =
|
|
132
|
+
let r = n.multiple === !0, i = n.required ? `${e.yellow.bold(t)} is required` : `Enter ${e.yellow.bold(t)}`;
|
|
108
133
|
return n.description && (i += `: ${e.gray(`(${n.description})`)}`), i += ` ${e.green(`(${n.type}${r ? "[]" : ""})`)}\n`, i;
|
|
109
134
|
}
|
|
110
135
|
function x(e) {
|
|
111
136
|
return e == null ? [] : typeof e == "string" ? [e] : e;
|
|
112
137
|
}
|
|
138
|
+
function S(e) {
|
|
139
|
+
return e.length === 1 ? `-${e}` : `--${e}`;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/shared/flagsUtils.ts
|
|
143
|
+
function C(e) {
|
|
144
|
+
return e.type === "option" && "options" in e;
|
|
145
|
+
}
|
|
113
146
|
//#endregion
|
|
114
147
|
//#region src/errors/InvalidFlag.ts
|
|
115
|
-
var
|
|
148
|
+
var w = class extends _ {
|
|
149
|
+
$type = "InvalidFlag";
|
|
116
150
|
constructor(e, t = {}) {
|
|
117
151
|
super(`Flag ${e} is not recognized`), this.flag = e, this.flagsSchema = t;
|
|
118
152
|
}
|
|
119
153
|
pretty(t) {
|
|
120
154
|
let n = Object.entries(this.flagsSchema).map(([t, n]) => {
|
|
121
|
-
let r = x(n.alias), i = `--${t}${r.length > 0 ? r.map((e) => `,
|
|
155
|
+
let r = x(n.alias), i = `--${t}${r.length > 0 ? r.map((e) => `, ${S(e)}`).join("") : ""}`, a = C(n) ? n.options.join(" | ") : n.type, o = n.description ?? "", s = o ? `${o} ${e.dim(`(${a})`)}` : e.dim(`(${a})`);
|
|
122
156
|
return [e.cyan(i), s];
|
|
123
157
|
});
|
|
124
|
-
|
|
125
|
-
title: `flag ${
|
|
158
|
+
y(t, {
|
|
159
|
+
title: `flag ${v(this.flag)} is not recognized`,
|
|
126
160
|
details: n
|
|
127
161
|
});
|
|
128
162
|
}
|
|
129
|
-
},
|
|
163
|
+
}, T = class extends _ {
|
|
164
|
+
$type = "MissingRequiredArgumentValue";
|
|
130
165
|
constructor(e) {
|
|
131
166
|
super(`Argument "${e}" is required.`), this.argument = e;
|
|
132
167
|
}
|
|
133
168
|
pretty(e) {
|
|
134
|
-
|
|
169
|
+
y(e, { title: `argument ${v(this.argument)} is required` });
|
|
135
170
|
}
|
|
136
|
-
},
|
|
171
|
+
}, E = class extends _ {
|
|
172
|
+
$type = "MissingRequiredFlagValue";
|
|
137
173
|
constructor(e) {
|
|
138
174
|
super(`Flag "${e}" is required.`), this.flag = e;
|
|
139
175
|
}
|
|
140
176
|
pretty(e) {
|
|
141
|
-
|
|
177
|
+
y(e, { title: `flag ${v(this.flag)} is required` });
|
|
178
|
+
}
|
|
179
|
+
}, D = class extends Error {
|
|
180
|
+
constructor(e) {
|
|
181
|
+
super(e);
|
|
142
182
|
}
|
|
143
|
-
},
|
|
183
|
+
}, O = class extends _ {
|
|
184
|
+
$type = "BadCommandArgument";
|
|
144
185
|
constructor(e, t) {
|
|
145
186
|
let n = `Argument "${e.arg}" value is invalid.`;
|
|
146
187
|
e.reason ? n += ` Reason: ${e.reason}` : n += ` Value: "${e.value}"`, super(n), this.detail = e, this.argDefinition = t;
|
|
147
188
|
}
|
|
148
189
|
pretty(t) {
|
|
149
190
|
let n = [];
|
|
150
|
-
this.detail.value != null && n.push([e.dim("value"), e.yellow(`"${this.detail.value}"`)]), this.detail.reason != null && n.push([e.dim("reason"), this.detail.reason]), this.argDefinition?.help != null && n.push([e.dim("help"), e.green(this.argDefinition.help)]),
|
|
151
|
-
title: `argument ${
|
|
191
|
+
this.detail.value != null && n.push([e.dim("value"), e.yellow(`"${this.detail.value}"`)]), this.detail.reason != null && n.push([e.dim("reason"), this.detail.reason]), this.argDefinition?.help != null && n.push([e.dim("help"), e.green(this.argDefinition.help)]), y(t, {
|
|
192
|
+
title: `argument ${v(this.detail.arg)} is invalid`,
|
|
152
193
|
details: n
|
|
153
194
|
});
|
|
154
195
|
}
|
|
155
|
-
},
|
|
196
|
+
}, k = class extends _ {
|
|
197
|
+
$type = "BadCommandFlag";
|
|
156
198
|
constructor(e, t) {
|
|
157
199
|
let n = `Flag "${e.flag}" value is invalid.`;
|
|
158
200
|
e.reason ? n += ` Reason: ${e.reason}` : n += ` Value: "${e.value}"`, super(n), this.param = e, this.flagDefinition = t;
|
|
159
201
|
}
|
|
160
202
|
pretty(t) {
|
|
161
203
|
let n = [];
|
|
162
|
-
this.param.value != null && n.push([e.dim("value"), e.yellow(`"${this.param.value}"`)]), this.param.reason != null && n.push([e.dim("reason"), this.param.reason]), this.flagDefinition?.help != null && n.push([e.dim("help"), e.green(this.flagDefinition.help)]),
|
|
163
|
-
title: `flag ${
|
|
204
|
+
this.param.value != null && n.push([e.dim("value"), e.yellow(`"${this.param.value}"`)]), this.param.reason != null && n.push([e.dim("reason"), this.param.reason]), this.flagDefinition?.help != null && n.push([e.dim("help"), e.green(this.flagDefinition.help)]), y(t, {
|
|
205
|
+
title: `flag ${v(this.param.flag)} is invalid`,
|
|
164
206
|
details: n
|
|
165
207
|
});
|
|
166
208
|
}
|
|
167
|
-
},
|
|
209
|
+
}, A = class extends _ {
|
|
210
|
+
$type = "TooManyArguments";
|
|
168
211
|
constructor(e, t) {
|
|
169
212
|
super(`Too many arguments provided. Expected ${e}, got ${t}.`), this.expected = e, this.received = t;
|
|
170
213
|
}
|
|
171
214
|
pretty(t) {
|
|
172
|
-
|
|
215
|
+
y(t, {
|
|
173
216
|
title: "too many arguments",
|
|
174
217
|
details: [[e.dim("expected"), e.green(String(this.expected))], [e.dim("received"), e.bold.yellow(String(this.received))]]
|
|
175
218
|
});
|
|
176
219
|
}
|
|
177
|
-
},
|
|
178
|
-
constructor(e) {
|
|
179
|
-
super(e);
|
|
180
|
-
}
|
|
181
|
-
}, k = class {
|
|
220
|
+
}, j = class {
|
|
182
221
|
flags;
|
|
183
222
|
parsedFlags = null;
|
|
184
223
|
args;
|
|
@@ -191,7 +230,7 @@ var S = class extends g {
|
|
|
191
230
|
this.opts = e, this.ux = e.ux, this.flags = e.flags, this.args = e.args;
|
|
192
231
|
}
|
|
193
232
|
async init(e) {
|
|
194
|
-
let { _: t, ...n } =
|
|
233
|
+
let { _: t, ...n } = i(e);
|
|
195
234
|
return this.shouldValidateUnknownFlags && this.validateUnknownFlags(n), this.parsedFlags = await this.handleOptions(n), this.parsedArgs = await this.handleArguments(t), {
|
|
196
235
|
flags: this.parsedFlags,
|
|
197
236
|
args: this.parsedArgs
|
|
@@ -206,7 +245,7 @@ var S = class extends g {
|
|
|
206
245
|
}
|
|
207
246
|
async setFlag(e, t) {
|
|
208
247
|
if (!this.parsedFlags) throw Error("Flags have not been parsed yet. Call init() first.");
|
|
209
|
-
if (!(e in this.flags)) throw new
|
|
248
|
+
if (!(e in this.flags)) throw new w(e, this.flags);
|
|
210
249
|
this.parsedFlags[e] = t;
|
|
211
250
|
}
|
|
212
251
|
argument(e, t) {
|
|
@@ -215,7 +254,7 @@ var S = class extends g {
|
|
|
215
254
|
}
|
|
216
255
|
async setArgument(e, t) {
|
|
217
256
|
if (!this.parsedArgs) throw Error("Arguments have not been parsed yet. Call init() first.");
|
|
218
|
-
if (!(e in this.args)) throw new
|
|
257
|
+
if (!(e in this.args)) throw new O({
|
|
219
258
|
arg: e,
|
|
220
259
|
reason: `Argument "${e}" is not recognized`
|
|
221
260
|
});
|
|
@@ -224,6 +263,9 @@ var S = class extends g {
|
|
|
224
263
|
isEmptyValue(e) {
|
|
225
264
|
return e == null || typeof e == "string" && e.trim() === "" || Array.isArray(e) && e.length === 0;
|
|
226
265
|
}
|
|
266
|
+
isMissing(e) {
|
|
267
|
+
return e == null || Array.isArray(e) && e.length === 0;
|
|
268
|
+
}
|
|
227
269
|
validateUnknownFlags(e) {
|
|
228
270
|
let t = /* @__PURE__ */ new Set();
|
|
229
271
|
for (let e in this.flags) {
|
|
@@ -231,7 +273,7 @@ var S = class extends g {
|
|
|
231
273
|
let n = this.flags[e], r = Array.isArray(n.alias) ? n.alias : n.alias ? [n.alias] : [];
|
|
232
274
|
for (let e of r) t.add(e);
|
|
233
275
|
}
|
|
234
|
-
for (let n in e) if (!t.has(n)) throw new
|
|
276
|
+
for (let n in e) if (!t.has(n)) throw new w(n, this.flags);
|
|
235
277
|
}
|
|
236
278
|
async handleOptions(e) {
|
|
237
279
|
let t = {};
|
|
@@ -242,13 +284,13 @@ var S = class extends g {
|
|
|
242
284
|
let t = {}, n = [...e], r = Object.keys(this.args).length;
|
|
243
285
|
for (let e in this.args) {
|
|
244
286
|
let r = this.args[e];
|
|
245
|
-
if (
|
|
287
|
+
if (r.multiple) {
|
|
246
288
|
t[e] = await this.parseValue(n, r, "arg", { name: e }), n.length = 0;
|
|
247
289
|
continue;
|
|
248
290
|
}
|
|
249
291
|
t[e] = await this.parseValue(n.shift(), r, "arg", { name: e });
|
|
250
292
|
}
|
|
251
|
-
if (this.shouldRejectExtraArguments && n.length > 0) throw new
|
|
293
|
+
if (this.shouldRejectExtraArguments && n.length > 0) throw new A(r, r + n.length);
|
|
252
294
|
return t;
|
|
253
295
|
}
|
|
254
296
|
async resolveFlagValue(e, t, n) {
|
|
@@ -261,8 +303,8 @@ var S = class extends g {
|
|
|
261
303
|
return this.parseValue(r, t, "flag", { name: e });
|
|
262
304
|
}
|
|
263
305
|
async parseValue(e, t, n, r) {
|
|
264
|
-
if (this.
|
|
265
|
-
if (
|
|
306
|
+
if (this.isMissing(e)) return typeof t.default == "function" ? await t.default() : t.default;
|
|
307
|
+
if (t.multiple) {
|
|
266
308
|
Array.isArray(e) || (e = [e]);
|
|
267
309
|
let i = [];
|
|
268
310
|
for (let a of e) i.push(await this.safeParse(a, t, n, r));
|
|
@@ -276,20 +318,20 @@ var S = class extends g {
|
|
|
276
318
|
ux: this.ux,
|
|
277
319
|
ctx: this.opts.ctx,
|
|
278
320
|
definition: t,
|
|
279
|
-
cmd: this.opts.cmd ??
|
|
321
|
+
cmd: this.opts.cmd ?? Q
|
|
280
322
|
};
|
|
281
323
|
}
|
|
282
324
|
async safeParse(e, t, n, r) {
|
|
283
325
|
try {
|
|
284
326
|
return t.parse(e, this.buildOpts(r?.name ?? "", t));
|
|
285
327
|
} catch (t) {
|
|
286
|
-
if (t instanceof
|
|
287
|
-
let i = t
|
|
288
|
-
throw n === "flag" ? new
|
|
328
|
+
if (t instanceof k || t instanceof O || !(t instanceof D) || !r) throw t;
|
|
329
|
+
let i = t.message;
|
|
330
|
+
throw n === "flag" ? new k({
|
|
289
331
|
flag: r.name,
|
|
290
332
|
value: e,
|
|
291
333
|
reason: i
|
|
292
|
-
}) : new
|
|
334
|
+
}) : new O({
|
|
293
335
|
arg: r.name,
|
|
294
336
|
value: e,
|
|
295
337
|
reason: i
|
|
@@ -300,10 +342,10 @@ var S = class extends g {
|
|
|
300
342
|
for (let r in e) {
|
|
301
343
|
let i = e[r], a = t?.[r], o = this.isEmptyValue(a);
|
|
302
344
|
if (i.required && o) {
|
|
303
|
-
if (!this.shouldPromptForMissingFlags) throw n === "flag" ? new
|
|
345
|
+
if (!this.shouldPromptForMissingFlags) throw n === "flag" ? new E(r) : new T(r);
|
|
304
346
|
let e = await this.promptFor(r, i);
|
|
305
347
|
if (e != null && t) a = await this.parseValue(e, i, n, { name: r }), t[r] = a;
|
|
306
|
-
else throw n === "flag" ? new
|
|
348
|
+
else throw n === "flag" ? new E(r) : new T(r);
|
|
307
349
|
}
|
|
308
350
|
}
|
|
309
351
|
}
|
|
@@ -322,68 +364,78 @@ var S = class extends g {
|
|
|
322
364
|
};
|
|
323
365
|
//#endregion
|
|
324
366
|
//#region src/flags/custom.ts
|
|
325
|
-
function
|
|
326
|
-
function
|
|
367
|
+
function M(e = {}) {
|
|
368
|
+
return function(t) {
|
|
327
369
|
return {
|
|
328
370
|
type: "custom",
|
|
329
|
-
default: e
|
|
371
|
+
default: e.multiple || t?.multiple ? [] : null,
|
|
372
|
+
parse: (e) => e,
|
|
330
373
|
...e,
|
|
331
374
|
...t
|
|
332
375
|
};
|
|
333
|
-
}
|
|
334
|
-
return t;
|
|
376
|
+
};
|
|
335
377
|
}
|
|
336
378
|
//#endregion
|
|
337
379
|
//#region src/shared/parsers.ts
|
|
338
|
-
function
|
|
339
|
-
if (typeof e == "boolean") throw
|
|
380
|
+
function ge(e) {
|
|
381
|
+
if (typeof e == "boolean") throw new D(`Expected a string, got boolean "${e}"`);
|
|
340
382
|
return String(e);
|
|
341
383
|
}
|
|
342
|
-
function
|
|
384
|
+
function _e(e, t) {
|
|
343
385
|
let n = typeof e == "number" ? e : Number(e);
|
|
344
|
-
if (isNaN(n)) throw new
|
|
345
|
-
if (t?.min !== void 0 && n < t.min) throw new
|
|
346
|
-
if (t?.max !== void 0 && n > t.max) throw new
|
|
386
|
+
if (isNaN(n)) throw new D("must be a valid number");
|
|
387
|
+
if (t?.min !== void 0 && n < t.min) throw new D(`is below minimum ${t.min}`);
|
|
388
|
+
if (t?.max !== void 0 && n > t.max) throw new D(`exceeds maximum ${t.max}`);
|
|
347
389
|
return n;
|
|
348
390
|
}
|
|
349
|
-
function
|
|
391
|
+
function ve(e) {
|
|
350
392
|
if (typeof e == "boolean") return e;
|
|
351
393
|
let t = String(e).toLowerCase();
|
|
352
394
|
if (t === "true" || t === "1") return !0;
|
|
353
395
|
if (t === "false" || t === "0") return !1;
|
|
354
|
-
throw new
|
|
396
|
+
throw new D(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`);
|
|
355
397
|
}
|
|
356
|
-
function
|
|
398
|
+
function ye(e, t) {
|
|
357
399
|
let n = String(e);
|
|
358
|
-
if (!t.includes(n)) throw new
|
|
400
|
+
if (!t.includes(n)) throw new D(`must be one of: ${t.map((e) => `"${e}"`).join(", ")}`);
|
|
359
401
|
return n;
|
|
360
402
|
}
|
|
361
|
-
function
|
|
403
|
+
function be(e, n) {
|
|
362
404
|
let r = String(e);
|
|
363
|
-
if (n?.exists
|
|
405
|
+
if (n?.exists) try {
|
|
406
|
+
t.accessSync(r, t.constants.F_OK);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
let t = e.code;
|
|
409
|
+
throw t === "ENOENT" ? new D("file does not exist") : t === "EACCES" ? new D("file is not accessible (permission denied)") : new D(`file is not accessible (${t ?? e.message})`);
|
|
410
|
+
}
|
|
364
411
|
return r;
|
|
365
412
|
}
|
|
366
|
-
function
|
|
413
|
+
function xe(e, n) {
|
|
367
414
|
let r = String(e);
|
|
368
|
-
if (n?.exists)
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
415
|
+
if (n?.exists) {
|
|
416
|
+
let e;
|
|
417
|
+
try {
|
|
418
|
+
e = t.lstatSync(r);
|
|
419
|
+
} catch (e) {
|
|
420
|
+
let t = e.code;
|
|
421
|
+
throw t === "ENOENT" ? new D("directory does not exist") : t === "EACCES" ? new D("directory is not accessible (permission denied)") : t === "ELOOP" ? new D("symlink loop detected") : new D(`directory is not accessible (${t ?? e.message})`);
|
|
422
|
+
}
|
|
423
|
+
if (!e.isDirectory()) throw new D("path is not a directory");
|
|
372
424
|
}
|
|
373
425
|
return r;
|
|
374
426
|
}
|
|
375
|
-
function
|
|
427
|
+
function Se(e) {
|
|
376
428
|
try {
|
|
377
429
|
return new URL(String(e));
|
|
378
|
-
} catch {
|
|
379
|
-
throw new
|
|
430
|
+
} catch (t) {
|
|
431
|
+
throw new D(`Invalid URL "${e}": ${t instanceof Error ? t.message : String(t)}`);
|
|
380
432
|
}
|
|
381
433
|
}
|
|
382
434
|
//#endregion
|
|
383
435
|
//#region src/flags/boolean.ts
|
|
384
|
-
var
|
|
436
|
+
var Ce = M({
|
|
385
437
|
default: !1,
|
|
386
|
-
parse: (e) =>
|
|
438
|
+
parse: (e) => ve(e),
|
|
387
439
|
ask: async (e) => {
|
|
388
440
|
let t = b(e.name, e.definition);
|
|
389
441
|
return await e.ux.askForToggle(t);
|
|
@@ -392,18 +444,19 @@ var ue = A({
|
|
|
392
444
|
});
|
|
393
445
|
//#endregion
|
|
394
446
|
//#region src/shared/ask-helpers.ts
|
|
395
|
-
function
|
|
447
|
+
function N(e, t) {
|
|
396
448
|
return (n) => {
|
|
397
449
|
if ((n == null || typeof n == "string" && n.trim() === "") && e.required) return "This value is required";
|
|
398
450
|
try {
|
|
399
451
|
e.parse(n, t);
|
|
400
452
|
} catch (e) {
|
|
401
|
-
|
|
453
|
+
if (e instanceof D) return e.message;
|
|
454
|
+
throw e;
|
|
402
455
|
}
|
|
403
456
|
return !0;
|
|
404
457
|
};
|
|
405
458
|
}
|
|
406
|
-
function
|
|
459
|
+
function P(e, t) {
|
|
407
460
|
return (n) => {
|
|
408
461
|
if ((n == null || n.trim() === "") && e.required) return "Please enter at least one value";
|
|
409
462
|
for (let r of n.split(",")) {
|
|
@@ -411,123 +464,126 @@ function M(e, t) {
|
|
|
411
464
|
if (n !== "") try {
|
|
412
465
|
e.parse(n, t);
|
|
413
466
|
} catch (e) {
|
|
414
|
-
|
|
467
|
+
if (e instanceof D) return `"${n}": ${e.message}`;
|
|
468
|
+
throw e;
|
|
415
469
|
}
|
|
416
470
|
}
|
|
417
471
|
return !0;
|
|
418
472
|
};
|
|
419
473
|
}
|
|
420
|
-
async function
|
|
421
|
-
let t = e.definition, n =
|
|
474
|
+
async function we(e) {
|
|
475
|
+
let t = e.definition, n = t.multiple === !0, r = b(e.name, t);
|
|
422
476
|
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
423
477
|
separator: ",",
|
|
424
|
-
validate:
|
|
425
|
-
}) :
|
|
478
|
+
validate: P(t, e)
|
|
479
|
+
}) : t.secret ? e.ux.askForPassword(r, { validate: N(t, e) }) : await e.ux.askForInput(r, { validate: N(t, e) });
|
|
426
480
|
}
|
|
427
|
-
async function
|
|
428
|
-
let t = e.definition, n =
|
|
481
|
+
async function Te(e) {
|
|
482
|
+
let t = e.definition, n = t.multiple === !0, r = b(e.name, t);
|
|
429
483
|
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
430
484
|
separator: ",",
|
|
431
|
-
validate:
|
|
485
|
+
validate: P(t, e)
|
|
432
486
|
}) : await e.ux.askForNumber(r, { validate: (n) => {
|
|
433
487
|
if (n === void 0 && t.required) return "This value is required";
|
|
434
488
|
if (n !== void 0) try {
|
|
435
489
|
t.parse(String(n), e);
|
|
436
490
|
} catch (e) {
|
|
437
|
-
|
|
491
|
+
if (e instanceof D) return e.message;
|
|
492
|
+
throw e;
|
|
438
493
|
}
|
|
439
494
|
return !0;
|
|
440
495
|
} });
|
|
441
496
|
}
|
|
442
|
-
async function
|
|
443
|
-
let t = e.definition, n =
|
|
444
|
-
if (t
|
|
497
|
+
async function Ee(e) {
|
|
498
|
+
let t = e.definition, n = t.multiple === !0, r = b(e.name, t);
|
|
499
|
+
if (!C(t)) return null;
|
|
445
500
|
let i = t.options.map((e) => ({
|
|
446
501
|
name: e,
|
|
447
502
|
value: e
|
|
448
503
|
}));
|
|
449
504
|
return n ? await e.ux.askForCheckbox(r, i) : await e.ux.askForSelect(r, i);
|
|
450
505
|
}
|
|
451
|
-
async function
|
|
506
|
+
async function De(e) {
|
|
452
507
|
let t = b(e.name, e.definition);
|
|
453
508
|
return e.ux.askForFile(t, { basePath: process.cwd() });
|
|
454
509
|
}
|
|
455
|
-
async function
|
|
510
|
+
async function Oe(e) {
|
|
456
511
|
let t = b(e.name, e.definition);
|
|
457
512
|
return e.ux.askForDirectory(t, { basePath: process.cwd() });
|
|
458
513
|
}
|
|
459
|
-
async function
|
|
514
|
+
async function ke(e) {
|
|
460
515
|
let t = b(e.name, e.definition);
|
|
461
|
-
return await e.ux.askForInput(t, { validate:
|
|
516
|
+
return await e.ux.askForInput(t, { validate: N(e.definition, e) });
|
|
462
517
|
}
|
|
463
518
|
//#endregion
|
|
464
519
|
//#region src/flags/directory.ts
|
|
465
|
-
var
|
|
466
|
-
parse: (e, t) =>
|
|
467
|
-
ask:
|
|
520
|
+
var F = M({
|
|
521
|
+
parse: (e, t) => xe(e, { exists: t.definition.exists }),
|
|
522
|
+
ask: Oe,
|
|
468
523
|
type: "directory"
|
|
469
|
-
}),
|
|
470
|
-
parse: (e, t) =>
|
|
471
|
-
ask:
|
|
524
|
+
}), I = M({
|
|
525
|
+
parse: (e, t) => be(e, { exists: t.definition.exists }),
|
|
526
|
+
ask: De,
|
|
472
527
|
type: "file"
|
|
473
|
-
}),
|
|
474
|
-
parse: (e, t) =>
|
|
528
|
+
}), L = M({
|
|
529
|
+
parse: (e, t) => _e(e, {
|
|
475
530
|
min: t.definition.min,
|
|
476
531
|
max: t.definition.max
|
|
477
532
|
}),
|
|
478
|
-
ask:
|
|
533
|
+
ask: Te,
|
|
479
534
|
type: "number"
|
|
480
535
|
});
|
|
481
536
|
//#endregion
|
|
482
537
|
//#region src/flags/option.ts
|
|
483
|
-
function
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
538
|
+
function R(e) {
|
|
539
|
+
let { options: t, ...n } = e;
|
|
540
|
+
return M({
|
|
541
|
+
type: "option",
|
|
542
|
+
ask: Ee,
|
|
543
|
+
parse: (e) => ye(e, t ?? []),
|
|
544
|
+
...e
|
|
545
|
+
})(n);
|
|
490
546
|
}
|
|
491
547
|
//#endregion
|
|
492
548
|
//#region src/flags/string.ts
|
|
493
|
-
var
|
|
494
|
-
parse: (e) =>
|
|
495
|
-
ask:
|
|
549
|
+
var z = M({
|
|
550
|
+
parse: (e) => ge(e),
|
|
551
|
+
ask: we,
|
|
496
552
|
type: "string"
|
|
497
|
-
}),
|
|
498
|
-
parse: (e) =>
|
|
499
|
-
ask:
|
|
553
|
+
}), B = M({
|
|
554
|
+
parse: (e) => Se(e),
|
|
555
|
+
ask: ke,
|
|
500
556
|
type: "url"
|
|
501
|
-
}),
|
|
502
|
-
string:
|
|
503
|
-
number:
|
|
504
|
-
option:
|
|
505
|
-
file:
|
|
506
|
-
directory:
|
|
507
|
-
url:
|
|
508
|
-
custom:
|
|
509
|
-
},
|
|
510
|
-
string:
|
|
511
|
-
number:
|
|
512
|
-
boolean:
|
|
513
|
-
option:
|
|
514
|
-
file:
|
|
515
|
-
directory:
|
|
516
|
-
url:
|
|
517
|
-
custom:
|
|
557
|
+
}), V = {
|
|
558
|
+
string: z,
|
|
559
|
+
number: L,
|
|
560
|
+
option: R,
|
|
561
|
+
file: I,
|
|
562
|
+
directory: F,
|
|
563
|
+
url: B,
|
|
564
|
+
custom: M
|
|
565
|
+
}, H = {
|
|
566
|
+
string: z,
|
|
567
|
+
number: L,
|
|
568
|
+
boolean: Ce,
|
|
569
|
+
option: R,
|
|
570
|
+
file: I,
|
|
571
|
+
directory: F,
|
|
572
|
+
url: B,
|
|
573
|
+
custom: M
|
|
518
574
|
};
|
|
519
575
|
//#endregion
|
|
520
576
|
//#region src/lib/string.ts
|
|
521
|
-
function
|
|
577
|
+
function U(e) {
|
|
522
578
|
return Array(e + 5).join(" ");
|
|
523
579
|
}
|
|
524
580
|
//#endregion
|
|
525
581
|
//#region src/HelpFlag.ts
|
|
526
|
-
function
|
|
582
|
+
function Ae(e) {
|
|
527
583
|
let t = e.type;
|
|
528
|
-
return
|
|
584
|
+
return C(e) ? `enum: ${e.options.join("|")}` : t ?? "custom";
|
|
529
585
|
}
|
|
530
|
-
var
|
|
586
|
+
var je = H.boolean({
|
|
531
587
|
alias: ["h"],
|
|
532
588
|
description: "Displays help information about the command",
|
|
533
589
|
handler: (t, n) => {
|
|
@@ -540,7 +596,7 @@ var ve = B.boolean({
|
|
|
540
596
|
return {
|
|
541
597
|
name: e,
|
|
542
598
|
...t,
|
|
543
|
-
flagWithAlias: `--${e}${n.map((e) => `,
|
|
599
|
+
flagWithAlias: `--${e}${n.map((e) => `, ${S(e)}`).join("")}`
|
|
544
600
|
};
|
|
545
601
|
}), l = o.filter(([, e]) => e.required);
|
|
546
602
|
console.log(e.yellow("Description:")), console.log(` ${r.description}\n`), r.aliases.length > 0 && (console.log(e.yellow("Aliases:")), console.log(` ${r.aliases.join(", ")}\n`)), console.log(e.yellow("Usage:")), console.log(` ${r.command} ${l.length > 0 ? l.map(([e]) => `<${e}>`).join(" ") : "\b"} [options]`);
|
|
@@ -548,19 +604,19 @@ var ve = B.boolean({
|
|
|
548
604
|
if (o.length > 0) {
|
|
549
605
|
console.log(`\n${e.yellow("Arguments")}:`);
|
|
550
606
|
for (let [t, n] of o) {
|
|
551
|
-
let r =
|
|
607
|
+
let r = U(f - t.length), i = ` ${e.green(t)} ${r} ${n.description ?? "\b"}`;
|
|
552
608
|
if (n.default !== void 0 && !n.required) {
|
|
553
609
|
let t = typeof n.default == "function" ? "[function]" : n.multiple ? JSON.stringify(n.default) : n.default;
|
|
554
610
|
i += ` ${e.yellow(`[default: ${t}]`)}`;
|
|
555
611
|
}
|
|
556
|
-
|
|
612
|
+
n.multiple && (i += ` ${e.white("(multiple)")}`), console.log(i);
|
|
557
613
|
}
|
|
558
614
|
}
|
|
559
615
|
if (s.length > 0) {
|
|
560
616
|
console.log(`\n${e.yellow("Options")}:`);
|
|
561
617
|
for (let t of c) {
|
|
562
|
-
let n =
|
|
563
|
-
if (t.type && (r += ` ${e.white(`(${
|
|
618
|
+
let n = U(f - t.flagWithAlias.length), r = ` ${e.green(t.flagWithAlias)} ${n} ${t.description ?? "\b"}`;
|
|
619
|
+
if (t.type && (r += ` ${e.white(`(${Ae(t)})`)}`), t.default !== void 0 && !t.required) {
|
|
564
620
|
let n = typeof t.default == "function" ? "(function)" : t.default;
|
|
565
621
|
r += ` ${e.yellow(`[default: ${n}]`)}`;
|
|
566
622
|
}
|
|
@@ -576,22 +632,24 @@ var ve = B.boolean({
|
|
|
576
632
|
}
|
|
577
633
|
return { shouldStop: !0 };
|
|
578
634
|
}
|
|
579
|
-
}),
|
|
635
|
+
}), Me = class extends Error {
|
|
580
636
|
name = "ExitPromptError";
|
|
581
|
-
}
|
|
637
|
+
}, Ne = /* @__PURE__ */ ce(((e, t) => {
|
|
638
|
+
t.exports = {};
|
|
639
|
+
}));
|
|
582
640
|
//#endregion
|
|
583
641
|
//#region src/ux/helpers.ts
|
|
584
|
-
async function
|
|
642
|
+
async function W(e, t) {
|
|
585
643
|
try {
|
|
586
644
|
return await e();
|
|
587
645
|
} catch (e) {
|
|
588
|
-
if (e instanceof
|
|
646
|
+
if (e instanceof Me || e instanceof Error && e.name === "ExitPromptError") return t;
|
|
589
647
|
throw e;
|
|
590
648
|
}
|
|
591
649
|
}
|
|
592
650
|
//#endregion
|
|
593
651
|
//#region src/ux/askForCheckbox.ts
|
|
594
|
-
async function
|
|
652
|
+
async function G(e, t, n) {
|
|
595
653
|
if (t.length === 0) throw Error("No options provided");
|
|
596
654
|
let r = t.map((e) => typeof e == "string" ? {
|
|
597
655
|
name: e,
|
|
@@ -603,7 +661,7 @@ async function U(e, t, n) {
|
|
|
603
661
|
checked: e.checked,
|
|
604
662
|
description: e.description
|
|
605
663
|
});
|
|
606
|
-
return
|
|
664
|
+
return W(() => a({
|
|
607
665
|
message: e,
|
|
608
666
|
choices: r,
|
|
609
667
|
required: n?.required,
|
|
@@ -615,17 +673,17 @@ async function U(e, t, n) {
|
|
|
615
673
|
}
|
|
616
674
|
//#endregion
|
|
617
675
|
//#region src/ux/askForConfirmation.ts
|
|
618
|
-
async function
|
|
619
|
-
return
|
|
676
|
+
async function K(e = "Do you want to continue?", t) {
|
|
677
|
+
return W(() => o({
|
|
620
678
|
message: e,
|
|
621
679
|
default: t?.default ?? !1,
|
|
622
680
|
transformer: t?.transformer
|
|
623
|
-
}),
|
|
681
|
+
}), null);
|
|
624
682
|
}
|
|
625
683
|
//#endregion
|
|
626
684
|
//#region src/ux/askForEditor.ts
|
|
627
|
-
async function
|
|
628
|
-
return
|
|
685
|
+
async function q(e, t) {
|
|
686
|
+
return W(() => s({
|
|
629
687
|
message: e,
|
|
630
688
|
default: t?.default,
|
|
631
689
|
postfix: t?.postfix,
|
|
@@ -635,8 +693,8 @@ async function G(e, t) {
|
|
|
635
693
|
}
|
|
636
694
|
//#endregion
|
|
637
695
|
//#region src/ux/askForExpand.ts
|
|
638
|
-
async function
|
|
639
|
-
return
|
|
696
|
+
async function Pe(e, t, n) {
|
|
697
|
+
return W(() => c({
|
|
640
698
|
message: e,
|
|
641
699
|
choices: t,
|
|
642
700
|
default: n?.default
|
|
@@ -644,9 +702,9 @@ async function K(e, t, n) {
|
|
|
644
702
|
}
|
|
645
703
|
//#endregion
|
|
646
704
|
//#region src/ux/askForFileSelector.ts
|
|
647
|
-
async function
|
|
648
|
-
return
|
|
649
|
-
let n = await
|
|
705
|
+
async function J(e, t) {
|
|
706
|
+
return W(async () => {
|
|
707
|
+
let n = await te({
|
|
650
708
|
message: e,
|
|
651
709
|
basePath: t?.basePath,
|
|
652
710
|
type: t?.type === "file+directory" ? void 0 : t?.type,
|
|
@@ -660,8 +718,8 @@ async function q(e, t) {
|
|
|
660
718
|
}
|
|
661
719
|
//#endregion
|
|
662
720
|
//#region src/ux/askForInput.ts
|
|
663
|
-
async function
|
|
664
|
-
return
|
|
721
|
+
async function Y(e, t) {
|
|
722
|
+
return W(() => l({
|
|
665
723
|
message: e,
|
|
666
724
|
default: t?.default,
|
|
667
725
|
required: t?.required,
|
|
@@ -671,9 +729,9 @@ async function J(e, t) {
|
|
|
671
729
|
}
|
|
672
730
|
//#endregion
|
|
673
731
|
//#region src/ux/askForList.ts
|
|
674
|
-
async function
|
|
732
|
+
async function Fe(e, t) {
|
|
675
733
|
let n = t?.separator ?? ",";
|
|
676
|
-
return
|
|
734
|
+
return W(async () => (await l({
|
|
677
735
|
message: e,
|
|
678
736
|
default: t?.default,
|
|
679
737
|
validate: t?.validate
|
|
@@ -681,8 +739,8 @@ async function be(e, t) {
|
|
|
681
739
|
}
|
|
682
740
|
//#endregion
|
|
683
741
|
//#region src/ux/askForNumber.ts
|
|
684
|
-
async function
|
|
685
|
-
return
|
|
742
|
+
async function Ie(e, t) {
|
|
743
|
+
return W(async () => await u({
|
|
686
744
|
message: e,
|
|
687
745
|
default: t?.default,
|
|
688
746
|
required: t?.required,
|
|
@@ -694,8 +752,8 @@ async function xe(e, t) {
|
|
|
694
752
|
}
|
|
695
753
|
//#endregion
|
|
696
754
|
//#region src/ux/askForPassword.ts
|
|
697
|
-
async function
|
|
698
|
-
return
|
|
755
|
+
async function Le(e, t) {
|
|
756
|
+
return W(() => d({
|
|
699
757
|
message: e,
|
|
700
758
|
mask: t?.mask,
|
|
701
759
|
validate: t?.validate
|
|
@@ -703,8 +761,8 @@ async function Se(e, t) {
|
|
|
703
761
|
}
|
|
704
762
|
//#endregion
|
|
705
763
|
//#region src/ux/askForRawList.ts
|
|
706
|
-
async function
|
|
707
|
-
return
|
|
764
|
+
async function Re(e, t, n) {
|
|
765
|
+
return W(() => f({
|
|
708
766
|
message: e,
|
|
709
767
|
choices: t,
|
|
710
768
|
loop: n?.loop
|
|
@@ -712,8 +770,8 @@ async function Ce(e, t, n) {
|
|
|
712
770
|
}
|
|
713
771
|
//#endregion
|
|
714
772
|
//#region src/ux/askForSearch.ts
|
|
715
|
-
async function
|
|
716
|
-
return
|
|
773
|
+
async function ze(e, t, n) {
|
|
774
|
+
return W(() => p({
|
|
717
775
|
message: e,
|
|
718
776
|
source: t,
|
|
719
777
|
pageSize: n?.pageSize,
|
|
@@ -722,13 +780,13 @@ async function we(e, t, n) {
|
|
|
722
780
|
}
|
|
723
781
|
//#endregion
|
|
724
782
|
//#region src/ux/askForSelect.ts
|
|
725
|
-
async function
|
|
783
|
+
async function Be(e, t, n) {
|
|
726
784
|
if (t.length === 0) throw Error("No options provided");
|
|
727
785
|
let r = t.map((e) => typeof e == "string" ? {
|
|
728
786
|
name: e,
|
|
729
787
|
value: e
|
|
730
788
|
} : e);
|
|
731
|
-
return
|
|
789
|
+
return W(() => ee({
|
|
732
790
|
message: e,
|
|
733
791
|
choices: r,
|
|
734
792
|
default: n?.default,
|
|
@@ -738,17 +796,17 @@ async function Te(e, t, n) {
|
|
|
738
796
|
}
|
|
739
797
|
//#endregion
|
|
740
798
|
//#region src/ux/askForToggle.ts
|
|
741
|
-
async function
|
|
799
|
+
async function X(e, t) {
|
|
742
800
|
let n = t?.active ?? "Yes", r = t?.inactive ?? "No";
|
|
743
|
-
return
|
|
801
|
+
return W(() => o({
|
|
744
802
|
message: e,
|
|
745
803
|
default: t?.default ?? !1,
|
|
746
804
|
transformer: (e) => e ? n : r
|
|
747
|
-
}),
|
|
805
|
+
}), null);
|
|
748
806
|
}
|
|
749
807
|
//#endregion
|
|
750
808
|
//#region src/ux/keyValue.ts
|
|
751
|
-
function
|
|
809
|
+
function Ve(t, n) {
|
|
752
810
|
let r = n?.separator ?? ": ", i = n?.keyStyle ?? e.bold, a = Array.isArray(t) ? t : Object.entries(t);
|
|
753
811
|
if (a.length === 0) return;
|
|
754
812
|
let o = Math.max(...a.map(([e]) => e.length));
|
|
@@ -756,7 +814,7 @@ function De(t, n) {
|
|
|
756
814
|
}
|
|
757
815
|
//#endregion
|
|
758
816
|
//#region src/ux/loader.ts
|
|
759
|
-
function
|
|
817
|
+
function He(e = "", t = [
|
|
760
818
|
"⠙",
|
|
761
819
|
"⠘",
|
|
762
820
|
"⠰",
|
|
@@ -770,7 +828,7 @@ function Oe(e = "", t = [
|
|
|
770
828
|
], n = 100) {
|
|
771
829
|
let r = e, i = null, a = e.length, o = 0, s = (e) => {
|
|
772
830
|
let t = process.stdout.columns || 80, n = e + 2, r = Math.max(1, Math.ceil(n / t));
|
|
773
|
-
if (process.stdout.isTTY && process.stdout.clearLine && process.stdout.moveCursor) {
|
|
831
|
+
if (process.stdout.isTTY && process.stdout.clearLine && process.stdout.moveCursor && process.stdout.cursorTo) {
|
|
774
832
|
r > 1 && process.stdout.moveCursor(0, -(r - 1));
|
|
775
833
|
for (let e = 0; e < r; e++) process.stdout.cursorTo(0), process.stdout.clearLine(1), e < r - 1 && process.stdout.moveCursor(0, 1);
|
|
776
834
|
r > 1 && process.stdout.moveCursor(0, -(r - 1)), process.stdout.cursorTo(0);
|
|
@@ -791,11 +849,11 @@ function Oe(e = "", t = [
|
|
|
791
849
|
}
|
|
792
850
|
//#endregion
|
|
793
851
|
//#region src/ux/progressBar.ts
|
|
794
|
-
function
|
|
852
|
+
function Ue(e, t) {
|
|
795
853
|
let n = t?.width ?? 30, r = t?.completeChar ?? "█", i = t?.incompleteChar ?? "░", a = 0, o = !1, s = () => {
|
|
796
854
|
if (o) return;
|
|
797
|
-
let t = e <= 0 ? 1 : Math.min(a / e, 1), s = Math.round(t * n),
|
|
798
|
-
process.stdout.write("\r" + c);
|
|
855
|
+
let t = e <= 0 ? 1 : Math.min(a / e, 1), s = Math.round(t * n), l = `${r.repeat(s) + i.repeat(n - s)} ${Math.round(t * 100)}% ${a}/${e}`;
|
|
856
|
+
process.stdout.write("\r" + l), (e <= 0 || a >= e) && c();
|
|
799
857
|
}, c = () => {
|
|
800
858
|
o || (o = !0, process.stdout.write("\n"));
|
|
801
859
|
};
|
|
@@ -813,7 +871,7 @@ function ke(e, t) {
|
|
|
813
871
|
}
|
|
814
872
|
//#endregion
|
|
815
873
|
//#region src/ux/table.ts
|
|
816
|
-
function
|
|
874
|
+
function We(t, n) {
|
|
817
875
|
if (t.length === 0) return;
|
|
818
876
|
let r = n ?? Object.keys(t[0]).map((e) => ({ key: e })), i = r.map((e) => e.header ?? e.key.toUpperCase()), a = r.map((e, n) => {
|
|
819
877
|
let r = Math.max(i[n].length, ...t.map((t) => (e.format ? e.format(t[e.key]) : String(t[e.key] ?? "")).length));
|
|
@@ -839,71 +897,71 @@ function Ae(t, n) {
|
|
|
839
897
|
}
|
|
840
898
|
//#endregion
|
|
841
899
|
//#region src/ux/index.ts
|
|
842
|
-
var
|
|
900
|
+
var Z = class {
|
|
843
901
|
askForConfirmation(e, t) {
|
|
844
|
-
return
|
|
902
|
+
return K(e, t);
|
|
845
903
|
}
|
|
846
904
|
askForInput(e, t) {
|
|
847
|
-
return
|
|
905
|
+
return Y(e, t);
|
|
848
906
|
}
|
|
849
907
|
askForPassword(e, t) {
|
|
850
|
-
return
|
|
908
|
+
return Le(e, t);
|
|
851
909
|
}
|
|
852
910
|
askForNumber(e, t) {
|
|
853
|
-
return
|
|
911
|
+
return Ie(e, t);
|
|
854
912
|
}
|
|
855
913
|
askForSelect(e, t, n) {
|
|
856
|
-
return
|
|
914
|
+
return Be(e, t, n);
|
|
857
915
|
}
|
|
858
916
|
askForCheckbox(e, t, n) {
|
|
859
|
-
return
|
|
917
|
+
return G(e, t, n);
|
|
860
918
|
}
|
|
861
919
|
askForSearch(e, t, n) {
|
|
862
|
-
return
|
|
920
|
+
return ze(e, t, n);
|
|
863
921
|
}
|
|
864
922
|
askForList(e, t) {
|
|
865
|
-
return
|
|
923
|
+
return Fe(e, t);
|
|
866
924
|
}
|
|
867
925
|
askForToggle(e, t) {
|
|
868
|
-
return
|
|
926
|
+
return X(e, t);
|
|
869
927
|
}
|
|
870
928
|
askForEditor(e, t) {
|
|
871
|
-
return
|
|
929
|
+
return q(e, t);
|
|
872
930
|
}
|
|
873
931
|
askForRawList(e, t, n) {
|
|
874
|
-
return
|
|
932
|
+
return Re(e, t, n);
|
|
875
933
|
}
|
|
876
934
|
askForExpand(e, t, n) {
|
|
877
|
-
return
|
|
935
|
+
return Pe(e, t, n);
|
|
878
936
|
}
|
|
879
937
|
askForFile(e, t) {
|
|
880
|
-
return
|
|
938
|
+
return J(e, {
|
|
881
939
|
...t,
|
|
882
940
|
type: "file"
|
|
883
941
|
});
|
|
884
942
|
}
|
|
885
943
|
askForDirectory(e, t) {
|
|
886
|
-
return
|
|
944
|
+
return J(e, {
|
|
887
945
|
...t,
|
|
888
946
|
type: "directory"
|
|
889
947
|
});
|
|
890
948
|
}
|
|
891
949
|
askForFileSelector(e, t) {
|
|
892
|
-
return
|
|
950
|
+
return J(e, t);
|
|
893
951
|
}
|
|
894
952
|
keyValue(e, t) {
|
|
895
|
-
return
|
|
953
|
+
return Ve(e, t);
|
|
896
954
|
}
|
|
897
955
|
table(e, t) {
|
|
898
|
-
return
|
|
956
|
+
return We(e, t);
|
|
899
957
|
}
|
|
900
958
|
newProgressBar(e, t) {
|
|
901
|
-
return
|
|
959
|
+
return Ue(e, t);
|
|
902
960
|
}
|
|
903
961
|
newLoader(e, t, n) {
|
|
904
|
-
return
|
|
962
|
+
return He(e, t, n);
|
|
905
963
|
}
|
|
906
|
-
},
|
|
964
|
+
}, Q = class {
|
|
907
965
|
static $type = "BobCommand";
|
|
908
966
|
static command = "";
|
|
909
967
|
static description = "";
|
|
@@ -921,9 +979,9 @@ var Y = class {
|
|
|
921
979
|
logger;
|
|
922
980
|
ux;
|
|
923
981
|
parser;
|
|
924
|
-
static baseFlags = { help:
|
|
982
|
+
static baseFlags = { help: je };
|
|
925
983
|
newCommandParser(e) {
|
|
926
|
-
return new
|
|
984
|
+
return new j({
|
|
927
985
|
ux: e.ux,
|
|
928
986
|
ctx: e.ctx,
|
|
929
987
|
flags: e.flags,
|
|
@@ -932,7 +990,7 @@ var Y = class {
|
|
|
932
990
|
});
|
|
933
991
|
}
|
|
934
992
|
newUX() {
|
|
935
|
-
return new
|
|
993
|
+
return new Z();
|
|
936
994
|
}
|
|
937
995
|
async run(e) {
|
|
938
996
|
let t = this.constructor;
|
|
@@ -964,7 +1022,7 @@ var Y = class {
|
|
|
964
1022
|
definition: a,
|
|
965
1023
|
cmd: t
|
|
966
1024
|
}, o = a.handler(i, r);
|
|
967
|
-
if (o && o.shouldStop) return
|
|
1025
|
+
if (o && o.shouldStop) return 0;
|
|
968
1026
|
}
|
|
969
1027
|
}
|
|
970
1028
|
await this.parser.validate(), n = {
|
|
@@ -981,22 +1039,22 @@ var Y = class {
|
|
|
981
1039
|
};
|
|
982
1040
|
//#endregion
|
|
983
1041
|
//#region src/lib/helpers.ts
|
|
984
|
-
function
|
|
985
|
-
return
|
|
1042
|
+
function Ge(e) {
|
|
1043
|
+
return e instanceof _;
|
|
986
1044
|
}
|
|
987
|
-
function
|
|
988
|
-
return typeof e == "function" ? e.prototype instanceof
|
|
1045
|
+
function $(e) {
|
|
1046
|
+
return typeof e == "function" ? e.prototype instanceof Q || e.$type === "BobCommand" : !1;
|
|
989
1047
|
}
|
|
990
1048
|
//#endregion
|
|
991
1049
|
//#region src/CommandRegistry.ts
|
|
992
|
-
var
|
|
1050
|
+
var Ke = .75, qe = .55, Je = .05, Ye = class {
|
|
993
1051
|
commands = {};
|
|
994
1052
|
aliases = {};
|
|
995
1053
|
ux;
|
|
996
1054
|
logger;
|
|
997
1055
|
stringSimilarity;
|
|
998
1056
|
constructor(e) {
|
|
999
|
-
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new
|
|
1057
|
+
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new Z(), this.stringSimilarity = e?.stringSimilarity ?? new g();
|
|
1000
1058
|
}
|
|
1001
1059
|
getAvailableCommands() {
|
|
1002
1060
|
return [...Object.keys(this.commands), ...Object.keys(this.aliases)];
|
|
@@ -1007,7 +1065,7 @@ var Q = class {
|
|
|
1007
1065
|
importFile = async (e) => (await import(e)).default;
|
|
1008
1066
|
commandResolver = async (e) => {
|
|
1009
1067
|
let t = await this.importFile(e);
|
|
1010
|
-
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" &&
|
|
1068
|
+
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" && $(t) ? t : null) : null;
|
|
1011
1069
|
};
|
|
1012
1070
|
withCommandResolver(e) {
|
|
1013
1071
|
return this.commandResolver = e, this;
|
|
@@ -1016,7 +1074,7 @@ var Q = class {
|
|
|
1016
1074
|
return this.importFile = e, this;
|
|
1017
1075
|
}
|
|
1018
1076
|
registerCommand(e, t = !1) {
|
|
1019
|
-
if (
|
|
1077
|
+
if (!$(e)) throw Error("Invalid command, it must extend the Command class.");
|
|
1020
1078
|
let n = e.command;
|
|
1021
1079
|
if (!n) throw Error(`Cannot register a command with no name. ${e.name} `);
|
|
1022
1080
|
if (!t && this.commands[n]) throw Error(`Command ${n} already registered.`);
|
|
@@ -1031,7 +1089,7 @@ var Q = class {
|
|
|
1031
1089
|
async loadCommandsPath(e) {
|
|
1032
1090
|
for await (let t of this.listCommandsFiles(e)) try {
|
|
1033
1091
|
let e = await this.commandResolver(t);
|
|
1034
|
-
|
|
1092
|
+
$(e) && this.registerCommand(e);
|
|
1035
1093
|
} catch (e) {
|
|
1036
1094
|
throw Error(`Command ${t} failed to load. ${e}`, { cause: e });
|
|
1037
1095
|
}
|
|
@@ -1043,10 +1101,10 @@ var Q = class {
|
|
|
1043
1101
|
if (!i) {
|
|
1044
1102
|
let r = await this.suggestCommand(t);
|
|
1045
1103
|
if (r) return await this.runCommand(e, r, ...n);
|
|
1046
|
-
throw new
|
|
1104
|
+
throw new he(t);
|
|
1047
1105
|
}
|
|
1048
1106
|
r = new i();
|
|
1049
|
-
} else r =
|
|
1107
|
+
} else r = $(t) ? new t() : t;
|
|
1050
1108
|
return await r.run({
|
|
1051
1109
|
ctx: e,
|
|
1052
1110
|
logger: this.logger,
|
|
@@ -1054,47 +1112,68 @@ var Q = class {
|
|
|
1054
1112
|
}) ?? 0;
|
|
1055
1113
|
}
|
|
1056
1114
|
async suggestCommand(t) {
|
|
1057
|
-
let n = this.getAvailableCommands()
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1060
|
-
|
|
1115
|
+
let n = this.getAvailableCommands();
|
|
1116
|
+
if (n.length === 0) return null;
|
|
1117
|
+
let { bestMatch: r, bestMatchIndex: i, ratings: a } = this.stringSimilarity.findBestMatch(t, n), o = [...a].sort((e, t) => t.rating - e.rating), s = o[1]?.rating ?? 0, c = o.filter((e) => e.rating >= qe).map((e) => e.target);
|
|
1118
|
+
if (r && r.rating >= Ke && r.rating - s > Je) {
|
|
1119
|
+
let e = n[i], r = await this.askRunSimilarCommand(t, e);
|
|
1120
|
+
return r === !0 ? e : (r === null && this.logger.debug(`suggestion prompt cancelled for "${t}"`), null);
|
|
1121
|
+
}
|
|
1122
|
+
if (c.length === 1) {
|
|
1123
|
+
let e = c[0], n = await this.askRunSimilarCommand(t, e);
|
|
1124
|
+
return n === !0 ? e : (n === null && this.logger.debug(`suggestion prompt cancelled for "${t}"`), null);
|
|
1061
1125
|
}
|
|
1062
|
-
if (
|
|
1063
|
-
|
|
1126
|
+
if (c.length > 1) {
|
|
1127
|
+
let n = await this.ux.askForSelect(`${e.red("unknown command")} ${e.bold.yellow(`'${t}'`)} ${e.dim("—")} did you mean one of these?`, c);
|
|
1128
|
+
return n || (n === null && this.logger.debug(`suggestion selection cancelled for "${t}"`), null);
|
|
1129
|
+
}
|
|
1130
|
+
return null;
|
|
1064
1131
|
}
|
|
1065
1132
|
async askRunSimilarCommand(t, n) {
|
|
1066
1133
|
return this.ux.askForConfirmation(`${e.red("unknown command")} ${e.bold.yellow(`'${t}'`)} ${e.dim("—")} did you mean ${e.bold.green(`'${n}'`)}?`);
|
|
1067
1134
|
}
|
|
1068
1135
|
async *listCommandsFiles(e) {
|
|
1069
|
-
let
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1136
|
+
let n;
|
|
1137
|
+
try {
|
|
1138
|
+
n = await t.promises.readdir(e, { withFileTypes: !0 });
|
|
1139
|
+
} catch (t) {
|
|
1140
|
+
throw Error(`Failed to read commands directory "${e}": ${t.message}`, { cause: t });
|
|
1141
|
+
}
|
|
1142
|
+
for (let t of n) {
|
|
1143
|
+
let n = r.resolve(e, t.name);
|
|
1144
|
+
if (t.isDirectory()) yield* this.listCommandsFiles(r.resolve(e, t.name));
|
|
1073
1145
|
else {
|
|
1074
|
-
if (!
|
|
1075
|
-
yield
|
|
1146
|
+
if (!n.endsWith(".ts") && !n.endsWith(".js") && !n.endsWith(".mjs") && !n.endsWith(".cjs")) continue;
|
|
1147
|
+
yield n;
|
|
1076
1148
|
}
|
|
1077
1149
|
}
|
|
1078
1150
|
}
|
|
1079
|
-
},
|
|
1151
|
+
}, Xe = class {
|
|
1080
1152
|
logger;
|
|
1081
1153
|
constructor(e) {
|
|
1082
1154
|
this.logger = e;
|
|
1083
1155
|
}
|
|
1084
1156
|
handle(e) {
|
|
1085
|
-
if (
|
|
1157
|
+
if (Ge(e)) return e.pretty(this.logger), -1;
|
|
1086
1158
|
throw e;
|
|
1087
1159
|
}
|
|
1088
|
-
},
|
|
1160
|
+
}, Ze = /* @__PURE__ */ ue(Ne(), 1);
|
|
1161
|
+
function Qe() {
|
|
1162
|
+
try {
|
|
1163
|
+
let e = n((0, Ze.fileURLToPath)(new URL("data:application/json;base64,ewogICJuYW1lIjogImJvYi1jb3JlIiwKICAidmVyc2lvbiI6ICIzLjAuMC1iZXRhLjYiLAogICJkZXNjcmlwdGlvbiI6ICJCT0IgQ29yZSIsCiAgInR5cGUiOiAibW9kdWxlIiwKICAibWFpbiI6ICIuL2Rpc3QvY2pzL3NyYy9pbmRleC5qcyIsCiAgIm1vZHVsZSI6ICIuL2Rpc3QvZXNtL3NyYy9pbmRleC5qcyIsCiAgInR5cGVzIjogIi4vZGlzdC9lc20vc3JjL2luZGV4LmQudHMiLAogICJmaWxlcyI6IFsKICAgICJkaXN0IgogIF0sCiAgImV4cG9ydHMiOiB7CiAgICAiLiI6IHsKICAgICAgImltcG9ydCI6IHsKICAgICAgICAidHlwZXMiOiAiLi9kaXN0L2VzbS9zcmMvaW5kZXguZC50cyIsCiAgICAgICAgImRlZmF1bHQiOiAiLi9kaXN0L2VzbS9zcmMvaW5kZXguanMiCiAgICAgIH0sCiAgICAgICJyZXF1aXJlIjogewogICAgICAgICJ0eXBlcyI6ICIuL2Rpc3QvY2pzL3NyYy9pbmRleC5kLnRzIiwKICAgICAgICAiZGVmYXVsdCI6ICIuL2Rpc3QvY2pzL3NyYy9pbmRleC5qcyIKICAgICAgfQogICAgfQogIH0sCiAgInNjcmlwdHMiOiB7CiAgICAic3RhcnQiOiAibm9kZSAtciBAc3djLW5vZGUvcmVnaXN0ZXIgZGVidWcvbWFpbi50cyIsCiAgICAiYnVpbGQiOiAicm0gLXJmIC4vZGlzdCAmJiB2aXRlIGJ1aWxkIiwKICAgICJ0eXBlY2hlY2siOiAidHNjIC0tbm9FbWl0IiwKICAgICJwcmVwYWNrIjogIm5wbSBydW4gYnVpbGQiLAogICAgInRlc3QiOiAidml0ZXN0IHJ1biIsCiAgICAibGludCI6ICJlc2xpbnQgLiIsCiAgICAibGludDpmaXgiOiAiZXNsaW50IC4gLS1maXgiCiAgfSwKICAiYXV0aG9yIjogIkzDqW8gSHViZXJ0IiwKICAibGljZW5zZSI6ICJJU0MiLAogICJkZXZEZXBlbmRlbmNpZXMiOiB7CiAgICAiQGVzbGludC9qcyI6ICJeOS4zOS40IiwKICAgICJAZmFrZXItanMvZmFrZXIiOiAiXjEwLjMuMCIsCiAgICAiQHN3Yy1ub2RlL3JlZ2lzdGVyIjogIl4xLjExLjEiLAogICAgIkB0cml2YWdvL3ByZXR0aWVyLXBsdWdpbi1zb3J0LWltcG9ydHMiOiAiXjUuMi4yIiwKICAgICJAdHlwZXMvbWluaW1pc3QiOiAiXjEuMi41IiwKICAgICJAdHlwZXMvbm9kZSI6ICJeMjAuMTQuNSIsCiAgICAiQHR5cGVzL3N0cmluZy1zaW1pbGFyaXR5IjogIl40LjAuMiIsCiAgICAiQHZpdGVzdC9jb3ZlcmFnZS12OCI6ICJeNC4xLjAiLAogICAgImVzbGludCI6ICJeOS4zOS40IiwKICAgICJlc2xpbnQtY29uZmlnLXByZXR0aWVyIjogIl4xMC4xLjgiLAogICAgImVzbGludC1wbHVnaW4tcHJldHRpZXIiOiAiXjUuNS41IiwKICAgICJwcmV0dGllciI6ICJeMy42LjIiLAogICAgInRzeCI6ICJeNC4yMS4wIiwKICAgICJ0eXBlc2NyaXB0IjogIl41LjkuMyIsCiAgICAidHlwZXNjcmlwdC1lc2xpbnQiOiAiXjguNTcuMCIsCiAgICAidml0ZSI6ICJeOC4wLjAiLAogICAgInZpdGUtcGx1Z2luLWR0cyI6ICJeNC41LjQiLAogICAgInZpdGVzdCI6ICJeNC4xLjAiCiAgfSwKICAiZGVwZW5kZW5jaWVzIjogewogICAgIkBpbnF1aXJlci9jb3JlIjogIl4xMS4xLjgiLAogICAgIkBpbnF1aXJlci9wcm9tcHRzIjogIl44LjQuMSIsCiAgICAiY2hhbGsiOiAiXjUuNi4yIiwKICAgICJpbnF1aXJlci1maWxlLXNlbGVjdG9yIjogIl4xLjAuMSIsCiAgICAibWluaW1pc3QiOiAiXjEuMi44IgogIH0KfQo=", "" + import.meta.url)), "utf8");
|
|
1164
|
+
return JSON.parse(e).version ?? "0.0.0";
|
|
1165
|
+
} catch {
|
|
1166
|
+
return "0.0.0";
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
var $e = class extends Q {
|
|
1089
1170
|
static command = "help";
|
|
1090
1171
|
static description = e.bold("Show help information about the CLI and its commands");
|
|
1091
1172
|
constructor(e) {
|
|
1092
1173
|
super(), this.opts = e;
|
|
1093
1174
|
}
|
|
1094
1175
|
async handle() {
|
|
1095
|
-
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0";
|
|
1096
|
-
Ne ??= (await import("../package-LkysKcR6.js"))?.default?.version ?? "0.0.0";
|
|
1097
|
-
let i = Ne;
|
|
1176
|
+
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0", i = Qe();
|
|
1098
1177
|
this.logger.log(`${n} ${e.green(r)} (core: ${e.yellow(i)})
|
|
1099
1178
|
|
|
1100
1179
|
${e.yellow("Usage")}:
|
|
@@ -1116,25 +1195,25 @@ ${e.yellow("Available commands")}:
|
|
|
1116
1195
|
r && this.logger.log(e.yellow(`${t}:`));
|
|
1117
1196
|
let i = n.sort((e, t) => e.command.toLowerCase().localeCompare(t.command.toLowerCase()));
|
|
1118
1197
|
for (let t of i) {
|
|
1119
|
-
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i =
|
|
1198
|
+
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i = U(a - (t.command.length + (t.aliases.length > 0 ? ` (${t.aliases.join(", ")})`.length : 0)));
|
|
1120
1199
|
r && (i = i.slice(2)), this.logger.log(`${r ? " " : ""}${e.green(t.command)}${n} ${i} ${t.description}`);
|
|
1121
1200
|
}
|
|
1122
1201
|
}
|
|
1123
1202
|
}
|
|
1124
|
-
},
|
|
1203
|
+
}, et = class {
|
|
1125
1204
|
ctx;
|
|
1126
1205
|
logger;
|
|
1127
1206
|
commandRegistry;
|
|
1128
1207
|
exceptionHandler;
|
|
1129
1208
|
helpCommand;
|
|
1130
1209
|
newCommandRegistry(e) {
|
|
1131
|
-
return new
|
|
1210
|
+
return new Ye(e);
|
|
1132
1211
|
}
|
|
1133
1212
|
newHelpCommand(e) {
|
|
1134
|
-
return new
|
|
1213
|
+
return new $e(e);
|
|
1135
1214
|
}
|
|
1136
1215
|
newExceptionHandler(e) {
|
|
1137
|
-
return new
|
|
1216
|
+
return new Xe(e.logger);
|
|
1138
1217
|
}
|
|
1139
1218
|
constructor(e = {}) {
|
|
1140
1219
|
this.ctx = e.ctx, this.logger = e.logger ?? new m(), this.commandRegistry = this.newCommandRegistry({ logger: this.logger }), this.exceptionHandler = this.newExceptionHandler({ logger: this.logger }), this.helpCommand = this.newHelpCommand({
|
|
@@ -1161,7 +1240,7 @@ ${e.yellow("Available commands")}:
|
|
|
1161
1240
|
registerCommand(e) {
|
|
1162
1241
|
this.commandRegistry.registerCommand(e);
|
|
1163
1242
|
}
|
|
1164
|
-
},
|
|
1243
|
+
}, tt = class e {
|
|
1165
1244
|
static parse(t, n = {}) {
|
|
1166
1245
|
let [r, ...i] = t.split(/\{(.*?)\}/g).map((e) => e.trim()).filter(Boolean), a = {}, o = {};
|
|
1167
1246
|
for (let t of i) {
|
|
@@ -1192,27 +1271,27 @@ ${e.yellow("Available commands")}:
|
|
|
1192
1271
|
}
|
|
1193
1272
|
n.startsWith("--") && (r = !0, n = n.slice(2)), n.endsWith("?") && (l = !1, n = n.slice(0, -1)), n.endsWith("*") && (c = !0, a = [], n = n.slice(0, -1)), i = i ?? t[n] ?? t[`--${n}`];
|
|
1194
1273
|
let u;
|
|
1195
|
-
return u = r ? s ?
|
|
1274
|
+
return u = r ? s ? H.boolean({
|
|
1196
1275
|
description: i,
|
|
1197
1276
|
alias: o,
|
|
1198
1277
|
...a === void 0 ? {} : { default: a }
|
|
1199
|
-
}) : c ?
|
|
1278
|
+
}) : c ? H.string({
|
|
1200
1279
|
description: i,
|
|
1201
1280
|
alias: o,
|
|
1202
1281
|
multiple: !0,
|
|
1203
1282
|
...l ? { required: !0 } : {},
|
|
1204
1283
|
default: a ?? []
|
|
1205
|
-
}) :
|
|
1284
|
+
}) : H.string({
|
|
1206
1285
|
description: i,
|
|
1207
1286
|
alias: o,
|
|
1208
1287
|
...l ? { required: !0 } : {},
|
|
1209
1288
|
...a === void 0 ? {} : { default: a }
|
|
1210
|
-
}) : c ?
|
|
1289
|
+
}) : c ? V.string({
|
|
1211
1290
|
description: i,
|
|
1212
1291
|
multiple: !0,
|
|
1213
1292
|
...l ? { required: !0 } : {},
|
|
1214
1293
|
default: a ?? []
|
|
1215
|
-
}) :
|
|
1294
|
+
}) : V.string({
|
|
1216
1295
|
description: i,
|
|
1217
1296
|
...l ? { required: !0 } : {},
|
|
1218
1297
|
...a === void 0 ? {} : { default: a }
|
|
@@ -1222,7 +1301,7 @@ ${e.yellow("Available commands")}:
|
|
|
1222
1301
|
definition: u
|
|
1223
1302
|
};
|
|
1224
1303
|
}
|
|
1225
|
-
},
|
|
1304
|
+
}, nt = class extends Q {
|
|
1226
1305
|
static signature = "";
|
|
1227
1306
|
static helperDefinitions = {};
|
|
1228
1307
|
static get command() {
|
|
@@ -1231,7 +1310,7 @@ ${e.yellow("Available commands")}:
|
|
|
1231
1310
|
async run(e) {
|
|
1232
1311
|
let t = this.constructor;
|
|
1233
1312
|
if (t.signature && !Object.prototype.hasOwnProperty.call(t, "_signatureParsed")) {
|
|
1234
|
-
let e =
|
|
1313
|
+
let e = tt.parse(t.signature, t.helperDefinitions), n = Object.prototype.hasOwnProperty.call(t, "flags") ? t.flags : {}, r = Object.prototype.hasOwnProperty.call(t, "args") ? t.args : {};
|
|
1235
1314
|
t.flags = {
|
|
1236
1315
|
...e.flags,
|
|
1237
1316
|
...n
|
|
@@ -1250,4 +1329,4 @@ ${e.yellow("Available commands")}:
|
|
|
1250
1329
|
}
|
|
1251
1330
|
};
|
|
1252
1331
|
//#endregion
|
|
1253
|
-
export {
|
|
1332
|
+
export { V as Args, O as BadCommandArgument, k as BadCommandFlag, _ as BobError, et as Cli, Q as Command, he as CommandNotFoundError, j as CommandParser, Ye as CommandRegistry, tt as CommandSignatureParser, nt as CommandWithSignature, Xe as ExceptionHandler, H as Flags, w as InvalidFlag, m as Logger, T as MissingRequiredArgumentValue, E as MissingRequiredFlagValue, g as StringSimilarity, A as TooManyArguments, Z as UX, D as ValidationError, G as askForCheckbox, K as askForConfirmation, q as askForEditor, Pe as askForExpand, J as askForFileSelector, Y as askForInput, Fe as askForList, Ie as askForNumber, Le as askForPassword, Re as askForRawList, ze as askForSearch, Be as askForSelect, X as askForToggle, Ve as keyValue, He as newLoader, Ue as newProgressBar, We as table, W as withCancelHandling };
|