varlock 0.2.0 → 0.2.2
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 +2 -0
- package/dist/auto-load.js +8 -8
- package/dist/{chunk-RZT65DRA.js → chunk-35SAMS66.js} +4 -4
- package/dist/{chunk-RZT65DRA.js.map → chunk-35SAMS66.js.map} +1 -1
- package/dist/{chunk-XVVLI2E7.js → chunk-3FLO3UFZ.js} +17 -11
- package/dist/chunk-3FLO3UFZ.js.map +1 -0
- package/dist/{chunk-FPQYEKFF.js → chunk-4N3YR2QQ.js} +4 -4
- package/dist/{chunk-FPQYEKFF.js.map → chunk-4N3YR2QQ.js.map} +1 -1
- package/dist/{chunk-XN24GZXQ.js → chunk-6PEHRAEP.js} +3 -8
- package/dist/{chunk-XN24GZXQ.js.map → chunk-6PEHRAEP.js.map} +1 -1
- package/dist/chunk-BHHYQ7SH.js +18 -0
- package/dist/{chunk-7SH6C6WJ.js.map → chunk-BHHYQ7SH.js.map} +1 -1
- package/dist/{chunk-RD44SH5U.js → chunk-FETFVFG5.js} +117 -23
- package/dist/chunk-FETFVFG5.js.map +1 -0
- package/dist/{chunk-RFRTLWK3.js → chunk-HPUQ2CCN.js} +6 -6
- package/dist/{chunk-RFRTLWK3.js.map → chunk-HPUQ2CCN.js.map} +1 -1
- package/dist/{chunk-FGMXIEFA.js → chunk-MIBOBKI4.js} +3 -3
- package/dist/{chunk-FGMXIEFA.js.map → chunk-MIBOBKI4.js.map} +1 -1
- package/dist/chunk-N2HZMIGS.js +1532 -0
- package/dist/chunk-N2HZMIGS.js.map +1 -0
- package/dist/{chunk-NDRSG3XS.js → chunk-N4REMPVX.js} +23 -14
- package/dist/chunk-N4REMPVX.js.map +1 -0
- package/dist/{chunk-FUDH2TTI.js → chunk-TVFOIGJP.js} +3 -3
- package/dist/{chunk-FUDH2TTI.js.map → chunk-TVFOIGJP.js.map} +1 -1
- package/dist/{chunk-5IMCRQTM.js → chunk-TYIS6T2T.js} +4 -4
- package/dist/{chunk-5IMCRQTM.js.map → chunk-TYIS6T2T.js.map} +1 -1
- package/dist/chunk-UDXNNRWI.js +1386 -0
- package/dist/chunk-UDXNNRWI.js.map +1 -0
- package/dist/{chunk-HPNRKYVF.js → chunk-UIOEEWG5.js} +4 -4
- package/dist/{chunk-HPNRKYVF.js.map → chunk-UIOEEWG5.js.map} +1 -1
- package/dist/{chunk-MSRPV5WH.js → chunk-WAMBVZL2.js} +4 -4
- package/dist/{chunk-MSRPV5WH.js.map → chunk-WAMBVZL2.js.map} +1 -1
- package/dist/{chunk-L5REVVXG.js → chunk-ZUNB52KY.js} +9 -4
- package/dist/chunk-ZUNB52KY.js.map +1 -0
- package/dist/{chunk-NSY7JMFV.js → chunk-ZXJ4CEDK.js} +4 -4
- package/dist/{chunk-NSY7JMFV.js.map → chunk-ZXJ4CEDK.js.map} +1 -1
- package/dist/cli/cli-executable.js +18 -18
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/dotenv-compat.js +8 -8
- package/dist/help.command-MLH2WA5Y.js +5 -0
- package/dist/{help.command-B7VWA53B.js.map → help.command-MLH2WA5Y.js.map} +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -9
- package/dist/init.command-DLPZ3R4T.js +8 -0
- package/dist/{init.command-AVNYY5CK.js.map → init.command-DLPZ3R4T.js.map} +1 -1
- package/dist/lib/exec-sync-varlock.js +2 -2
- package/dist/load.command-4G5POJYR.js +8 -0
- package/dist/{load.command-7CCTFAYS.js.map → load.command-4G5POJYR.js.map} +1 -1
- package/dist/run.command-L5LLHOW3.js +9 -0
- package/dist/{run.command-NGRKCLWP.js.map → run.command-L5LLHOW3.js.map} +1 -1
- package/dist/runtime/env.js +3 -3
- package/dist/runtime/patch-console.js +4 -4
- package/dist/runtime/patch-response.js +4 -4
- package/dist/runtime/patch-server-response.js +4 -4
- package/dist/telemetry.command-JF72FOYJ.js +8 -0
- package/dist/{telemetry.command-756WXWYK.js.map → telemetry.command-JF72FOYJ.js.map} +1 -1
- package/package.json +34 -15
- package/dist/chunk-33ROL4J5.js +0 -1013
- package/dist/chunk-33ROL4J5.js.map +0 -1
- package/dist/chunk-7SH6C6WJ.js +0 -18
- package/dist/chunk-L5REVVXG.js.map +0 -1
- package/dist/chunk-L5USEQO6.js +0 -1281
- package/dist/chunk-L5USEQO6.js.map +0 -1
- package/dist/chunk-NDRSG3XS.js.map +0 -1
- package/dist/chunk-RD44SH5U.js.map +0 -1
- package/dist/chunk-XVVLI2E7.js.map +0 -1
- package/dist/en-US-TSGNDI2P.js +0 -22
- package/dist/en-US-TSGNDI2P.js.map +0 -1
- package/dist/help.command-B7VWA53B.js +0 -5
- package/dist/init.command-AVNYY5CK.js +0 -8
- package/dist/ja-JP-UBPCQAAD.js +0 -22
- package/dist/ja-JP-UBPCQAAD.js.map +0 -1
- package/dist/load.command-7CCTFAYS.js +0 -8
- package/dist/run.command-NGRKCLWP.js +0 -9
- package/dist/telemetry.command-756WXWYK.js +0 -8
|
@@ -0,0 +1,1386 @@
|
|
|
1
|
+
import { __name } from './chunk-6PEHRAEP.js';
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/utils-DNS9AIR_.js
|
|
4
|
+
function kebabnize(str) {
|
|
5
|
+
return str.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
6
|
+
}
|
|
7
|
+
__name(kebabnize, "kebabnize");
|
|
8
|
+
function isLazyCommand(cmd) {
|
|
9
|
+
return typeof cmd === "function" && "commandName" in cmd && !!cmd.commandName;
|
|
10
|
+
}
|
|
11
|
+
__name(isLazyCommand, "isLazyCommand");
|
|
12
|
+
async function resolveLazyCommand(cmd, name, needRunResolving = false) {
|
|
13
|
+
let command;
|
|
14
|
+
if (isLazyCommand(cmd)) {
|
|
15
|
+
const baseCommand = {
|
|
16
|
+
name: cmd.commandName,
|
|
17
|
+
description: cmd.description,
|
|
18
|
+
args: cmd.args,
|
|
19
|
+
examples: cmd.examples,
|
|
20
|
+
internal: cmd.internal,
|
|
21
|
+
entry: cmd.entry,
|
|
22
|
+
subCommands: cmd.subCommands
|
|
23
|
+
};
|
|
24
|
+
if ("resource" in cmd && cmd.resource) baseCommand.resource = cmd.resource;
|
|
25
|
+
command = Object.assign(create(), baseCommand);
|
|
26
|
+
if (needRunResolving) {
|
|
27
|
+
const loaded = await cmd();
|
|
28
|
+
if (typeof loaded === "function") command.run = loaded;
|
|
29
|
+
else if (typeof loaded === "object") {
|
|
30
|
+
if (loaded.run == null) throw new TypeError(`'run' is required in command: ${cmd.name || name}`);
|
|
31
|
+
command.run = loaded.run;
|
|
32
|
+
command.name = loaded.name;
|
|
33
|
+
command.description = loaded.description;
|
|
34
|
+
command.args = loaded.args;
|
|
35
|
+
command.examples = loaded.examples;
|
|
36
|
+
command.internal = loaded.internal;
|
|
37
|
+
command.entry = loaded.entry;
|
|
38
|
+
command.subCommands = loaded.subCommands || cmd.subCommands;
|
|
39
|
+
if ("resource" in loaded && loaded.resource) command.resource = loaded.resource;
|
|
40
|
+
} else throw new TypeError(`Cannot resolve command: ${cmd.name || name}`);
|
|
41
|
+
}
|
|
42
|
+
} else command = Object.assign(create(), cmd);
|
|
43
|
+
if (command.name == null && name) command.name = name;
|
|
44
|
+
return deepFreeze(command);
|
|
45
|
+
}
|
|
46
|
+
__name(resolveLazyCommand, "resolveLazyCommand");
|
|
47
|
+
function create(obj = null) {
|
|
48
|
+
return Object.create(obj);
|
|
49
|
+
}
|
|
50
|
+
__name(create, "create");
|
|
51
|
+
function log(...args) {
|
|
52
|
+
console.log(...args);
|
|
53
|
+
}
|
|
54
|
+
__name(log, "log");
|
|
55
|
+
function getCommandSubCommands(cmd) {
|
|
56
|
+
const subCommands = isLazyCommand(cmd) ? cmd.subCommands : typeof cmd === "object" ? cmd.subCommands : void 0;
|
|
57
|
+
if (!subCommands) return;
|
|
58
|
+
if (subCommands instanceof Map) return subCommands.size > 0 ? subCommands : void 0;
|
|
59
|
+
if (typeof subCommands === "object") {
|
|
60
|
+
const entries = Object.entries(subCommands);
|
|
61
|
+
if (entries.length === 0) return;
|
|
62
|
+
const map = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const [name, cmd2] of entries) map.set(name, cmd2);
|
|
64
|
+
return map;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
__name(getCommandSubCommands, "getCommandSubCommands");
|
|
68
|
+
function deepFreeze(obj, ignores = []) {
|
|
69
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
70
|
+
for (const key of Object.keys(obj)) {
|
|
71
|
+
const value = obj[key];
|
|
72
|
+
if (ignores.includes(key)) continue;
|
|
73
|
+
if (typeof value === "object" && value !== null) deepFreeze(value, ignores);
|
|
74
|
+
}
|
|
75
|
+
return Object.freeze(obj);
|
|
76
|
+
}
|
|
77
|
+
__name(deepFreeze, "deepFreeze");
|
|
78
|
+
|
|
79
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/constants-WviiKqbt.js
|
|
80
|
+
var ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
81
|
+
var NOOP = /* @__PURE__ */ __name(() => {
|
|
82
|
+
}, "NOOP");
|
|
83
|
+
var CLI_OPTIONS_DEFAULT = {
|
|
84
|
+
name: void 0,
|
|
85
|
+
description: void 0,
|
|
86
|
+
version: void 0,
|
|
87
|
+
cwd: void 0,
|
|
88
|
+
usageSilent: false,
|
|
89
|
+
subCommands: void 0,
|
|
90
|
+
leftMargin: 2,
|
|
91
|
+
middleMargin: 10,
|
|
92
|
+
usageOptionType: false,
|
|
93
|
+
usageOptionValue: true,
|
|
94
|
+
renderHeader: void 0,
|
|
95
|
+
renderUsage: void 0,
|
|
96
|
+
renderValidationErrors: void 0,
|
|
97
|
+
plugins: void 0,
|
|
98
|
+
fallbackToEntry: false
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/context-CHDIbgwd.js
|
|
102
|
+
async function createCommandContext({ args = {}, explicit = {}, values = {}, positionals = [], rest = [], argv = [], tokens = [], command = {}, extensions = {}, cliOptions = {}, callMode = "entry", commandPath = [], omitted = false, validationError = void 0 }) {
|
|
103
|
+
const _args = Object.entries(args).reduce((acc, [key, value]) => {
|
|
104
|
+
acc[key] = Object.assign(create(), value);
|
|
105
|
+
return acc;
|
|
106
|
+
}, create());
|
|
107
|
+
const env = Object.assign(create(), CLI_OPTIONS_DEFAULT, cliOptions);
|
|
108
|
+
if (command.rendering) {
|
|
109
|
+
const { header, usage, validationErrors } = command.rendering;
|
|
110
|
+
if (header !== void 0) env.renderHeader = header;
|
|
111
|
+
if (usage !== void 0) env.renderUsage = usage;
|
|
112
|
+
if (validationErrors !== void 0) env.renderValidationErrors = validationErrors;
|
|
113
|
+
}
|
|
114
|
+
const core = Object.assign(create(), {
|
|
115
|
+
name: getCommandName(command),
|
|
116
|
+
description: command.description,
|
|
117
|
+
omitted,
|
|
118
|
+
callMode,
|
|
119
|
+
commandPath,
|
|
120
|
+
env,
|
|
121
|
+
args: _args,
|
|
122
|
+
explicit,
|
|
123
|
+
values,
|
|
124
|
+
positionals,
|
|
125
|
+
rest,
|
|
126
|
+
_: argv,
|
|
127
|
+
tokens,
|
|
128
|
+
toKebab: command.toKebab,
|
|
129
|
+
log: cliOptions.usageSilent ? NOOP : log,
|
|
130
|
+
validationError
|
|
131
|
+
});
|
|
132
|
+
if (Object.keys(extensions).length > 0) {
|
|
133
|
+
const ext = create(null);
|
|
134
|
+
Object.defineProperty(core, "extensions", {
|
|
135
|
+
value: ext,
|
|
136
|
+
writable: false,
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
140
|
+
for (const [key, extension2] of Object.entries(extensions)) {
|
|
141
|
+
ext[key] = await extension2.factory(core, command);
|
|
142
|
+
if (extension2.onFactory) await extension2.onFactory(core, command);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return deepFreeze(core, ["extensions"]);
|
|
146
|
+
}
|
|
147
|
+
__name(createCommandContext, "createCommandContext");
|
|
148
|
+
function getCommandName(cmd) {
|
|
149
|
+
if (isLazyCommand(cmd)) return cmd.commandName || cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
150
|
+
else if (typeof cmd === "object") return cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
151
|
+
else return ANONYMOUS_COMMAND_NAME;
|
|
152
|
+
}
|
|
153
|
+
__name(getCommandName, "getCommandName");
|
|
154
|
+
|
|
155
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/definition.js
|
|
156
|
+
function define(definition) {
|
|
157
|
+
return definition;
|
|
158
|
+
}
|
|
159
|
+
__name(define, "define");
|
|
160
|
+
|
|
161
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/core-C9P_Gd_f.js
|
|
162
|
+
var HYPHEN_CHAR = "-";
|
|
163
|
+
var HYPHEN_CODE = HYPHEN_CHAR.codePointAt(0);
|
|
164
|
+
var EQUAL_CHAR = "=";
|
|
165
|
+
var EQUAL_CODE = EQUAL_CHAR.codePointAt(0);
|
|
166
|
+
var TERMINATOR = "--";
|
|
167
|
+
var SHORT_OPTION_PREFIX = HYPHEN_CHAR;
|
|
168
|
+
var LONG_OPTION_PREFIX = "--";
|
|
169
|
+
function parseArgs(args, options = {}) {
|
|
170
|
+
const { allowCompatible = false } = options;
|
|
171
|
+
const tokens = [];
|
|
172
|
+
const remainings = [...args];
|
|
173
|
+
let index = -1;
|
|
174
|
+
let groupCount = 0;
|
|
175
|
+
let hasShortValueSeparator = false;
|
|
176
|
+
while (remainings.length > 0) {
|
|
177
|
+
const arg = remainings.shift();
|
|
178
|
+
if (arg == void 0) break;
|
|
179
|
+
const nextArg = remainings[0];
|
|
180
|
+
if (groupCount > 0) groupCount--;
|
|
181
|
+
else index++;
|
|
182
|
+
if (arg === TERMINATOR) {
|
|
183
|
+
tokens.push({
|
|
184
|
+
kind: "option-terminator",
|
|
185
|
+
index
|
|
186
|
+
});
|
|
187
|
+
const mapped = remainings.map((arg2) => {
|
|
188
|
+
return {
|
|
189
|
+
kind: "positional",
|
|
190
|
+
index: ++index,
|
|
191
|
+
value: arg2
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
tokens.push(...mapped);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
if (isShortOption(arg)) {
|
|
198
|
+
const shortOption = arg.charAt(1);
|
|
199
|
+
let value;
|
|
200
|
+
let inlineValue;
|
|
201
|
+
if (groupCount) {
|
|
202
|
+
tokens.push({
|
|
203
|
+
kind: "option",
|
|
204
|
+
name: shortOption,
|
|
205
|
+
rawName: arg,
|
|
206
|
+
index,
|
|
207
|
+
value,
|
|
208
|
+
inlineValue
|
|
209
|
+
});
|
|
210
|
+
if (groupCount === 1 && hasOptionValue(nextArg)) {
|
|
211
|
+
value = remainings.shift();
|
|
212
|
+
if (hasShortValueSeparator) {
|
|
213
|
+
inlineValue = true;
|
|
214
|
+
hasShortValueSeparator = false;
|
|
215
|
+
}
|
|
216
|
+
tokens.push({
|
|
217
|
+
kind: "option",
|
|
218
|
+
index,
|
|
219
|
+
value,
|
|
220
|
+
inlineValue
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
} else tokens.push({
|
|
224
|
+
kind: "option",
|
|
225
|
+
name: shortOption,
|
|
226
|
+
rawName: arg,
|
|
227
|
+
index,
|
|
228
|
+
value,
|
|
229
|
+
inlineValue
|
|
230
|
+
});
|
|
231
|
+
if (value != null) ++index;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (isShortOptionGroup(arg)) {
|
|
235
|
+
const expanded = [];
|
|
236
|
+
let shortValue = "";
|
|
237
|
+
for (let i = 1; i < arg.length; i++) {
|
|
238
|
+
const shortableOption = arg.charAt(i);
|
|
239
|
+
if (hasShortValueSeparator) shortValue += shortableOption;
|
|
240
|
+
else if (!allowCompatible && shortableOption.codePointAt(0) === EQUAL_CODE) hasShortValueSeparator = true;
|
|
241
|
+
else expanded.push(`${SHORT_OPTION_PREFIX}${shortableOption}`);
|
|
242
|
+
}
|
|
243
|
+
if (shortValue) expanded.push(shortValue);
|
|
244
|
+
remainings.unshift(...expanded);
|
|
245
|
+
groupCount = expanded.length;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (isLongOption(arg)) {
|
|
249
|
+
const longOption = arg.slice(2);
|
|
250
|
+
tokens.push({
|
|
251
|
+
kind: "option",
|
|
252
|
+
name: longOption,
|
|
253
|
+
rawName: arg,
|
|
254
|
+
index,
|
|
255
|
+
value: void 0,
|
|
256
|
+
inlineValue: void 0
|
|
257
|
+
});
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (isLongOptionAndValue(arg)) {
|
|
261
|
+
const equalIndex = arg.indexOf(EQUAL_CHAR);
|
|
262
|
+
const longOption = arg.slice(2, equalIndex);
|
|
263
|
+
const value = arg.slice(equalIndex + 1);
|
|
264
|
+
tokens.push({
|
|
265
|
+
kind: "option",
|
|
266
|
+
name: longOption,
|
|
267
|
+
rawName: `${LONG_OPTION_PREFIX}${longOption}`,
|
|
268
|
+
index,
|
|
269
|
+
value,
|
|
270
|
+
inlineValue: true
|
|
271
|
+
});
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
tokens.push({
|
|
275
|
+
kind: "positional",
|
|
276
|
+
index,
|
|
277
|
+
value: arg
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return tokens;
|
|
281
|
+
}
|
|
282
|
+
__name(parseArgs, "parseArgs");
|
|
283
|
+
function isShortOption(arg) {
|
|
284
|
+
return arg.length === 2 && arg.codePointAt(0) === HYPHEN_CODE && arg.codePointAt(1) !== HYPHEN_CODE;
|
|
285
|
+
}
|
|
286
|
+
__name(isShortOption, "isShortOption");
|
|
287
|
+
function isShortOptionGroup(arg) {
|
|
288
|
+
if (arg.length <= 2) return false;
|
|
289
|
+
if (arg.codePointAt(0) !== HYPHEN_CODE) return false;
|
|
290
|
+
if (arg.codePointAt(1) === HYPHEN_CODE) return false;
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
__name(isShortOptionGroup, "isShortOptionGroup");
|
|
294
|
+
function isLongOption(arg) {
|
|
295
|
+
return hasLongOptionPrefix(arg) && !arg.includes(EQUAL_CHAR, 3);
|
|
296
|
+
}
|
|
297
|
+
__name(isLongOption, "isLongOption");
|
|
298
|
+
function isLongOptionAndValue(arg) {
|
|
299
|
+
return hasLongOptionPrefix(arg) && arg.includes(EQUAL_CHAR, 3);
|
|
300
|
+
}
|
|
301
|
+
__name(isLongOptionAndValue, "isLongOptionAndValue");
|
|
302
|
+
function hasLongOptionPrefix(arg) {
|
|
303
|
+
return arg.length > 2 && ~arg.indexOf(LONG_OPTION_PREFIX);
|
|
304
|
+
}
|
|
305
|
+
__name(hasLongOptionPrefix, "hasLongOptionPrefix");
|
|
306
|
+
function hasOptionValue(value) {
|
|
307
|
+
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
308
|
+
}
|
|
309
|
+
__name(hasOptionValue, "hasOptionValue");
|
|
310
|
+
var SKIP_POSITIONAL_DEFAULT = -1;
|
|
311
|
+
function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKIP_POSITIONAL_DEFAULT, toKebab = false } = {}) {
|
|
312
|
+
const skipPositionalIndex = typeof skipPositional === "number" ? Math.max(skipPositional, SKIP_POSITIONAL_DEFAULT) : SKIP_POSITIONAL_DEFAULT;
|
|
313
|
+
const rest = [];
|
|
314
|
+
const optionTokens = [];
|
|
315
|
+
const positionalTokens = [];
|
|
316
|
+
let currentLongOption;
|
|
317
|
+
let currentShortOption;
|
|
318
|
+
const expandableShortOptions = [];
|
|
319
|
+
function toShortValue() {
|
|
320
|
+
if (expandableShortOptions.length === 0) return;
|
|
321
|
+
else {
|
|
322
|
+
const value = expandableShortOptions.map((token) => token.name).join("");
|
|
323
|
+
expandableShortOptions.length = 0;
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
__name(toShortValue, "toShortValue");
|
|
328
|
+
function applyLongOptionValue(value = void 0) {
|
|
329
|
+
if (currentLongOption) {
|
|
330
|
+
currentLongOption.value = value;
|
|
331
|
+
optionTokens.push({ ...currentLongOption });
|
|
332
|
+
currentLongOption = void 0;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
__name(applyLongOptionValue, "applyLongOptionValue");
|
|
336
|
+
function applyShortOptionValue(value = void 0) {
|
|
337
|
+
if (currentShortOption) {
|
|
338
|
+
currentShortOption.value = value || toShortValue();
|
|
339
|
+
optionTokens.push({ ...currentShortOption });
|
|
340
|
+
currentShortOption = void 0;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
__name(applyShortOptionValue, "applyShortOptionValue");
|
|
344
|
+
const schemas = Object.values(args);
|
|
345
|
+
let terminated = false;
|
|
346
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
347
|
+
const token = tokens[i];
|
|
348
|
+
if (token.kind === "positional") {
|
|
349
|
+
if (terminated && token.value) {
|
|
350
|
+
rest.push(token.value);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (currentShortOption) {
|
|
354
|
+
if (schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean")) positionalTokens.push({ ...token });
|
|
355
|
+
} else if (currentLongOption) {
|
|
356
|
+
if (args[currentLongOption.name]?.type === "boolean") positionalTokens.push({ ...token });
|
|
357
|
+
} else positionalTokens.push({ ...token });
|
|
358
|
+
applyLongOptionValue(token.value);
|
|
359
|
+
applyShortOptionValue(token.value);
|
|
360
|
+
} else if (token.kind === "option") if (token.rawName) {
|
|
361
|
+
if (hasLongOptionPrefix(token.rawName)) {
|
|
362
|
+
applyLongOptionValue();
|
|
363
|
+
if (token.inlineValue) optionTokens.push({ ...token });
|
|
364
|
+
else currentLongOption = { ...token };
|
|
365
|
+
applyShortOptionValue();
|
|
366
|
+
} else if (isShortOption(token.rawName)) if (currentShortOption) {
|
|
367
|
+
if (currentShortOption.index === token.index) if (shortGrouping) {
|
|
368
|
+
currentShortOption.value = token.value;
|
|
369
|
+
optionTokens.push({ ...currentShortOption });
|
|
370
|
+
currentShortOption = { ...token };
|
|
371
|
+
} else expandableShortOptions.push({ ...token });
|
|
372
|
+
else {
|
|
373
|
+
currentShortOption.value = toShortValue();
|
|
374
|
+
optionTokens.push({ ...currentShortOption });
|
|
375
|
+
currentShortOption = { ...token };
|
|
376
|
+
}
|
|
377
|
+
applyLongOptionValue();
|
|
378
|
+
} else {
|
|
379
|
+
currentShortOption = { ...token };
|
|
380
|
+
applyLongOptionValue();
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
|
|
384
|
+
currentShortOption.value = token.value;
|
|
385
|
+
optionTokens.push({ ...currentShortOption });
|
|
386
|
+
currentShortOption = void 0;
|
|
387
|
+
}
|
|
388
|
+
applyLongOptionValue();
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
if (token.kind === "option-terminator") terminated = true;
|
|
392
|
+
applyLongOptionValue();
|
|
393
|
+
applyShortOptionValue();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
applyLongOptionValue();
|
|
397
|
+
applyShortOptionValue();
|
|
398
|
+
const values = /* @__PURE__ */ Object.create(null);
|
|
399
|
+
const errors = [];
|
|
400
|
+
const explicit = /* @__PURE__ */ Object.create(null);
|
|
401
|
+
const actualInputNames = /* @__PURE__ */ new Map();
|
|
402
|
+
function checkTokenName(option, schema, token) {
|
|
403
|
+
return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
|
|
404
|
+
}
|
|
405
|
+
__name(checkTokenName, "checkTokenName");
|
|
406
|
+
const positionalItemCount = tokens.filter((token) => token.kind === "positional").length;
|
|
407
|
+
function getPositionalSkipIndex() {
|
|
408
|
+
return Math.min(skipPositionalIndex, positionalItemCount);
|
|
409
|
+
}
|
|
410
|
+
__name(getPositionalSkipIndex, "getPositionalSkipIndex");
|
|
411
|
+
let positionalsCount = 0;
|
|
412
|
+
for (const [rawArg, schema] of Object.entries(args)) {
|
|
413
|
+
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
414
|
+
explicit[rawArg] = false;
|
|
415
|
+
if (schema.type === "positional") {
|
|
416
|
+
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
|
|
417
|
+
if (schema.multiple) {
|
|
418
|
+
const remainingPositionals = positionalTokens.slice(positionalsCount);
|
|
419
|
+
if (remainingPositionals.length > 0) {
|
|
420
|
+
values[rawArg] = remainingPositionals.map((p) => p.value);
|
|
421
|
+
positionalsCount += remainingPositionals.length;
|
|
422
|
+
explicit[rawArg] = true;
|
|
423
|
+
} else if (schema.required) errors.push(createRequireError(arg, schema));
|
|
424
|
+
} else {
|
|
425
|
+
const positional = positionalTokens[positionalsCount];
|
|
426
|
+
if (positional != null) {
|
|
427
|
+
values[rawArg] = positional.value;
|
|
428
|
+
explicit[rawArg] = true;
|
|
429
|
+
} else errors.push(createRequireError(arg, schema));
|
|
430
|
+
positionalsCount++;
|
|
431
|
+
}
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (schema.required) {
|
|
435
|
+
if (!optionTokens.find((token) => {
|
|
436
|
+
return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
|
|
437
|
+
})) {
|
|
438
|
+
errors.push(createRequireError(arg, schema));
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
for (let i = 0; i < optionTokens.length; i++) {
|
|
443
|
+
const token = optionTokens[i];
|
|
444
|
+
if (checkTokenName(arg, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
|
|
445
|
+
const invalid = validateRequire(token, arg, schema);
|
|
446
|
+
if (invalid) {
|
|
447
|
+
errors.push(invalid);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
explicit[rawArg] = true;
|
|
451
|
+
const actualInputName = isShortOption(token.rawName) ? `-${token.name}` : `--${arg}`;
|
|
452
|
+
actualInputNames.set(rawArg, actualInputName);
|
|
453
|
+
if (schema.type === "boolean") token.value = void 0;
|
|
454
|
+
const [parsedValue, error] = parse(token, arg, schema);
|
|
455
|
+
if (error) errors.push(error);
|
|
456
|
+
else if (schema.multiple) {
|
|
457
|
+
values[rawArg] ||= [];
|
|
458
|
+
values[rawArg].push(parsedValue);
|
|
459
|
+
} else values[rawArg] = parsedValue;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (values[rawArg] == null && schema.default != null) values[rawArg] = schema.default;
|
|
463
|
+
}
|
|
464
|
+
const conflictErrors = checkConflicts(args, explicit, toKebab, actualInputNames);
|
|
465
|
+
errors.push(...conflictErrors);
|
|
466
|
+
return {
|
|
467
|
+
values,
|
|
468
|
+
positionals: positionalTokens.map((token) => token.value),
|
|
469
|
+
rest,
|
|
470
|
+
error: errors.length > 0 ? new AggregateError(errors) : void 0,
|
|
471
|
+
explicit
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
__name(resolveArgs, "resolveArgs");
|
|
475
|
+
function parse(token, option, schema) {
|
|
476
|
+
switch (schema.type) {
|
|
477
|
+
case "string":
|
|
478
|
+
return typeof token.value === "string" ? [token.value || schema.default, void 0] : [void 0, createTypeError(option, schema)];
|
|
479
|
+
case "boolean":
|
|
480
|
+
return token.value ? [token.value || schema.default, void 0] : [!(schema.negatable && token.name.startsWith("no-")), void 0];
|
|
481
|
+
case "number":
|
|
482
|
+
if (!isNumeric(token.value)) return [void 0, createTypeError(option, schema)];
|
|
483
|
+
return token.value ? [+token.value, void 0] : [+(schema.default || ""), void 0];
|
|
484
|
+
case "enum":
|
|
485
|
+
if (schema.choices && !schema.choices.includes(token.value)) return [void 0, new ArgResolveError(`Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be chosen from '${schema.type}' [${schema.choices.map((c) => JSON.stringify(c)).join(", ")}] values`, option, "type", schema)];
|
|
486
|
+
return [token.value || schema.default, void 0];
|
|
487
|
+
case "custom":
|
|
488
|
+
if (typeof schema.parse !== "function") throw new TypeError(`argument '${option}' should have a 'parse' function`);
|
|
489
|
+
try {
|
|
490
|
+
return [schema.parse(token.value || String(schema.default || "")), void 0];
|
|
491
|
+
} catch (error) {
|
|
492
|
+
return [void 0, error];
|
|
493
|
+
}
|
|
494
|
+
default:
|
|
495
|
+
throw new Error(`Unsupported argument type '${schema.type}' for option '${option}'`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
__name(parse, "parse");
|
|
499
|
+
function createRequireError(option, schema) {
|
|
500
|
+
return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, "required", schema);
|
|
501
|
+
}
|
|
502
|
+
__name(createRequireError, "createRequireError");
|
|
503
|
+
var ArgResolveError = class extends Error {
|
|
504
|
+
static {
|
|
505
|
+
__name(this, "ArgResolveError");
|
|
506
|
+
}
|
|
507
|
+
name;
|
|
508
|
+
schema;
|
|
509
|
+
type;
|
|
510
|
+
/**
|
|
511
|
+
* Create an `ArgResolveError` instance.
|
|
512
|
+
*
|
|
513
|
+
* @param message - the error message
|
|
514
|
+
* @param name - the name of the argument
|
|
515
|
+
* @param type - the type of the error, either 'type' or 'required'
|
|
516
|
+
* @param schema - the argument schema that caused the error
|
|
517
|
+
*/
|
|
518
|
+
constructor(message, name, type, schema) {
|
|
519
|
+
super(message);
|
|
520
|
+
this.name = name;
|
|
521
|
+
this.type = type;
|
|
522
|
+
this.schema = schema;
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
function validateRequire(token, option, schema) {
|
|
526
|
+
if (schema.required && schema.type !== "boolean" && !token.value) return createRequireError(option, schema);
|
|
527
|
+
}
|
|
528
|
+
__name(validateRequire, "validateRequire");
|
|
529
|
+
function isNumeric(str) {
|
|
530
|
+
return str.trim() !== "" && !isNaN(str);
|
|
531
|
+
}
|
|
532
|
+
__name(isNumeric, "isNumeric");
|
|
533
|
+
function createTypeError(option, schema) {
|
|
534
|
+
return new ArgResolveError(`Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be '${schema.type}'`, option, "type", schema);
|
|
535
|
+
}
|
|
536
|
+
__name(createTypeError, "createTypeError");
|
|
537
|
+
function checkConflicts(args, explicit, toKebab, actualInputNames) {
|
|
538
|
+
for (const rawArg in args) {
|
|
539
|
+
const schema = args[rawArg];
|
|
540
|
+
if (!explicit[rawArg]) continue;
|
|
541
|
+
if (!schema.conflicts) continue;
|
|
542
|
+
const conflicts = Array.isArray(schema.conflicts) ? schema.conflicts : [schema.conflicts];
|
|
543
|
+
for (let i = 0; i < conflicts.length; i++) {
|
|
544
|
+
const conflictingArg = conflicts[i];
|
|
545
|
+
if (!explicit[conflictingArg]) continue;
|
|
546
|
+
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
547
|
+
const conflictingArgKebab = toKebab || args[conflictingArg]?.toKebab ? kebabnize(conflictingArg) : conflictingArg;
|
|
548
|
+
return [new ArgResolveError(`Optional argument '${actualInputNames.get(rawArg) || `--${arg}`}' conflicts with '${actualInputNames.get(conflictingArg) || `--${conflictingArgKebab}`}'`, rawArg, "conflict", schema)];
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return [];
|
|
552
|
+
}
|
|
553
|
+
__name(checkConflicts, "checkConflicts");
|
|
554
|
+
var EMPTY_RENDERER = /* @__PURE__ */ __name(() => Promise.resolve(""), "EMPTY_RENDERER");
|
|
555
|
+
function createDecorators() {
|
|
556
|
+
const headerDecorators = [];
|
|
557
|
+
const usageDecorators = [];
|
|
558
|
+
const validationDecorators = [];
|
|
559
|
+
const commandDecorators = [];
|
|
560
|
+
function buildRenderer(decorators, defaultRenderer) {
|
|
561
|
+
if (decorators.length === 0) return defaultRenderer;
|
|
562
|
+
let renderer2 = defaultRenderer;
|
|
563
|
+
for (const decorator2 of decorators) {
|
|
564
|
+
const previousRenderer = renderer2;
|
|
565
|
+
renderer2 = /* @__PURE__ */ __name((ctx) => decorator2(previousRenderer, ctx), "renderer");
|
|
566
|
+
}
|
|
567
|
+
return renderer2;
|
|
568
|
+
}
|
|
569
|
+
__name(buildRenderer, "buildRenderer");
|
|
570
|
+
return Object.freeze({
|
|
571
|
+
addHeaderDecorator(decorator2) {
|
|
572
|
+
headerDecorators.push(decorator2);
|
|
573
|
+
},
|
|
574
|
+
addUsageDecorator(decorator2) {
|
|
575
|
+
usageDecorators.push(decorator2);
|
|
576
|
+
},
|
|
577
|
+
addValidationErrorsDecorator(decorator2) {
|
|
578
|
+
validationDecorators.push(decorator2);
|
|
579
|
+
},
|
|
580
|
+
addCommandDecorator(decorator2) {
|
|
581
|
+
commandDecorators.push(decorator2);
|
|
582
|
+
},
|
|
583
|
+
get commandDecorators() {
|
|
584
|
+
return [...commandDecorators];
|
|
585
|
+
},
|
|
586
|
+
getHeaderRenderer() {
|
|
587
|
+
return buildRenderer(headerDecorators, EMPTY_RENDERER);
|
|
588
|
+
},
|
|
589
|
+
getUsageRenderer() {
|
|
590
|
+
return buildRenderer(usageDecorators, EMPTY_RENDERER);
|
|
591
|
+
},
|
|
592
|
+
getValidationErrorsRenderer() {
|
|
593
|
+
if (validationDecorators.length === 0) return EMPTY_RENDERER;
|
|
594
|
+
let renderer2 = EMPTY_RENDERER;
|
|
595
|
+
for (const decorator2 of validationDecorators) {
|
|
596
|
+
const previousRenderer = renderer2;
|
|
597
|
+
renderer2 = /* @__PURE__ */ __name((ctx, error) => decorator2(previousRenderer, ctx, error), "renderer");
|
|
598
|
+
}
|
|
599
|
+
return renderer2;
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
__name(createDecorators, "createDecorators");
|
|
604
|
+
function createPluginContext(decorators, initialSubCommands) {
|
|
605
|
+
const globalOptions = /* @__PURE__ */ new Map();
|
|
606
|
+
const subCommands = new Map(initialSubCommands || []);
|
|
607
|
+
return Object.freeze({
|
|
608
|
+
get globalOptions() {
|
|
609
|
+
return new Map(globalOptions);
|
|
610
|
+
},
|
|
611
|
+
addGlobalOption(name, schema) {
|
|
612
|
+
if (!name) throw new Error("Option name must be a non-empty string");
|
|
613
|
+
if (globalOptions.has(name)) throw new Error(`Global option '${name}' is already registered`);
|
|
614
|
+
globalOptions.set(name, schema);
|
|
615
|
+
},
|
|
616
|
+
get subCommands() {
|
|
617
|
+
return new Map(subCommands);
|
|
618
|
+
},
|
|
619
|
+
addCommand(name, command) {
|
|
620
|
+
if (!name) throw new Error("Command name must be a non-empty string");
|
|
621
|
+
if (subCommands.has(name)) throw new Error(`Command '${name}' is already registered`);
|
|
622
|
+
subCommands.set(name, command);
|
|
623
|
+
},
|
|
624
|
+
hasCommand(name) {
|
|
625
|
+
return subCommands.has(name);
|
|
626
|
+
},
|
|
627
|
+
decorateHeaderRenderer(decorator2) {
|
|
628
|
+
decorators.addHeaderDecorator(decorator2);
|
|
629
|
+
},
|
|
630
|
+
decorateUsageRenderer(decorator2) {
|
|
631
|
+
decorators.addUsageDecorator(decorator2);
|
|
632
|
+
},
|
|
633
|
+
decorateValidationErrorsRenderer(decorator2) {
|
|
634
|
+
decorators.addValidationErrorsDecorator(decorator2);
|
|
635
|
+
},
|
|
636
|
+
decorateCommand(decorator2) {
|
|
637
|
+
decorators.addCommandDecorator(decorator2);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
__name(createPluginContext, "createPluginContext");
|
|
642
|
+
function resolveDependencies(plugins) {
|
|
643
|
+
const sorted = [];
|
|
644
|
+
const visited = /* @__PURE__ */ new Set();
|
|
645
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
646
|
+
const pluginMap = /* @__PURE__ */ new Map();
|
|
647
|
+
for (const plugin2 of plugins) if (plugin2.id) {
|
|
648
|
+
if (pluginMap.has(plugin2.id)) console.warn(`Duplicate plugin id detected: \`${plugin2.id}\``);
|
|
649
|
+
pluginMap.set(plugin2.id, plugin2);
|
|
650
|
+
}
|
|
651
|
+
function visit(plugin2) {
|
|
652
|
+
if (!plugin2.id) return;
|
|
653
|
+
if (visited.has(plugin2.id)) return;
|
|
654
|
+
if (visiting.has(plugin2.id)) throw new Error(`Circular dependency detected: \`${[...visiting].join(` -> `) + " -> " + plugin2.id}\``);
|
|
655
|
+
visiting.add(plugin2.id);
|
|
656
|
+
const deps = plugin2.dependencies || [];
|
|
657
|
+
for (const dep of deps) {
|
|
658
|
+
const depId = typeof dep === "string" ? dep : dep.id;
|
|
659
|
+
const isOptional = typeof dep === "string" ? false : dep.optional || false;
|
|
660
|
+
const depPlugin = pluginMap.get(depId);
|
|
661
|
+
if (!depPlugin && !isOptional) throw new Error(`Missing required dependency: \`${depId}\` on \`${plugin2.id}\``);
|
|
662
|
+
if (depPlugin) visit(depPlugin);
|
|
663
|
+
}
|
|
664
|
+
visiting.delete(plugin2.id);
|
|
665
|
+
visited.add(plugin2.id);
|
|
666
|
+
sorted.push(plugin2);
|
|
667
|
+
}
|
|
668
|
+
__name(visit, "visit");
|
|
669
|
+
for (const plugin2 of plugins) visit(plugin2);
|
|
670
|
+
return sorted;
|
|
671
|
+
}
|
|
672
|
+
__name(resolveDependencies, "resolveDependencies");
|
|
673
|
+
async function cliCore(argv, entry, options, plugins) {
|
|
674
|
+
const decorators = createDecorators();
|
|
675
|
+
const pluginContext = createPluginContext(decorators, createInitialSubCommands(options, entry));
|
|
676
|
+
const resolvedPlugins = await applyPlugins(pluginContext, [...plugins, ...options.plugins || []]);
|
|
677
|
+
const cliOptions = normalizeCliOptions(options, decorators, pluginContext);
|
|
678
|
+
const tokens = parseArgs(argv);
|
|
679
|
+
const resolved = resolveCommandTree(tokens, entry, cliOptions);
|
|
680
|
+
const { commandName: name, command, callMode, commandPath, depth, levelSubCommands } = resolved;
|
|
681
|
+
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
682
|
+
const args = resolveArguments(pluginContext, getCommandArgs(command));
|
|
683
|
+
const skipPositional = depth > 0 ? depth - 1 : -1;
|
|
684
|
+
const { explicit, values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
685
|
+
shortGrouping: true,
|
|
686
|
+
toKebab: command.toKebab,
|
|
687
|
+
skipPositional
|
|
688
|
+
});
|
|
689
|
+
const omitted = resolved.omitted;
|
|
690
|
+
if (levelSubCommands) cliOptions.subCommands = levelSubCommands;
|
|
691
|
+
const resolvedCommand = isLazyCommand(command) ? await resolveLazyCommand(command, name, true) : command;
|
|
692
|
+
return await executeCommand(resolvedCommand, await createCommandContext({
|
|
693
|
+
args,
|
|
694
|
+
explicit,
|
|
695
|
+
values,
|
|
696
|
+
positionals,
|
|
697
|
+
rest,
|
|
698
|
+
argv,
|
|
699
|
+
tokens,
|
|
700
|
+
omitted,
|
|
701
|
+
callMode,
|
|
702
|
+
commandPath,
|
|
703
|
+
command: resolvedCommand,
|
|
704
|
+
extensions: getPluginExtensions(resolvedPlugins),
|
|
705
|
+
validationError: error,
|
|
706
|
+
cliOptions
|
|
707
|
+
}), decorators.commandDecorators);
|
|
708
|
+
}
|
|
709
|
+
__name(cliCore, "cliCore");
|
|
710
|
+
async function applyPlugins(pluginContext, plugins) {
|
|
711
|
+
const sortedPlugins = resolveDependencies(plugins);
|
|
712
|
+
try {
|
|
713
|
+
for (const plugin2 of sortedPlugins)
|
|
714
|
+
await plugin2(pluginContext);
|
|
715
|
+
} catch (error) {
|
|
716
|
+
console.error("Error loading plugin:", error.message);
|
|
717
|
+
}
|
|
718
|
+
return sortedPlugins;
|
|
719
|
+
}
|
|
720
|
+
__name(applyPlugins, "applyPlugins");
|
|
721
|
+
function getCommandArgs(cmd) {
|
|
722
|
+
if (isLazyCommand(cmd)) return cmd.args || create();
|
|
723
|
+
else if (typeof cmd === "object") return cmd.args || create();
|
|
724
|
+
else return create();
|
|
725
|
+
}
|
|
726
|
+
__name(getCommandArgs, "getCommandArgs");
|
|
727
|
+
function resolveArguments(pluginContext, args) {
|
|
728
|
+
return Object.assign(create(), Object.fromEntries(pluginContext.globalOptions), args);
|
|
729
|
+
}
|
|
730
|
+
__name(resolveArguments, "resolveArguments");
|
|
731
|
+
var isObject = /* @__PURE__ */ __name((val) => val !== null && typeof val === "object", "isObject");
|
|
732
|
+
function createInitialSubCommands(options, entryCmd) {
|
|
733
|
+
const hasSubCommands = options.subCommands ? options.subCommands instanceof Map ? options.subCommands.size > 0 : isObject(options.subCommands) && Object.keys(options.subCommands).length > 0 : false;
|
|
734
|
+
const subCommands = new Map(options.subCommands instanceof Map ? options.subCommands : []);
|
|
735
|
+
if (!(options.subCommands instanceof Map) && isObject(options.subCommands)) for (const [name, cmd] of Object.entries(options.subCommands)) subCommands.set(name, cmd);
|
|
736
|
+
if (hasSubCommands) {
|
|
737
|
+
if (isLazyCommand(entryCmd)) {
|
|
738
|
+
const entryCopy = Object.assign((...args) => entryCmd(...args), entryCmd, { entry: true });
|
|
739
|
+
subCommands.set(resolveEntryName(entryCopy), entryCopy);
|
|
740
|
+
} else if (typeof entryCmd === "object") {
|
|
741
|
+
const entryCopy = Object.assign(create(), entryCmd, { entry: true });
|
|
742
|
+
subCommands.set(resolveEntryName(entryCopy), entryCopy);
|
|
743
|
+
} else if (typeof entryCmd === "function") {
|
|
744
|
+
const name = entryCmd.name || ANONYMOUS_COMMAND_NAME;
|
|
745
|
+
subCommands.set(name, {
|
|
746
|
+
run: entryCmd,
|
|
747
|
+
name,
|
|
748
|
+
entry: true
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return subCommands;
|
|
753
|
+
}
|
|
754
|
+
__name(createInitialSubCommands, "createInitialSubCommands");
|
|
755
|
+
function normalizeCliOptions(options, decorators, pluginContext) {
|
|
756
|
+
const subCommands = new Map(pluginContext.subCommands);
|
|
757
|
+
const resolvedOptions = Object.assign(create(), CLI_OPTIONS_DEFAULT, options, { subCommands });
|
|
758
|
+
if (resolvedOptions.renderHeader === void 0) resolvedOptions.renderHeader = decorators.getHeaderRenderer();
|
|
759
|
+
if (resolvedOptions.renderUsage === void 0) resolvedOptions.renderUsage = decorators.getUsageRenderer();
|
|
760
|
+
if (resolvedOptions.renderValidationErrors === void 0) resolvedOptions.renderValidationErrors = decorators.getValidationErrorsRenderer();
|
|
761
|
+
return resolvedOptions;
|
|
762
|
+
}
|
|
763
|
+
__name(normalizeCliOptions, "normalizeCliOptions");
|
|
764
|
+
function getPositionalTokens(tokens) {
|
|
765
|
+
return tokens.filter((t) => t.kind === "positional").map((t) => t.value).filter((v) => !!v);
|
|
766
|
+
}
|
|
767
|
+
__name(getPositionalTokens, "getPositionalTokens");
|
|
768
|
+
function resolveCommandTree(tokens, entry, options) {
|
|
769
|
+
const positionals = getPositionalTokens(tokens);
|
|
770
|
+
function resolveAsEntry() {
|
|
771
|
+
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
|
|
772
|
+
commandName: entry.commandName,
|
|
773
|
+
command: entry,
|
|
774
|
+
callMode: "entry",
|
|
775
|
+
commandPath: [],
|
|
776
|
+
depth: 0,
|
|
777
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
778
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
|
|
779
|
+
};
|
|
780
|
+
else return {
|
|
781
|
+
command: {
|
|
782
|
+
run: entry,
|
|
783
|
+
entry: true
|
|
784
|
+
},
|
|
785
|
+
callMode: "entry",
|
|
786
|
+
commandPath: [],
|
|
787
|
+
depth: 0,
|
|
788
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
789
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
|
|
790
|
+
};
|
|
791
|
+
else if (typeof entry === "object") return {
|
|
792
|
+
commandName: resolveEntryName(entry),
|
|
793
|
+
command: entry,
|
|
794
|
+
callMode: "entry",
|
|
795
|
+
commandPath: [],
|
|
796
|
+
depth: 0,
|
|
797
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
798
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
|
|
799
|
+
};
|
|
800
|
+
else return {
|
|
801
|
+
callMode: "unexpected",
|
|
802
|
+
commandPath: [],
|
|
803
|
+
depth: 0,
|
|
804
|
+
omitted: false,
|
|
805
|
+
levelSubCommands: void 0
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
__name(resolveAsEntry, "resolveAsEntry");
|
|
809
|
+
if (positionals.length === 0 || options.subCommands.size === 0) return resolveAsEntry();
|
|
810
|
+
let currentSubCommands = options.subCommands;
|
|
811
|
+
let resolvedCommand;
|
|
812
|
+
let resolvedName;
|
|
813
|
+
const commandPath = [];
|
|
814
|
+
let depth = 0;
|
|
815
|
+
for (let i = 0; i < positionals.length; i++) {
|
|
816
|
+
const token = positionals[i];
|
|
817
|
+
const cmd = currentSubCommands.get(token);
|
|
818
|
+
if (cmd == null) {
|
|
819
|
+
if (depth === 0) {
|
|
820
|
+
if (options.fallbackToEntry) return resolveAsEntry();
|
|
821
|
+
return {
|
|
822
|
+
commandName: token,
|
|
823
|
+
callMode: "unexpected",
|
|
824
|
+
commandPath: [],
|
|
825
|
+
depth: 0,
|
|
826
|
+
omitted: false,
|
|
827
|
+
levelSubCommands: void 0
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
let resolved = cmd;
|
|
833
|
+
if (typeof cmd === "function" && cmd.commandName == null) resolved = Object.assign((...args) => cmd(...args), cmd, { commandName: token });
|
|
834
|
+
else if (typeof cmd === "object" && cmd.name == null) resolved = Object.assign(create(), cmd, { name: token });
|
|
835
|
+
resolvedCommand = resolved;
|
|
836
|
+
resolvedName = token;
|
|
837
|
+
commandPath.push(token);
|
|
838
|
+
depth++;
|
|
839
|
+
const nestedSubCommands = getCommandSubCommands(cmd);
|
|
840
|
+
if (nestedSubCommands && nestedSubCommands.size > 0) currentSubCommands = nestedSubCommands;
|
|
841
|
+
else break;
|
|
842
|
+
}
|
|
843
|
+
if (!resolvedCommand) return resolveAsEntry();
|
|
844
|
+
const resolvedSubCommands = getCommandSubCommands(resolvedCommand);
|
|
845
|
+
const omitted = resolvedSubCommands != null && resolvedSubCommands.size > 0;
|
|
846
|
+
let levelSubCommands;
|
|
847
|
+
if (omitted && resolvedSubCommands) {
|
|
848
|
+
levelSubCommands = new Map(resolvedSubCommands);
|
|
849
|
+
let entryCopy;
|
|
850
|
+
if (typeof resolvedCommand === "function") entryCopy = Object.assign((...args) => resolvedCommand(...args), resolvedCommand, { entry: true });
|
|
851
|
+
else entryCopy = Object.assign(create(), resolvedCommand, { entry: true });
|
|
852
|
+
levelSubCommands.set(resolvedName || resolveEntryName(entryCopy), entryCopy);
|
|
853
|
+
}
|
|
854
|
+
return {
|
|
855
|
+
commandName: resolvedName,
|
|
856
|
+
command: resolvedCommand,
|
|
857
|
+
callMode: depth > 0 ? "subCommand" : "entry",
|
|
858
|
+
commandPath,
|
|
859
|
+
depth,
|
|
860
|
+
omitted,
|
|
861
|
+
levelSubCommands
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
__name(resolveCommandTree, "resolveCommandTree");
|
|
865
|
+
function resolveEntryName(entry) {
|
|
866
|
+
return isLazyCommand(entry) ? entry.commandName || ANONYMOUS_COMMAND_NAME : entry.name || ANONYMOUS_COMMAND_NAME;
|
|
867
|
+
}
|
|
868
|
+
__name(resolveEntryName, "resolveEntryName");
|
|
869
|
+
function getPluginExtensions(plugins) {
|
|
870
|
+
const extensions = create();
|
|
871
|
+
for (const plugin2 of plugins) if (plugin2.extension) {
|
|
872
|
+
const key = plugin2.id;
|
|
873
|
+
if (extensions[key]) console.warn(`Plugin "${key}" is already installed. Ignore it for command context extending.`);
|
|
874
|
+
else extensions[key] = plugin2.extension;
|
|
875
|
+
}
|
|
876
|
+
return extensions;
|
|
877
|
+
}
|
|
878
|
+
__name(getPluginExtensions, "getPluginExtensions");
|
|
879
|
+
async function executeCommand(cmd, ctx, decorators) {
|
|
880
|
+
const baseRunner = cmd.run || NOOP;
|
|
881
|
+
const decoratedRunner = decorators.reduceRight((runner, decorator2) => decorator2(runner), baseRunner);
|
|
882
|
+
try {
|
|
883
|
+
if (ctx.env.onBeforeCommand) await ctx.env.onBeforeCommand(ctx);
|
|
884
|
+
const result = await decoratedRunner(ctx);
|
|
885
|
+
if (ctx.env.onAfterCommand) await ctx.env.onAfterCommand(ctx, result);
|
|
886
|
+
return typeof result === "string" ? result : void 0;
|
|
887
|
+
} catch (error) {
|
|
888
|
+
if (ctx.env.onErrorCommand) try {
|
|
889
|
+
await ctx.env.onErrorCommand(ctx, error);
|
|
890
|
+
} catch (hookError) {
|
|
891
|
+
console.error("Error in onErrorCommand hook:", hookError);
|
|
892
|
+
}
|
|
893
|
+
throw error;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
__name(executeCommand, "executeCommand");
|
|
897
|
+
|
|
898
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/core-eN5xmB3s.js
|
|
899
|
+
var NOOP_EXTENSION = /* @__PURE__ */ __name(() => {
|
|
900
|
+
return /* @__PURE__ */ Object.create(null);
|
|
901
|
+
}, "NOOP_EXTENSION");
|
|
902
|
+
function plugin(options = {}) {
|
|
903
|
+
const { id, name, setup, onExtension, dependencies: dependencies2 } = options;
|
|
904
|
+
const extension2 = options.extension || NOOP_EXTENSION;
|
|
905
|
+
const pluginFn = /* @__PURE__ */ __name(async (ctx) => {
|
|
906
|
+
if (setup) await setup(ctx);
|
|
907
|
+
}, "pluginFn");
|
|
908
|
+
const props = {
|
|
909
|
+
writable: false,
|
|
910
|
+
enumerable: true,
|
|
911
|
+
configurable: true
|
|
912
|
+
};
|
|
913
|
+
return Object.defineProperties(pluginFn, {
|
|
914
|
+
id: {
|
|
915
|
+
value: id,
|
|
916
|
+
...props
|
|
917
|
+
},
|
|
918
|
+
...name && { name: {
|
|
919
|
+
value: name,
|
|
920
|
+
...props
|
|
921
|
+
} },
|
|
922
|
+
...dependencies2 && { dependencies: {
|
|
923
|
+
value: dependencies2,
|
|
924
|
+
...props
|
|
925
|
+
} },
|
|
926
|
+
...extension2 && { extension: {
|
|
927
|
+
value: {
|
|
928
|
+
key: Symbol(id),
|
|
929
|
+
factory: extension2,
|
|
930
|
+
onFactory: onExtension
|
|
931
|
+
},
|
|
932
|
+
...props
|
|
933
|
+
} }
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
__name(plugin, "plugin");
|
|
937
|
+
|
|
938
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/src-CfO5ab2f.js
|
|
939
|
+
var BUILT_IN_PREFIX = "_";
|
|
940
|
+
var PLUGIN_PREFIX = "g";
|
|
941
|
+
var ARG_PREFIX = "arg";
|
|
942
|
+
var BUILT_IN_KEY_SEPARATOR = ":";
|
|
943
|
+
var BUILD_IN_PREFIX_AND_KEY_SEPARATOR = `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}`;
|
|
944
|
+
var ARG_PREFIX_AND_KEY_SEPARATOR = `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}`;
|
|
945
|
+
var ARG_NEGATABLE_PREFIX = "no-";
|
|
946
|
+
var COMMON_ARGS = {
|
|
947
|
+
help: {
|
|
948
|
+
type: "boolean",
|
|
949
|
+
short: "h",
|
|
950
|
+
description: "Display this help message"
|
|
951
|
+
},
|
|
952
|
+
version: {
|
|
953
|
+
type: "boolean",
|
|
954
|
+
short: "v",
|
|
955
|
+
description: "Display this version"
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
var NEGATABLE = "Negatable of";
|
|
959
|
+
var en_US_default = {
|
|
960
|
+
COMMAND: "COMMAND",
|
|
961
|
+
COMMANDS: "COMMANDS",
|
|
962
|
+
SUBCOMMAND: "SUBCOMMAND",
|
|
963
|
+
USAGE: "USAGE",
|
|
964
|
+
ARGUMENTS: "ARGUMENTS",
|
|
965
|
+
OPTIONS: "OPTIONS",
|
|
966
|
+
EXAMPLES: "EXAMPLES",
|
|
967
|
+
FORMORE: "For more info, run any command with the `--help` flag",
|
|
968
|
+
NEGATABLE,
|
|
969
|
+
DEFAULT: "default",
|
|
970
|
+
CHOICES: "choices",
|
|
971
|
+
help: "Display this help message",
|
|
972
|
+
version: "Display this version"
|
|
973
|
+
};
|
|
974
|
+
function resolveBuiltInKey(key) {
|
|
975
|
+
return `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
976
|
+
}
|
|
977
|
+
__name(resolveBuiltInKey, "resolveBuiltInKey");
|
|
978
|
+
function resolveArgKey(key, name) {
|
|
979
|
+
return `${name ? `${name}${BUILT_IN_KEY_SEPARATOR}` : ""}${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
980
|
+
}
|
|
981
|
+
__name(resolveArgKey, "resolveArgKey");
|
|
982
|
+
function resolveKey(key, name) {
|
|
983
|
+
return `${name ? `${name}${BUILT_IN_KEY_SEPARATOR}` : ""}${key}`;
|
|
984
|
+
}
|
|
985
|
+
__name(resolveKey, "resolveKey");
|
|
986
|
+
async function resolveExamples$1(ctx, examples) {
|
|
987
|
+
return typeof examples === "string" ? examples : typeof examples === "function" ? await examples(ctx) : "";
|
|
988
|
+
}
|
|
989
|
+
__name(resolveExamples$1, "resolveExamples$1");
|
|
990
|
+
function namespacedId(id) {
|
|
991
|
+
return `${PLUGIN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${id}`;
|
|
992
|
+
}
|
|
993
|
+
__name(namespacedId, "namespacedId");
|
|
994
|
+
function makeShortLongOptionPair(schema, name, toKebab) {
|
|
995
|
+
let key = `--${toKebab || schema.toKebab ? kebabnize(name) : name}`;
|
|
996
|
+
if (schema.short) key = `-${schema.short}, ${key}`;
|
|
997
|
+
return key;
|
|
998
|
+
}
|
|
999
|
+
__name(makeShortLongOptionPair, "makeShortLongOptionPair");
|
|
1000
|
+
function localizable(ctx, cmd, translate) {
|
|
1001
|
+
async function localize(key, values) {
|
|
1002
|
+
if (translate) return translate(key, values);
|
|
1003
|
+
if (key.startsWith(BUILD_IN_PREFIX_AND_KEY_SEPARATOR)) return en_US_default[key.slice(BUILD_IN_PREFIX_AND_KEY_SEPARATOR.length)] || key;
|
|
1004
|
+
const namaspacedArgKey = resolveKey(ARG_PREFIX_AND_KEY_SEPARATOR, ctx.name);
|
|
1005
|
+
if (key.startsWith(namaspacedArgKey)) {
|
|
1006
|
+
let argKey = key.slice(namaspacedArgKey.length);
|
|
1007
|
+
let negatable = false;
|
|
1008
|
+
if (argKey.startsWith(ARG_NEGATABLE_PREFIX)) {
|
|
1009
|
+
argKey = argKey.slice(ARG_NEGATABLE_PREFIX.length);
|
|
1010
|
+
negatable = true;
|
|
1011
|
+
}
|
|
1012
|
+
const schema = ctx.args[argKey];
|
|
1013
|
+
if (!schema) return argKey;
|
|
1014
|
+
return negatable && schema.type === "boolean" && schema.negatable ? `${NEGATABLE} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
|
|
1015
|
+
}
|
|
1016
|
+
if (key === resolveKey("description", ctx.name)) return "";
|
|
1017
|
+
else if (key === resolveKey("examples", ctx.name)) return await resolveExamples$1(ctx, cmd.examples);
|
|
1018
|
+
else return key;
|
|
1019
|
+
}
|
|
1020
|
+
__name(localize, "localize");
|
|
1021
|
+
return localize;
|
|
1022
|
+
}
|
|
1023
|
+
__name(localizable, "localizable");
|
|
1024
|
+
function renderHeader(ctx) {
|
|
1025
|
+
const title = ctx.env.description || ctx.env.name || "";
|
|
1026
|
+
return Promise.resolve(title ? `${title} (${ctx.env.name || ""}${ctx.env.version ? ` v${ctx.env.version}` : ""})` : title);
|
|
1027
|
+
}
|
|
1028
|
+
__name(renderHeader, "renderHeader");
|
|
1029
|
+
var pluginId = namespacedId("renderer");
|
|
1030
|
+
var COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
|
|
1031
|
+
async function renderUsage(ctx) {
|
|
1032
|
+
const messages = [];
|
|
1033
|
+
if (ctx.callMode === "subCommand") {
|
|
1034
|
+
const description = await resolveDescription(ctx);
|
|
1035
|
+
if (description) messages.push(description, "");
|
|
1036
|
+
}
|
|
1037
|
+
messages.push(...await renderUsageSection(ctx), "");
|
|
1038
|
+
if (ctx.omitted && await hasCommands(ctx)) messages.push(...await renderCommandsSection(ctx), "");
|
|
1039
|
+
if (hasPositionalArgs(ctx.args)) messages.push(...await renderPositionalArgsSection(ctx), "");
|
|
1040
|
+
if (hasOptionalArgs(ctx.args)) messages.push(...await renderOptionalArgsSection(ctx), "");
|
|
1041
|
+
const examples = await renderExamplesSection(ctx);
|
|
1042
|
+
if (examples.length > 0) messages.push(...examples, "");
|
|
1043
|
+
return messages.join("\n");
|
|
1044
|
+
}
|
|
1045
|
+
__name(renderUsage, "renderUsage");
|
|
1046
|
+
async function renderPositionalArgsSection(ctx) {
|
|
1047
|
+
const messages = [];
|
|
1048
|
+
messages.push(`${await ctx.extensions[pluginId].text(resolveBuiltInKey("ARGUMENTS"))}:`);
|
|
1049
|
+
messages.push(await generatePositionalArgsUsage(ctx));
|
|
1050
|
+
return messages;
|
|
1051
|
+
}
|
|
1052
|
+
__name(renderPositionalArgsSection, "renderPositionalArgsSection");
|
|
1053
|
+
async function renderOptionalArgsSection(ctx) {
|
|
1054
|
+
const messages = [];
|
|
1055
|
+
messages.push(`${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}:`);
|
|
1056
|
+
messages.push(await generateOptionalArgsUsage(ctx, getOptionalArgsPairs(ctx)));
|
|
1057
|
+
return messages;
|
|
1058
|
+
}
|
|
1059
|
+
__name(renderOptionalArgsSection, "renderOptionalArgsSection");
|
|
1060
|
+
async function renderExamplesSection(ctx) {
|
|
1061
|
+
const messages = [];
|
|
1062
|
+
const resolvedExamples = await resolveExamples(ctx);
|
|
1063
|
+
if (resolvedExamples) {
|
|
1064
|
+
const examples = resolvedExamples.split("\n").map((example) => example.padStart(ctx.env.leftMargin + example.length));
|
|
1065
|
+
messages.push(`${await ctx.extensions[pluginId].text(resolveBuiltInKey("EXAMPLES"))}:`, ...examples);
|
|
1066
|
+
}
|
|
1067
|
+
return messages;
|
|
1068
|
+
}
|
|
1069
|
+
__name(renderExamplesSection, "renderExamplesSection");
|
|
1070
|
+
async function renderUsageSection(ctx) {
|
|
1071
|
+
const messages = [`${await ctx.extensions[pluginId].text(resolveBuiltInKey("USAGE"))}:`];
|
|
1072
|
+
const usageStr = await makeUsageSymbols(ctx);
|
|
1073
|
+
messages.push(usageStr.padStart(ctx.env.leftMargin + usageStr.length));
|
|
1074
|
+
return messages;
|
|
1075
|
+
}
|
|
1076
|
+
__name(renderUsageSection, "renderUsageSection");
|
|
1077
|
+
async function makeUsageSymbols(ctx) {
|
|
1078
|
+
const messages = [await resolveEntry(ctx)];
|
|
1079
|
+
if (ctx.omitted) if (await hasCommands(ctx)) messages.push(` [${await ctx.extensions[pluginId].text(resolveBuiltInKey("COMMANDS"))}]`);
|
|
1080
|
+
else messages.push(`${ctx.callMode === "subCommand" ? ` ${await resolveSubCommand(ctx)}` : ""}`);
|
|
1081
|
+
else messages.push(`${ctx.callMode === "subCommand" ? ` ${await resolveSubCommand(ctx)}` : ""}`);
|
|
1082
|
+
const optionsSymbols = await generateOptionsSymbols(ctx, ctx.args);
|
|
1083
|
+
if (optionsSymbols) messages.push(" ", optionsSymbols);
|
|
1084
|
+
const positionalSymbols = generatePositionalSymbols(ctx.args);
|
|
1085
|
+
if (positionalSymbols) messages.push(" ", positionalSymbols);
|
|
1086
|
+
return messages.join("");
|
|
1087
|
+
}
|
|
1088
|
+
__name(makeUsageSymbols, "makeUsageSymbols");
|
|
1089
|
+
async function renderCommandsSection(ctx) {
|
|
1090
|
+
const messages = [`${await ctx.extensions[pluginId].text(resolveBuiltInKey("COMMANDS"))}:`];
|
|
1091
|
+
const loadedCommands = await ctx.extensions?.[pluginId].loadCommands() || [];
|
|
1092
|
+
const commandMaxLength = Math.max(...loadedCommands.map((cmd) => (cmd.name || "").length));
|
|
1093
|
+
const commandsStr = await Promise.all(loadedCommands.map(async (cmd) => {
|
|
1094
|
+
const desc = cmd.description || "";
|
|
1095
|
+
const optionSymbol = await generateOptionsSymbols(ctx, ctx.args);
|
|
1096
|
+
const positionalSymbol = generatePositionalSymbols(ctx.args);
|
|
1097
|
+
const commandStr = await makeCommandSymbol(ctx, cmd);
|
|
1098
|
+
const symbolLength = desc.length > 0 ? commandMaxLength + optionSymbol.length + positionalSymbol.length : 0;
|
|
1099
|
+
const command = `${commandStr.padEnd(symbolLength + ctx.env.middleMargin)}${desc}`;
|
|
1100
|
+
return `${command.padStart(ctx.env.leftMargin + command.length)}`;
|
|
1101
|
+
}));
|
|
1102
|
+
messages.push(...commandsStr, "", `${await ctx.extensions[pluginId].text(resolveBuiltInKey("FORMORE"))}:`);
|
|
1103
|
+
const basePath = ctx.commandPath && ctx.commandPath.length > 0 ? `${ctx.env.name} ${ctx.commandPath.join(" ")}` : ctx.env.name;
|
|
1104
|
+
messages.push(...loadedCommands.map((cmd) => {
|
|
1105
|
+
let commandStr = cmd.entry ? "" : cmd.name || "";
|
|
1106
|
+
if (commandStr) commandStr += " ";
|
|
1107
|
+
const commandHelp = `${basePath} ${commandStr}--help`;
|
|
1108
|
+
return `${commandHelp.padStart(ctx.env.leftMargin + commandHelp.length)}`;
|
|
1109
|
+
}));
|
|
1110
|
+
return messages;
|
|
1111
|
+
}
|
|
1112
|
+
__name(renderCommandsSection, "renderCommandsSection");
|
|
1113
|
+
async function makeCommandSymbol(ctx, cmd) {
|
|
1114
|
+
const optionSymbol = await generateOptionsSymbols(ctx, ctx.args);
|
|
1115
|
+
const positionalSymbol = generatePositionalSymbols(ctx.args);
|
|
1116
|
+
let commandStr = cmd.entry ? cmd.name === void 0 || cmd.name === ANONYMOUS_COMMAND_NAME ? "" : `[${cmd.name}]` : cmd.name || "";
|
|
1117
|
+
if (optionSymbol) {
|
|
1118
|
+
if (commandStr) commandStr += " ";
|
|
1119
|
+
commandStr += `${optionSymbol}`;
|
|
1120
|
+
}
|
|
1121
|
+
if (positionalSymbol) {
|
|
1122
|
+
if (commandStr) commandStr += " ";
|
|
1123
|
+
commandStr += `${positionalSymbol}`;
|
|
1124
|
+
}
|
|
1125
|
+
return commandStr;
|
|
1126
|
+
}
|
|
1127
|
+
__name(makeCommandSymbol, "makeCommandSymbol");
|
|
1128
|
+
async function resolveEntry(ctx) {
|
|
1129
|
+
return ctx.env.name || await ctx.extensions[pluginId].text(resolveBuiltInKey("COMMAND"));
|
|
1130
|
+
}
|
|
1131
|
+
__name(resolveEntry, "resolveEntry");
|
|
1132
|
+
async function resolveSubCommand(ctx) {
|
|
1133
|
+
if (ctx.commandPath && ctx.commandPath.length > 0) return ctx.commandPath.join(" ");
|
|
1134
|
+
return ctx.name || await ctx.extensions[pluginId].text(resolveBuiltInKey("SUBCOMMAND"));
|
|
1135
|
+
}
|
|
1136
|
+
__name(resolveSubCommand, "resolveSubCommand");
|
|
1137
|
+
async function resolveDescription(ctx) {
|
|
1138
|
+
return await ctx.extensions[pluginId].text(resolveKey("description", ctx.name)) || ctx.description || "";
|
|
1139
|
+
}
|
|
1140
|
+
__name(resolveDescription, "resolveDescription");
|
|
1141
|
+
async function resolveExamples(ctx) {
|
|
1142
|
+
const ret = await ctx.extensions[pluginId].text(resolveKey("examples", ctx.name));
|
|
1143
|
+
if (ret) return ret;
|
|
1144
|
+
const command = ctx.env.subCommands?.get(ctx.name || "");
|
|
1145
|
+
return await resolveExamples$1(ctx, command?.examples);
|
|
1146
|
+
}
|
|
1147
|
+
__name(resolveExamples, "resolveExamples");
|
|
1148
|
+
async function hasCommands(ctx) {
|
|
1149
|
+
return (await ctx.extensions?.[pluginId].loadCommands() || []).length > 1;
|
|
1150
|
+
}
|
|
1151
|
+
__name(hasCommands, "hasCommands");
|
|
1152
|
+
function hasOptionalArgs(args) {
|
|
1153
|
+
return Object.values(args).some((arg) => arg.type !== "positional");
|
|
1154
|
+
}
|
|
1155
|
+
__name(hasOptionalArgs, "hasOptionalArgs");
|
|
1156
|
+
function hasPositionalArgs(args) {
|
|
1157
|
+
return Object.values(args).some((arg) => arg.type === "positional");
|
|
1158
|
+
}
|
|
1159
|
+
__name(hasPositionalArgs, "hasPositionalArgs");
|
|
1160
|
+
function hasAllDefaultOptions(args) {
|
|
1161
|
+
return !!(args && Object.values(args).every((arg) => arg.default));
|
|
1162
|
+
}
|
|
1163
|
+
__name(hasAllDefaultOptions, "hasAllDefaultOptions");
|
|
1164
|
+
async function generateOptionsSymbols(ctx, args) {
|
|
1165
|
+
return hasOptionalArgs(args) ? hasAllDefaultOptions(args) ? `[${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}]` : `<${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}>` : "";
|
|
1166
|
+
}
|
|
1167
|
+
__name(generateOptionsSymbols, "generateOptionsSymbols");
|
|
1168
|
+
function getOptionalArgsPairs(ctx) {
|
|
1169
|
+
return Object.entries(ctx.args).reduce((acc, [name, schema]) => {
|
|
1170
|
+
if (schema.type === "positional") return acc;
|
|
1171
|
+
let key = makeShortLongOptionPair(schema, name, ctx.toKebab);
|
|
1172
|
+
if (schema.type !== "boolean") {
|
|
1173
|
+
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
1174
|
+
key = schema.default ? `${key} [${displayName}]` : `${key} <${displayName}>`;
|
|
1175
|
+
}
|
|
1176
|
+
acc[name] = key;
|
|
1177
|
+
if (schema.type === "boolean" && schema.negatable && !COMMON_ARGS_KEYS.includes(name)) {
|
|
1178
|
+
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
1179
|
+
acc[`${ARG_NEGATABLE_PREFIX}${name}`] = `--${ARG_NEGATABLE_PREFIX}${displayName}`;
|
|
1180
|
+
}
|
|
1181
|
+
return acc;
|
|
1182
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
1183
|
+
}
|
|
1184
|
+
__name(getOptionalArgsPairs, "getOptionalArgsPairs");
|
|
1185
|
+
var resolveNegatableKey = /* @__PURE__ */ __name((key) => key.split(ARG_NEGATABLE_PREFIX)[1], "resolveNegatableKey");
|
|
1186
|
+
function resolveNegatableType(key, ctx) {
|
|
1187
|
+
return ctx.args[key.startsWith(ARG_NEGATABLE_PREFIX) ? resolveNegatableKey(key) : key].type;
|
|
1188
|
+
}
|
|
1189
|
+
__name(resolveNegatableType, "resolveNegatableType");
|
|
1190
|
+
async function generateDefaultDisplayValue(ctx, schema) {
|
|
1191
|
+
return `${await ctx.extensions[pluginId].text(resolveBuiltInKey("DEFAULT"))}: ${schema.default}`;
|
|
1192
|
+
}
|
|
1193
|
+
__name(generateDefaultDisplayValue, "generateDefaultDisplayValue");
|
|
1194
|
+
async function resolveDisplayValue(ctx, key) {
|
|
1195
|
+
if (COMMON_ARGS_KEYS.includes(key)) return "";
|
|
1196
|
+
const schema = ctx.args[key];
|
|
1197
|
+
if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "custom") && schema.default !== void 0) return `(${await generateDefaultDisplayValue(ctx, schema)})`;
|
|
1198
|
+
if (schema.type === "enum") {
|
|
1199
|
+
const _default = schema.default === void 0 ? "" : await generateDefaultDisplayValue(ctx, schema);
|
|
1200
|
+
const choices = `${await ctx.extensions[pluginId].text(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
|
|
1201
|
+
return `(${_default ? `${_default}, ${choices}` : choices})`;
|
|
1202
|
+
}
|
|
1203
|
+
return "";
|
|
1204
|
+
}
|
|
1205
|
+
__name(resolveDisplayValue, "resolveDisplayValue");
|
|
1206
|
+
async function generateOptionalArgsUsage(ctx, optionsPairs) {
|
|
1207
|
+
const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
|
|
1208
|
+
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
|
|
1209
|
+
return (await Promise.all(Object.entries(optionsPairs).map(async ([key, value]) => {
|
|
1210
|
+
let rawDesc = await ctx.extensions[pluginId].text(resolveArgKey(key, ctx.name));
|
|
1211
|
+
if (!rawDesc && key.startsWith(ARG_NEGATABLE_PREFIX)) {
|
|
1212
|
+
const name = resolveNegatableKey(key);
|
|
1213
|
+
const schema = ctx.args[name];
|
|
1214
|
+
const optionKey = makeShortLongOptionPair(schema, name, ctx.toKebab);
|
|
1215
|
+
rawDesc = `${await ctx.extensions[pluginId].text(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
|
|
1216
|
+
}
|
|
1217
|
+
const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
|
|
1218
|
+
const valueDesc = key.startsWith(ARG_NEGATABLE_PREFIX) ? "" : await resolveDisplayValue(ctx, key);
|
|
1219
|
+
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
|
|
1220
|
+
const descLength = desc.length + valueDesc.length;
|
|
1221
|
+
const option = `${value.padEnd((descLength > 0 ? optionsMaxLength : 0) + ctx.env.middleMargin)}${desc}${valueDesc ? ` ${valueDesc}` : ""}`;
|
|
1222
|
+
return `${option.padStart(ctx.env.leftMargin + option.length)}`;
|
|
1223
|
+
}))).join("\n");
|
|
1224
|
+
}
|
|
1225
|
+
__name(generateOptionalArgsUsage, "generateOptionalArgsUsage");
|
|
1226
|
+
function getPositionalArgs(args) {
|
|
1227
|
+
return Object.entries(args).filter(([_, schema]) => schema.type === "positional");
|
|
1228
|
+
}
|
|
1229
|
+
__name(getPositionalArgs, "getPositionalArgs");
|
|
1230
|
+
async function generatePositionalArgsUsage(ctx) {
|
|
1231
|
+
const positionals = getPositionalArgs(ctx.args);
|
|
1232
|
+
const argsMaxLength = Math.max(...positionals.map(([name]) => name.length));
|
|
1233
|
+
return (await Promise.all(positionals.map(async ([name]) => {
|
|
1234
|
+
const desc = await ctx.extensions[pluginId].text(resolveArgKey(name, ctx.name)) || ctx.args[name].description || "";
|
|
1235
|
+
const arg = `${name.padEnd(argsMaxLength + ctx.env.middleMargin)} ${desc}`;
|
|
1236
|
+
return `${arg.padStart(ctx.env.leftMargin + arg.length)}`;
|
|
1237
|
+
}))).join("\n");
|
|
1238
|
+
}
|
|
1239
|
+
__name(generatePositionalArgsUsage, "generatePositionalArgsUsage");
|
|
1240
|
+
function generatePositionalSymbols(args) {
|
|
1241
|
+
return hasPositionalArgs(args) ? getPositionalArgs(args).map(([name, arg]) => {
|
|
1242
|
+
const elements = [];
|
|
1243
|
+
if (!arg.multiple || arg.required) elements.push(`<${name}>`);
|
|
1244
|
+
if (arg.multiple) elements.push(`[<${name}> ...]`);
|
|
1245
|
+
return elements.join(" ");
|
|
1246
|
+
}).join(" ") : "";
|
|
1247
|
+
}
|
|
1248
|
+
__name(generatePositionalSymbols, "generatePositionalSymbols");
|
|
1249
|
+
function renderValidationErrors(_ctx, error) {
|
|
1250
|
+
const messages = [];
|
|
1251
|
+
for (const err of error.errors) messages.push(err.message);
|
|
1252
|
+
return Promise.resolve(messages.join("\n"));
|
|
1253
|
+
}
|
|
1254
|
+
__name(renderValidationErrors, "renderValidationErrors");
|
|
1255
|
+
var i18nPluginId = namespacedId("i18n");
|
|
1256
|
+
var dependencies = [{
|
|
1257
|
+
id: i18nPluginId,
|
|
1258
|
+
optional: true
|
|
1259
|
+
}];
|
|
1260
|
+
function renderer() {
|
|
1261
|
+
return plugin({
|
|
1262
|
+
id: pluginId,
|
|
1263
|
+
name: "usage renderer",
|
|
1264
|
+
dependencies,
|
|
1265
|
+
extension: /* @__PURE__ */ __name((ctx, cmd) => {
|
|
1266
|
+
const i18n = ctx.extensions[i18nPluginId];
|
|
1267
|
+
let cachedCommands;
|
|
1268
|
+
async function loadCommands() {
|
|
1269
|
+
if (cachedCommands) return cachedCommands;
|
|
1270
|
+
const subCommands = [...ctx.env.subCommands || []];
|
|
1271
|
+
cachedCommands = (await Promise.all(subCommands.map(async ([name, cmd2]) => await resolveLazyCommand(cmd2, name)))).filter((cmd2) => !cmd2.internal).filter(Boolean);
|
|
1272
|
+
cachedCommands.sort((a, b) => {
|
|
1273
|
+
if (a.entry && !b.entry) return -1;
|
|
1274
|
+
if (!a.entry && b.entry) return 1;
|
|
1275
|
+
if (a.name && b.name) return a.name.localeCompare(b.name);
|
|
1276
|
+
if (a.name && !b.name) return -1;
|
|
1277
|
+
if (!a.name && b.name) return 1;
|
|
1278
|
+
return 0;
|
|
1279
|
+
});
|
|
1280
|
+
return cachedCommands;
|
|
1281
|
+
}
|
|
1282
|
+
__name(loadCommands, "loadCommands");
|
|
1283
|
+
return {
|
|
1284
|
+
text: localizable(ctx, cmd, i18n?.translate),
|
|
1285
|
+
loadCommands
|
|
1286
|
+
};
|
|
1287
|
+
}, "extension"),
|
|
1288
|
+
setup: /* @__PURE__ */ __name((ctx) => {
|
|
1289
|
+
ctx.decorateHeaderRenderer(async (_baseRenderer, cmdCtx) => await renderHeader(cmdCtx));
|
|
1290
|
+
ctx.decorateUsageRenderer(async (_baseRenderer, cmdCtx) => await renderUsage(cmdCtx));
|
|
1291
|
+
ctx.decorateValidationErrorsRenderer(async (_baseRenderer, cmdCtx, error) => await renderValidationErrors(cmdCtx, error));
|
|
1292
|
+
}, "setup")
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
__name(renderer, "renderer");
|
|
1296
|
+
|
|
1297
|
+
// ../../node_modules/.pnpm/gunshi@0.28.0/node_modules/gunshi/lib/cli-l4AYjN-O.js
|
|
1298
|
+
var pluginId2 = namespacedId("global");
|
|
1299
|
+
var decorator = /* @__PURE__ */ __name((baseRunner) => async (ctx) => {
|
|
1300
|
+
const { values, validationError, extensions: { [pluginId2]: { showVersion, showHeader, showUsage, showValidationErrors } } } = ctx;
|
|
1301
|
+
if (values.version) return showVersion();
|
|
1302
|
+
const buf = [];
|
|
1303
|
+
const header = await showHeader();
|
|
1304
|
+
if (header) buf.push(header);
|
|
1305
|
+
if (values.help) {
|
|
1306
|
+
const usage = await showUsage();
|
|
1307
|
+
if (usage) {
|
|
1308
|
+
buf.push(usage);
|
|
1309
|
+
return buf.join("\n");
|
|
1310
|
+
}
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
if (validationError) return await showValidationErrors(validationError);
|
|
1314
|
+
return baseRunner(ctx);
|
|
1315
|
+
}, "decorator");
|
|
1316
|
+
var decorator_default = decorator;
|
|
1317
|
+
function extension(ctx) {
|
|
1318
|
+
return {
|
|
1319
|
+
showVersion: /* @__PURE__ */ __name(() => {
|
|
1320
|
+
const version = ctx.env.version || "unknown";
|
|
1321
|
+
if (!ctx.env.usageSilent) ctx.log(version);
|
|
1322
|
+
return version;
|
|
1323
|
+
}, "showVersion"),
|
|
1324
|
+
showHeader: /* @__PURE__ */ __name(async () => {
|
|
1325
|
+
let header;
|
|
1326
|
+
if (ctx.env.renderHeader != null) {
|
|
1327
|
+
header = await ctx.env.renderHeader(ctx);
|
|
1328
|
+
if (header) {
|
|
1329
|
+
ctx.log(header);
|
|
1330
|
+
ctx.log();
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
return header;
|
|
1334
|
+
}, "showHeader"),
|
|
1335
|
+
showUsage: /* @__PURE__ */ __name(async () => {
|
|
1336
|
+
if (ctx.env.renderUsage != null) {
|
|
1337
|
+
const usage = await ctx.env.renderUsage(ctx);
|
|
1338
|
+
if (usage) {
|
|
1339
|
+
ctx.log(usage);
|
|
1340
|
+
return usage;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}, "showUsage"),
|
|
1344
|
+
showValidationErrors: /* @__PURE__ */ __name(async (error) => {
|
|
1345
|
+
if (ctx.env.renderValidationErrors === null) return;
|
|
1346
|
+
if (ctx.env.renderValidationErrors !== void 0) {
|
|
1347
|
+
const message = await ctx.env.renderValidationErrors(ctx, error);
|
|
1348
|
+
ctx.log(message);
|
|
1349
|
+
return message;
|
|
1350
|
+
}
|
|
1351
|
+
}, "showValidationErrors")
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
__name(extension, "extension");
|
|
1355
|
+
function global() {
|
|
1356
|
+
return plugin({
|
|
1357
|
+
id: pluginId2,
|
|
1358
|
+
name: "global options",
|
|
1359
|
+
extension,
|
|
1360
|
+
setup(ctx) {
|
|
1361
|
+
for (const [name, schema] of Object.entries(COMMON_ARGS)) ctx.addGlobalOption(name, schema);
|
|
1362
|
+
ctx.decorateCommand(decorator_default);
|
|
1363
|
+
}
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
__name(global, "global");
|
|
1367
|
+
async function cli(args, entry, options = {}) {
|
|
1368
|
+
return cliCore(args, entry, options, [global(), renderer()]);
|
|
1369
|
+
}
|
|
1370
|
+
__name(cli, "cli");
|
|
1371
|
+
/*! Bundled license information:
|
|
1372
|
+
|
|
1373
|
+
gunshi/lib/utils-DNS9AIR_.js:
|
|
1374
|
+
gunshi/lib/context-CHDIbgwd.js:
|
|
1375
|
+
gunshi/lib/core-C9P_Gd_f.js:
|
|
1376
|
+
gunshi/lib/src-CfO5ab2f.js:
|
|
1377
|
+
gunshi/lib/cli-l4AYjN-O.js:
|
|
1378
|
+
(**
|
|
1379
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
1380
|
+
* @license MIT
|
|
1381
|
+
*)
|
|
1382
|
+
*/
|
|
1383
|
+
|
|
1384
|
+
export { cli, define };
|
|
1385
|
+
//# sourceMappingURL=chunk-UDXNNRWI.js.map
|
|
1386
|
+
//# sourceMappingURL=chunk-UDXNNRWI.js.map
|