varlock 0.0.0 → 0.0.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 +46 -0
- package/bin/cli.js +2 -0
- package/dist/auto-load.d.ts +2 -0
- package/dist/auto-load.js +11 -0
- package/dist/auto-load.js.map +1 -0
- package/dist/chunk-332HXE6L.js +53 -0
- package/dist/chunk-332HXE6L.js.map +1 -0
- package/dist/chunk-33ROL4J5.js +1013 -0
- package/dist/chunk-33ROL4J5.js.map +1 -0
- package/dist/chunk-4WO4BGKU.js +70 -0
- package/dist/chunk-4WO4BGKU.js.map +1 -0
- package/dist/chunk-6YLXKXKR.js +225 -0
- package/dist/chunk-6YLXKXKR.js.map +1 -0
- package/dist/chunk-7UQXFWKN.js +82 -0
- package/dist/chunk-7UQXFWKN.js.map +1 -0
- package/dist/chunk-B4UBSMSZ.js +142 -0
- package/dist/chunk-B4UBSMSZ.js.map +1 -0
- package/dist/chunk-CPA2D42B.js +146 -0
- package/dist/chunk-CPA2D42B.js.map +1 -0
- package/dist/chunk-DAZNZPLN.js +675 -0
- package/dist/chunk-DAZNZPLN.js.map +1 -0
- package/dist/chunk-G4BD2BPH.js +2310 -0
- package/dist/chunk-G4BD2BPH.js.map +1 -0
- package/dist/chunk-LQZ6ICSS.js +21 -0
- package/dist/chunk-LQZ6ICSS.js.map +1 -0
- package/dist/chunk-O2QPQ5MG.js +98 -0
- package/dist/chunk-O2QPQ5MG.js.map +1 -0
- package/dist/chunk-QCC3P7BT.js +39 -0
- package/dist/chunk-QCC3P7BT.js.map +1 -0
- package/dist/chunk-RCHPHIHX.js +15 -0
- package/dist/chunk-RCHPHIHX.js.map +1 -0
- package/dist/chunk-RY3YIJFG.js +681 -0
- package/dist/chunk-RY3YIJFG.js.map +1 -0
- package/dist/chunk-XCFZJA7V.js +32 -0
- package/dist/chunk-XCFZJA7V.js.map +1 -0
- package/dist/chunk-XN24GZXQ.js +35 -0
- package/dist/chunk-XN24GZXQ.js.map +1 -0
- package/dist/chunk-Z55UMN2B.js +69 -0
- package/dist/chunk-Z55UMN2B.js.map +1 -0
- package/dist/cli/cli-executable.d.ts +2 -0
- package/dist/cli/cli-executable.js +205 -0
- package/dist/cli/cli-executable.js.map +1 -0
- package/dist/doctor.command-SHZI7SR3.js +6 -0
- package/dist/doctor.command-SHZI7SR3.js.map +1 -0
- package/dist/dotenv-compat.d.ts +2 -0
- package/dist/dotenv-compat.js +11 -0
- package/dist/dotenv-compat.js.map +1 -0
- package/dist/en-US-TSGNDI2P.js +22 -0
- package/dist/en-US-TSGNDI2P.js.map +1 -0
- package/dist/encrypt.command-VGJABHNK.js +6 -0
- package/dist/encrypt.command-VGJABHNK.js.map +1 -0
- package/dist/help.command-YZDL2VEQ.js +5 -0
- package/dist/help.command-YZDL2VEQ.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/init.command-ERPGU436.js +10 -0
- package/dist/init.command-ERPGU436.js.map +1 -0
- package/dist/ja-JP-UBPCQAAD.js +22 -0
- package/dist/ja-JP-UBPCQAAD.js.map +1 -0
- package/dist/load.command-LQDSWJSK.js +9 -0
- package/dist/load.command-LQDSWJSK.js.map +1 -0
- package/dist/login.command-22RUZJLR.js +7 -0
- package/dist/login.command-22RUZJLR.js.map +1 -0
- package/dist/opt-out.command-Y4KUQ6PQ.js +5 -0
- package/dist/opt-out.command-Y4KUQ6PQ.js.map +1 -0
- package/dist/run.command-OF3UV7AD.js +9 -0
- package/dist/run.command-OF3UV7AD.js.map +1 -0
- package/package.json +50 -3
- package/notes.md +0 -3
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
import { __name, __glob } from './chunk-XN24GZXQ.js';
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/gunshi@0.26.3/node_modules/gunshi/lib/definition-wq1Kmbvq.js
|
|
4
|
+
function define(definition) {
|
|
5
|
+
return definition;
|
|
6
|
+
}
|
|
7
|
+
__name(define, "define");
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/gunshi@0.26.3/node_modules/gunshi/lib/utils-D41C8Abf.js
|
|
10
|
+
var DEFAULT_LOCALE = "en-US";
|
|
11
|
+
var BUILT_IN_PREFIX = "_";
|
|
12
|
+
var ARG_PREFIX = "arg";
|
|
13
|
+
var BUILT_IN_KEY_SEPARATOR = ":";
|
|
14
|
+
var ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
15
|
+
var NOOP = /* @__PURE__ */ __name(() => {
|
|
16
|
+
}, "NOOP");
|
|
17
|
+
var COMMON_ARGS = {
|
|
18
|
+
help: {
|
|
19
|
+
type: "boolean",
|
|
20
|
+
short: "h",
|
|
21
|
+
description: "Display this help message"
|
|
22
|
+
},
|
|
23
|
+
version: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
short: "v",
|
|
26
|
+
description: "Display this version"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var COMMAND_OPTIONS_DEFAULT = {
|
|
30
|
+
name: void 0,
|
|
31
|
+
description: void 0,
|
|
32
|
+
version: void 0,
|
|
33
|
+
cwd: void 0,
|
|
34
|
+
usageSilent: false,
|
|
35
|
+
subCommands: void 0,
|
|
36
|
+
leftMargin: 2,
|
|
37
|
+
middleMargin: 10,
|
|
38
|
+
usageOptionType: false,
|
|
39
|
+
usageOptionValue: true,
|
|
40
|
+
renderHeader: void 0,
|
|
41
|
+
renderUsage: void 0,
|
|
42
|
+
renderValidationErrors: void 0,
|
|
43
|
+
translationAdapterFactory: void 0
|
|
44
|
+
};
|
|
45
|
+
function isLazyCommand(cmd) {
|
|
46
|
+
return typeof cmd === "function" && "commandName" in cmd && !!cmd.commandName;
|
|
47
|
+
}
|
|
48
|
+
__name(isLazyCommand, "isLazyCommand");
|
|
49
|
+
async function resolveLazyCommand(cmd, name, needRunResolving = false) {
|
|
50
|
+
let command;
|
|
51
|
+
if (isLazyCommand(cmd)) {
|
|
52
|
+
command = Object.assign(create(), {
|
|
53
|
+
name: cmd.commandName,
|
|
54
|
+
description: cmd.description,
|
|
55
|
+
args: cmd.args,
|
|
56
|
+
examples: cmd.examples,
|
|
57
|
+
resource: cmd.resource
|
|
58
|
+
});
|
|
59
|
+
if (needRunResolving) {
|
|
60
|
+
const loaded = await cmd();
|
|
61
|
+
if (typeof loaded === "function") command.run = loaded;
|
|
62
|
+
else if (typeof loaded === "object") {
|
|
63
|
+
if (loaded.run == null) throw new TypeError(`'run' is required in command: ${cmd.name || name}`);
|
|
64
|
+
command.run = loaded.run;
|
|
65
|
+
command.name = loaded.name;
|
|
66
|
+
command.description = loaded.description;
|
|
67
|
+
command.args = loaded.args;
|
|
68
|
+
command.examples = loaded.examples;
|
|
69
|
+
command.resource = loaded.resource;
|
|
70
|
+
} else throw new TypeError(`Cannot resolve command: ${cmd.name || name}`);
|
|
71
|
+
}
|
|
72
|
+
} else command = Object.assign(create(), cmd);
|
|
73
|
+
if (command.name == null && name) command.name = name;
|
|
74
|
+
return deepFreeze(command);
|
|
75
|
+
}
|
|
76
|
+
__name(resolveLazyCommand, "resolveLazyCommand");
|
|
77
|
+
function resolveBuiltInKey(key) {
|
|
78
|
+
return `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
79
|
+
}
|
|
80
|
+
__name(resolveBuiltInKey, "resolveBuiltInKey");
|
|
81
|
+
function resolveArgKey(key) {
|
|
82
|
+
return `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
83
|
+
}
|
|
84
|
+
__name(resolveArgKey, "resolveArgKey");
|
|
85
|
+
async function resolveExamples(ctx, examples) {
|
|
86
|
+
return typeof examples === "string" ? examples : typeof examples === "function" ? await examples(ctx) : "";
|
|
87
|
+
}
|
|
88
|
+
__name(resolveExamples, "resolveExamples");
|
|
89
|
+
function mapResourceWithBuiltinKey(resource) {
|
|
90
|
+
return Object.entries(resource).reduce((acc, [key, value]) => {
|
|
91
|
+
acc[resolveBuiltInKey(key)] = value;
|
|
92
|
+
return acc;
|
|
93
|
+
}, create());
|
|
94
|
+
}
|
|
95
|
+
__name(mapResourceWithBuiltinKey, "mapResourceWithBuiltinKey");
|
|
96
|
+
function create(obj = null) {
|
|
97
|
+
return Object.create(obj);
|
|
98
|
+
}
|
|
99
|
+
__name(create, "create");
|
|
100
|
+
function log(...args) {
|
|
101
|
+
console.log(...args);
|
|
102
|
+
}
|
|
103
|
+
__name(log, "log");
|
|
104
|
+
function deepFreeze(obj) {
|
|
105
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
106
|
+
for (const key of Object.keys(obj)) {
|
|
107
|
+
const value = obj[key];
|
|
108
|
+
if (typeof value === "object" && value !== null) deepFreeze(value);
|
|
109
|
+
}
|
|
110
|
+
return Object.freeze(obj);
|
|
111
|
+
}
|
|
112
|
+
__name(deepFreeze, "deepFreeze");
|
|
113
|
+
|
|
114
|
+
// import("./locales/**/*.json") in ../../node_modules/.pnpm/gunshi@0.26.3/node_modules/gunshi/lib/context-D_EmfRNA.js
|
|
115
|
+
var globImport_locales_json = __glob({
|
|
116
|
+
"./locales/en-US.json": () => import('./en-US-TSGNDI2P.js'),
|
|
117
|
+
"./locales/ja-JP.json": () => import('./ja-JP-UBPCQAAD.js')
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// ../../node_modules/.pnpm/gunshi@0.26.3/node_modules/gunshi/lib/context-D_EmfRNA.js
|
|
121
|
+
var COMMAND = "COMMAND";
|
|
122
|
+
var COMMANDS = "COMMANDS";
|
|
123
|
+
var SUBCOMMAND = "SUBCOMMAND";
|
|
124
|
+
var USAGE = "USAGE";
|
|
125
|
+
var ARGUMENTS = "ARGUMENTS";
|
|
126
|
+
var OPTIONS = "OPTIONS";
|
|
127
|
+
var EXAMPLES = "EXAMPLES";
|
|
128
|
+
var FORMORE = "For more info, run any command with the `--help` flag:";
|
|
129
|
+
var NEGATABLE = "Negatable of";
|
|
130
|
+
var DEFAULT = "default";
|
|
131
|
+
var CHOICES = "choices";
|
|
132
|
+
var help = "Display this help message";
|
|
133
|
+
var version = "Display this version";
|
|
134
|
+
var en_US_default = {
|
|
135
|
+
COMMAND,
|
|
136
|
+
COMMANDS,
|
|
137
|
+
SUBCOMMAND,
|
|
138
|
+
USAGE,
|
|
139
|
+
ARGUMENTS,
|
|
140
|
+
OPTIONS,
|
|
141
|
+
EXAMPLES,
|
|
142
|
+
FORMORE,
|
|
143
|
+
NEGATABLE,
|
|
144
|
+
DEFAULT,
|
|
145
|
+
CHOICES,
|
|
146
|
+
help,
|
|
147
|
+
version
|
|
148
|
+
};
|
|
149
|
+
function createTranslationAdapter(options) {
|
|
150
|
+
return new DefaultTranslation(options);
|
|
151
|
+
}
|
|
152
|
+
__name(createTranslationAdapter, "createTranslationAdapter");
|
|
153
|
+
var DefaultTranslation = class {
|
|
154
|
+
static {
|
|
155
|
+
__name(this, "DefaultTranslation");
|
|
156
|
+
}
|
|
157
|
+
#resources = /* @__PURE__ */ new Map();
|
|
158
|
+
#options;
|
|
159
|
+
constructor(options) {
|
|
160
|
+
this.#options = options;
|
|
161
|
+
this.#resources.set(options.locale, create());
|
|
162
|
+
if (options.locale !== options.fallbackLocale) this.#resources.set(options.fallbackLocale, create());
|
|
163
|
+
}
|
|
164
|
+
getResource(locale) {
|
|
165
|
+
return this.#resources.get(locale);
|
|
166
|
+
}
|
|
167
|
+
setResource(locale, resource) {
|
|
168
|
+
this.#resources.set(locale, resource);
|
|
169
|
+
}
|
|
170
|
+
getMessage(locale, key) {
|
|
171
|
+
const resource = this.getResource(locale);
|
|
172
|
+
if (resource) return resource[key];
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
translate(locale, key, values = create()) {
|
|
176
|
+
let message = this.getMessage(locale, key);
|
|
177
|
+
if (message === void 0 && locale !== this.#options.fallbackLocale) message = this.getMessage(this.#options.fallbackLocale, key);
|
|
178
|
+
if (message === void 0) return;
|
|
179
|
+
return message.replaceAll(/\{\{(\w+)\}\}/g, (_, name) => {
|
|
180
|
+
return values[name] == null ? "" : values[name].toString();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
|
|
185
|
+
async function createCommandContext({ args, values, positionals, rest, argv, tokens, command, cliOptions, callMode = "entry", omitted = false }) {
|
|
186
|
+
const _args = Object.entries(args).reduce((acc, [key, value]) => {
|
|
187
|
+
acc[key] = Object.assign(create(), value);
|
|
188
|
+
return acc;
|
|
189
|
+
}, create());
|
|
190
|
+
const env = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, cliOptions);
|
|
191
|
+
const locale = resolveLocale(cliOptions.locale);
|
|
192
|
+
const localeStr = locale.toString();
|
|
193
|
+
const translationAdapterFactory = cliOptions.translationAdapterFactory || createTranslationAdapter;
|
|
194
|
+
const adapter = translationAdapterFactory({
|
|
195
|
+
locale: localeStr,
|
|
196
|
+
fallbackLocale: DEFAULT_LOCALE
|
|
197
|
+
});
|
|
198
|
+
const localeResources = /* @__PURE__ */ new Map();
|
|
199
|
+
let builtInLoadedResources;
|
|
200
|
+
localeResources.set(DEFAULT_LOCALE, mapResourceWithBuiltinKey(en_US_default));
|
|
201
|
+
if (DEFAULT_LOCALE !== localeStr) try {
|
|
202
|
+
builtInLoadedResources = (await globImport_locales_json(`./locales/${localeStr}.json`)).default;
|
|
203
|
+
localeResources.set(localeStr, mapResourceWithBuiltinKey(builtInLoadedResources));
|
|
204
|
+
} catch {
|
|
205
|
+
}
|
|
206
|
+
function translate(key, values$1 = create()) {
|
|
207
|
+
const strKey = key;
|
|
208
|
+
if (strKey.codePointAt(0) === BUILT_IN_PREFIX_CODE) {
|
|
209
|
+
const resource = localeResources.get(localeStr) || localeResources.get(DEFAULT_LOCALE);
|
|
210
|
+
return resource[strKey] || strKey;
|
|
211
|
+
} else return adapter.translate(locale.toString(), strKey, values$1) || "";
|
|
212
|
+
}
|
|
213
|
+
__name(translate, "translate");
|
|
214
|
+
let cachedCommands;
|
|
215
|
+
async function loadCommands() {
|
|
216
|
+
if (cachedCommands) return cachedCommands;
|
|
217
|
+
const subCommands = [...cliOptions.subCommands || []];
|
|
218
|
+
return cachedCommands = await Promise.all(subCommands.map(async ([name, cmd]) => await resolveLazyCommand(cmd, name)));
|
|
219
|
+
}
|
|
220
|
+
__name(loadCommands, "loadCommands");
|
|
221
|
+
const ctx = deepFreeze(Object.assign(create(), {
|
|
222
|
+
name: getCommandName(command),
|
|
223
|
+
description: command.description,
|
|
224
|
+
omitted,
|
|
225
|
+
callMode,
|
|
226
|
+
locale,
|
|
227
|
+
env,
|
|
228
|
+
args: _args,
|
|
229
|
+
values,
|
|
230
|
+
positionals,
|
|
231
|
+
rest,
|
|
232
|
+
_: argv,
|
|
233
|
+
tokens,
|
|
234
|
+
toKebab: command.toKebab,
|
|
235
|
+
log: cliOptions.usageSilent ? NOOP : log,
|
|
236
|
+
loadCommands,
|
|
237
|
+
translate
|
|
238
|
+
}));
|
|
239
|
+
const loadedOptionsResources = Object.entries(args).map(([key, arg]) => {
|
|
240
|
+
const description = arg.description || "";
|
|
241
|
+
return [key, description];
|
|
242
|
+
});
|
|
243
|
+
const defaultCommandResource = loadedOptionsResources.reduce((res, [key, value]) => {
|
|
244
|
+
res[resolveArgKey(key)] = value;
|
|
245
|
+
return res;
|
|
246
|
+
}, create());
|
|
247
|
+
defaultCommandResource.description = command.description || "";
|
|
248
|
+
defaultCommandResource.examples = await resolveExamples(ctx, command.examples);
|
|
249
|
+
adapter.setResource(DEFAULT_LOCALE, defaultCommandResource);
|
|
250
|
+
const originalResource = await loadCommandResource(ctx, command);
|
|
251
|
+
if (originalResource) {
|
|
252
|
+
const resource = Object.assign(create(), originalResource, { examples: await resolveExamples(ctx, originalResource.examples) });
|
|
253
|
+
if (builtInLoadedResources) {
|
|
254
|
+
resource.help = builtInLoadedResources.help;
|
|
255
|
+
resource.version = builtInLoadedResources.version;
|
|
256
|
+
}
|
|
257
|
+
adapter.setResource(localeStr, resource);
|
|
258
|
+
}
|
|
259
|
+
return ctx;
|
|
260
|
+
}
|
|
261
|
+
__name(createCommandContext, "createCommandContext");
|
|
262
|
+
function getCommandName(cmd) {
|
|
263
|
+
if (isLazyCommand(cmd)) return cmd.commandName || cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
264
|
+
else if (typeof cmd === "object") return cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
265
|
+
else return ANONYMOUS_COMMAND_NAME;
|
|
266
|
+
}
|
|
267
|
+
__name(getCommandName, "getCommandName");
|
|
268
|
+
function resolveLocale(locale) {
|
|
269
|
+
return locale instanceof Intl.Locale ? locale : typeof locale === "string" ? new Intl.Locale(locale) : new Intl.Locale(DEFAULT_LOCALE);
|
|
270
|
+
}
|
|
271
|
+
__name(resolveLocale, "resolveLocale");
|
|
272
|
+
async function loadCommandResource(ctx, command) {
|
|
273
|
+
let resource;
|
|
274
|
+
try {
|
|
275
|
+
resource = await command.resource?.(ctx);
|
|
276
|
+
} catch {
|
|
277
|
+
}
|
|
278
|
+
return resource;
|
|
279
|
+
}
|
|
280
|
+
__name(loadCommandResource, "loadCommandResource");
|
|
281
|
+
|
|
282
|
+
// ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/utils-N7UlhLbz.js
|
|
283
|
+
function kebabnize(str) {
|
|
284
|
+
return str.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
285
|
+
}
|
|
286
|
+
__name(kebabnize, "kebabnize");
|
|
287
|
+
|
|
288
|
+
// ../../node_modules/.pnpm/gunshi@0.26.3/node_modules/gunshi/lib/renderer-BzRfaLdJ.js
|
|
289
|
+
function renderHeader(ctx) {
|
|
290
|
+
const title = ctx.env.description || ctx.env.name || "";
|
|
291
|
+
return Promise.resolve(title ? `${title} (${ctx.env.name || ""}${ctx.env.version ? ` v${ctx.env.version}` : ""})` : title);
|
|
292
|
+
}
|
|
293
|
+
__name(renderHeader, "renderHeader");
|
|
294
|
+
var COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
|
|
295
|
+
async function renderUsage(ctx) {
|
|
296
|
+
const messages = [];
|
|
297
|
+
if (!ctx.omitted) {
|
|
298
|
+
const description = resolveDescription(ctx);
|
|
299
|
+
if (description) messages.push(description, "");
|
|
300
|
+
}
|
|
301
|
+
messages.push(...await renderUsageSection(ctx), "");
|
|
302
|
+
if (ctx.omitted && await hasCommands(ctx)) messages.push(...await renderCommandsSection(ctx), "");
|
|
303
|
+
if (hasPositionalArgs(ctx)) messages.push(...await renderPositionalArgsSection(ctx), "");
|
|
304
|
+
if (hasOptionalArgs(ctx)) messages.push(...await renderOptionalArgsSection(ctx), "");
|
|
305
|
+
const examples = await renderExamplesSection(ctx);
|
|
306
|
+
if (examples.length > 0) messages.push(...examples, "");
|
|
307
|
+
return messages.join("\n");
|
|
308
|
+
}
|
|
309
|
+
__name(renderUsage, "renderUsage");
|
|
310
|
+
async function renderPositionalArgsSection(ctx) {
|
|
311
|
+
const messages = [];
|
|
312
|
+
messages.push(`${ctx.translate(resolveBuiltInKey("ARGUMENTS"))}:`);
|
|
313
|
+
messages.push(await generatePositionalArgsUsage(ctx));
|
|
314
|
+
return messages;
|
|
315
|
+
}
|
|
316
|
+
__name(renderPositionalArgsSection, "renderPositionalArgsSection");
|
|
317
|
+
async function renderOptionalArgsSection(ctx) {
|
|
318
|
+
const messages = [];
|
|
319
|
+
messages.push(`${ctx.translate(resolveBuiltInKey("OPTIONS"))}:`);
|
|
320
|
+
messages.push(await generateOptionalArgsUsage(ctx, getOptionalArgsPairs(ctx)));
|
|
321
|
+
return messages;
|
|
322
|
+
}
|
|
323
|
+
__name(renderOptionalArgsSection, "renderOptionalArgsSection");
|
|
324
|
+
async function renderExamplesSection(ctx) {
|
|
325
|
+
const messages = [];
|
|
326
|
+
const resolvedExamples = await resolveExamples$1(ctx);
|
|
327
|
+
if (resolvedExamples) {
|
|
328
|
+
const examples = resolvedExamples.split("\n").map((example) => example.padStart(ctx.env.leftMargin + example.length));
|
|
329
|
+
messages.push(`${ctx.translate(resolveBuiltInKey("EXAMPLES"))}:`, ...examples);
|
|
330
|
+
}
|
|
331
|
+
return messages;
|
|
332
|
+
}
|
|
333
|
+
__name(renderExamplesSection, "renderExamplesSection");
|
|
334
|
+
async function renderUsageSection(ctx) {
|
|
335
|
+
const messages = [`${ctx.translate(resolveBuiltInKey("USAGE"))}:`];
|
|
336
|
+
if (ctx.omitted) {
|
|
337
|
+
const defaultCommand = `${resolveEntry(ctx)}${await hasCommands(ctx) ? ` [${resolveSubCommand(ctx)}]` : ""} ${[generateOptionsSymbols(ctx), generatePositionalSymbols(ctx)].filter(Boolean).join(" ")}`;
|
|
338
|
+
messages.push(defaultCommand.padStart(ctx.env.leftMargin + defaultCommand.length));
|
|
339
|
+
if (await hasCommands(ctx)) {
|
|
340
|
+
const commandsUsage = `${resolveEntry(ctx)} <${ctx.translate(resolveBuiltInKey("COMMANDS"))}>`;
|
|
341
|
+
messages.push(commandsUsage.padStart(ctx.env.leftMargin + commandsUsage.length));
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
const usageStr = `${resolveEntry(ctx)} ${resolveSubCommand(ctx)} ${[generateOptionsSymbols(ctx), generatePositionalSymbols(ctx)].filter(Boolean).join(" ")}`;
|
|
345
|
+
messages.push(usageStr.padStart(ctx.env.leftMargin + usageStr.length));
|
|
346
|
+
}
|
|
347
|
+
return messages;
|
|
348
|
+
}
|
|
349
|
+
__name(renderUsageSection, "renderUsageSection");
|
|
350
|
+
async function renderCommandsSection(ctx) {
|
|
351
|
+
const messages = [`${ctx.translate(resolveBuiltInKey("COMMANDS"))}:`];
|
|
352
|
+
const loadedCommands = await ctx.loadCommands();
|
|
353
|
+
const commandMaxLength = Math.max(...loadedCommands.map((cmd) => (cmd.name || "").length));
|
|
354
|
+
const commandsStr = await Promise.all(loadedCommands.map((cmd) => {
|
|
355
|
+
const key = cmd.name || "";
|
|
356
|
+
const desc = cmd.description || "";
|
|
357
|
+
const command = `${key.padEnd(commandMaxLength + ctx.env.middleMargin)}${desc} `;
|
|
358
|
+
return `${command.padStart(ctx.env.leftMargin + command.length)} `;
|
|
359
|
+
}));
|
|
360
|
+
messages.push(...commandsStr, "", ctx.translate(resolveBuiltInKey("FORMORE")));
|
|
361
|
+
messages.push(...loadedCommands.map((cmd) => {
|
|
362
|
+
const commandHelp = `${ctx.env.name} ${cmd.name} --help`;
|
|
363
|
+
return `${commandHelp.padStart(ctx.env.leftMargin + commandHelp.length)}`;
|
|
364
|
+
}));
|
|
365
|
+
return messages;
|
|
366
|
+
}
|
|
367
|
+
__name(renderCommandsSection, "renderCommandsSection");
|
|
368
|
+
function resolveEntry(ctx) {
|
|
369
|
+
return ctx.env.name || ctx.translate(resolveBuiltInKey("COMMAND"));
|
|
370
|
+
}
|
|
371
|
+
__name(resolveEntry, "resolveEntry");
|
|
372
|
+
function resolveSubCommand(ctx) {
|
|
373
|
+
return ctx.name || ctx.translate(resolveBuiltInKey("SUBCOMMAND"));
|
|
374
|
+
}
|
|
375
|
+
__name(resolveSubCommand, "resolveSubCommand");
|
|
376
|
+
function resolveDescription(ctx) {
|
|
377
|
+
return ctx.translate("description") || ctx.description || "";
|
|
378
|
+
}
|
|
379
|
+
__name(resolveDescription, "resolveDescription");
|
|
380
|
+
async function resolveExamples$1(ctx) {
|
|
381
|
+
const ret = ctx.translate("examples");
|
|
382
|
+
if (ret) return ret;
|
|
383
|
+
const command = ctx.env.subCommands?.get(ctx.name || "");
|
|
384
|
+
return await resolveExamples(ctx, command?.examples);
|
|
385
|
+
}
|
|
386
|
+
__name(resolveExamples$1, "resolveExamples$1");
|
|
387
|
+
async function hasCommands(ctx) {
|
|
388
|
+
const loadedCommands = await ctx.loadCommands();
|
|
389
|
+
return loadedCommands.length > 1;
|
|
390
|
+
}
|
|
391
|
+
__name(hasCommands, "hasCommands");
|
|
392
|
+
function hasOptionalArgs(ctx) {
|
|
393
|
+
return !!(ctx.args && Object.values(ctx.args).some((arg) => arg.type !== "positional"));
|
|
394
|
+
}
|
|
395
|
+
__name(hasOptionalArgs, "hasOptionalArgs");
|
|
396
|
+
function hasPositionalArgs(ctx) {
|
|
397
|
+
return !!(ctx.args && Object.values(ctx.args).some((arg) => arg.type === "positional"));
|
|
398
|
+
}
|
|
399
|
+
__name(hasPositionalArgs, "hasPositionalArgs");
|
|
400
|
+
function hasAllDefaultOptions(ctx) {
|
|
401
|
+
return !!(ctx.args && Object.values(ctx.args).every((arg) => arg.default));
|
|
402
|
+
}
|
|
403
|
+
__name(hasAllDefaultOptions, "hasAllDefaultOptions");
|
|
404
|
+
function generateOptionsSymbols(ctx) {
|
|
405
|
+
return hasOptionalArgs(ctx) ? hasAllDefaultOptions(ctx) ? `[${ctx.translate(resolveBuiltInKey("OPTIONS"))}]` : `<${ctx.translate(resolveBuiltInKey("OPTIONS"))}>` : "";
|
|
406
|
+
}
|
|
407
|
+
__name(generateOptionsSymbols, "generateOptionsSymbols");
|
|
408
|
+
function makeShortLongOptionPair(schema, name, toKebab) {
|
|
409
|
+
const displayName = toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
410
|
+
let key = `--${displayName}`;
|
|
411
|
+
if (schema.short) key = `-${schema.short}, ${key}`;
|
|
412
|
+
return key;
|
|
413
|
+
}
|
|
414
|
+
__name(makeShortLongOptionPair, "makeShortLongOptionPair");
|
|
415
|
+
function getOptionalArgsPairs(ctx) {
|
|
416
|
+
return Object.entries(ctx.args).reduce((acc, [name, schema]) => {
|
|
417
|
+
if (schema.type === "positional") return acc;
|
|
418
|
+
let key = makeShortLongOptionPair(schema, name, ctx.toKebab);
|
|
419
|
+
if (schema.type !== "boolean") {
|
|
420
|
+
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
421
|
+
key = schema.default ? `${key} [${displayName}]` : `${key} <${displayName}>`;
|
|
422
|
+
}
|
|
423
|
+
acc[name] = key;
|
|
424
|
+
if (schema.type === "boolean" && schema.negatable && !COMMON_ARGS_KEYS.includes(name)) {
|
|
425
|
+
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
426
|
+
acc[`no-${name}`] = `--no-${displayName}`;
|
|
427
|
+
}
|
|
428
|
+
return acc;
|
|
429
|
+
}, create());
|
|
430
|
+
}
|
|
431
|
+
__name(getOptionalArgsPairs, "getOptionalArgsPairs");
|
|
432
|
+
var resolveNegatableKey = /* @__PURE__ */ __name((key) => key.split("no-")[1], "resolveNegatableKey");
|
|
433
|
+
function resolveNegatableType(key, ctx) {
|
|
434
|
+
return ctx.args[key.startsWith("no-") ? resolveNegatableKey(key) : key].type;
|
|
435
|
+
}
|
|
436
|
+
__name(resolveNegatableType, "resolveNegatableType");
|
|
437
|
+
function generateDefaultDisplayValue(ctx, schema) {
|
|
438
|
+
return `${ctx.translate(resolveBuiltInKey("DEFAULT"))}: ${schema.default}`;
|
|
439
|
+
}
|
|
440
|
+
__name(generateDefaultDisplayValue, "generateDefaultDisplayValue");
|
|
441
|
+
function resolveDisplayValue(ctx, key) {
|
|
442
|
+
if (COMMON_ARGS_KEYS.includes(key)) return "";
|
|
443
|
+
const schema = ctx.args[key];
|
|
444
|
+
if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "custom") && schema.default !== void 0) return `(${generateDefaultDisplayValue(ctx, schema)})`;
|
|
445
|
+
if (schema.type === "enum") {
|
|
446
|
+
const _default = schema.default !== void 0 ? generateDefaultDisplayValue(ctx, schema) : "";
|
|
447
|
+
const choices = `${ctx.translate(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
|
|
448
|
+
return `(${_default ? `${_default}, ${choices}` : choices})`;
|
|
449
|
+
}
|
|
450
|
+
return "";
|
|
451
|
+
}
|
|
452
|
+
__name(resolveDisplayValue, "resolveDisplayValue");
|
|
453
|
+
async function generateOptionalArgsUsage(ctx, optionsPairs) {
|
|
454
|
+
const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
|
|
455
|
+
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
|
|
456
|
+
const usages = await Promise.all(Object.entries(optionsPairs).map(([key, value]) => {
|
|
457
|
+
let rawDesc = ctx.translate(resolveArgKey(key));
|
|
458
|
+
if (!rawDesc && key.startsWith("no-")) {
|
|
459
|
+
const name = resolveNegatableKey(key);
|
|
460
|
+
const schema = ctx.args[name];
|
|
461
|
+
const optionKey = makeShortLongOptionPair(schema, name, ctx.toKebab);
|
|
462
|
+
rawDesc = `${ctx.translate(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
|
|
463
|
+
}
|
|
464
|
+
const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
|
|
465
|
+
const valueDesc = key.startsWith("no-") ? "" : resolveDisplayValue(ctx, key);
|
|
466
|
+
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
|
|
467
|
+
const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}${valueDesc ? ` ${valueDesc}` : ""}`;
|
|
468
|
+
return `${option.padStart(ctx.env.leftMargin + option.length)}`;
|
|
469
|
+
}));
|
|
470
|
+
return usages.join("\n");
|
|
471
|
+
}
|
|
472
|
+
__name(generateOptionalArgsUsage, "generateOptionalArgsUsage");
|
|
473
|
+
function getPositionalArgs(ctx) {
|
|
474
|
+
return Object.entries(ctx.args).filter(([_, schema]) => schema.type === "positional");
|
|
475
|
+
}
|
|
476
|
+
__name(getPositionalArgs, "getPositionalArgs");
|
|
477
|
+
async function generatePositionalArgsUsage(ctx) {
|
|
478
|
+
const positionals = getPositionalArgs(ctx);
|
|
479
|
+
const argsMaxLength = Math.max(...positionals.map(([name]) => name.length));
|
|
480
|
+
const usages = await Promise.all(positionals.map(([name]) => {
|
|
481
|
+
const desc = ctx.translate(resolveArgKey(name)) || ctx.args[name].description || "";
|
|
482
|
+
const arg = `${name.padEnd(argsMaxLength + ctx.env.middleMargin)} ${desc}`;
|
|
483
|
+
return `${arg.padStart(ctx.env.leftMargin + arg.length)}`;
|
|
484
|
+
}));
|
|
485
|
+
return usages.join("\n");
|
|
486
|
+
}
|
|
487
|
+
__name(generatePositionalArgsUsage, "generatePositionalArgsUsage");
|
|
488
|
+
function generatePositionalSymbols(ctx) {
|
|
489
|
+
return hasPositionalArgs(ctx) ? getPositionalArgs(ctx).map(([name]) => `<${name}>`).join(" ") : "";
|
|
490
|
+
}
|
|
491
|
+
__name(generatePositionalSymbols, "generatePositionalSymbols");
|
|
492
|
+
function renderValidationErrors(_ctx, error) {
|
|
493
|
+
const messages = [];
|
|
494
|
+
for (const err of error.errors) messages.push(err.message);
|
|
495
|
+
return Promise.resolve(messages.join("\n"));
|
|
496
|
+
}
|
|
497
|
+
__name(renderValidationErrors, "renderValidationErrors");
|
|
498
|
+
|
|
499
|
+
// ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/parser-Dr4iAGaX.js
|
|
500
|
+
var HYPHEN_CHAR = "-";
|
|
501
|
+
var HYPHEN_CODE = HYPHEN_CHAR.codePointAt(0);
|
|
502
|
+
var EQUAL_CHAR = "=";
|
|
503
|
+
var EQUAL_CODE = EQUAL_CHAR.codePointAt(0);
|
|
504
|
+
var TERMINATOR = "--";
|
|
505
|
+
var SHORT_OPTION_PREFIX = HYPHEN_CHAR;
|
|
506
|
+
var LONG_OPTION_PREFIX = "--";
|
|
507
|
+
function parseArgs(args, options = {}) {
|
|
508
|
+
const { allowCompatible = false } = options;
|
|
509
|
+
const tokens = [];
|
|
510
|
+
const remainings = [...args];
|
|
511
|
+
let index = -1;
|
|
512
|
+
let groupCount = 0;
|
|
513
|
+
let hasShortValueSeparator = false;
|
|
514
|
+
while (remainings.length > 0) {
|
|
515
|
+
const arg = remainings.shift();
|
|
516
|
+
if (arg == void 0) break;
|
|
517
|
+
const nextArg = remainings[0];
|
|
518
|
+
if (groupCount > 0) groupCount--;
|
|
519
|
+
else index++;
|
|
520
|
+
if (arg === TERMINATOR) {
|
|
521
|
+
tokens.push({
|
|
522
|
+
kind: "option-terminator",
|
|
523
|
+
index
|
|
524
|
+
});
|
|
525
|
+
const mapped = remainings.map((arg$1) => {
|
|
526
|
+
return {
|
|
527
|
+
kind: "positional",
|
|
528
|
+
index: ++index,
|
|
529
|
+
value: arg$1
|
|
530
|
+
};
|
|
531
|
+
});
|
|
532
|
+
tokens.push(...mapped);
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
if (isShortOption(arg)) {
|
|
536
|
+
const shortOption = arg.charAt(1);
|
|
537
|
+
let value;
|
|
538
|
+
let inlineValue;
|
|
539
|
+
if (groupCount) {
|
|
540
|
+
tokens.push({
|
|
541
|
+
kind: "option",
|
|
542
|
+
name: shortOption,
|
|
543
|
+
rawName: arg,
|
|
544
|
+
index,
|
|
545
|
+
value,
|
|
546
|
+
inlineValue
|
|
547
|
+
});
|
|
548
|
+
if (groupCount === 1 && hasOptionValue(nextArg)) {
|
|
549
|
+
value = remainings.shift();
|
|
550
|
+
if (hasShortValueSeparator) {
|
|
551
|
+
inlineValue = true;
|
|
552
|
+
hasShortValueSeparator = false;
|
|
553
|
+
}
|
|
554
|
+
tokens.push({
|
|
555
|
+
kind: "option",
|
|
556
|
+
index,
|
|
557
|
+
value,
|
|
558
|
+
inlineValue
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
} else tokens.push({
|
|
562
|
+
kind: "option",
|
|
563
|
+
name: shortOption,
|
|
564
|
+
rawName: arg,
|
|
565
|
+
index,
|
|
566
|
+
value,
|
|
567
|
+
inlineValue
|
|
568
|
+
});
|
|
569
|
+
if (value != null) ++index;
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (isShortOptionGroup(arg)) {
|
|
573
|
+
const expanded = [];
|
|
574
|
+
let shortValue = "";
|
|
575
|
+
for (let i = 1; i < arg.length; i++) {
|
|
576
|
+
const shortableOption = arg.charAt(i);
|
|
577
|
+
if (hasShortValueSeparator) shortValue += shortableOption;
|
|
578
|
+
else if (!allowCompatible && shortableOption.codePointAt(0) === EQUAL_CODE) hasShortValueSeparator = true;
|
|
579
|
+
else expanded.push(`${SHORT_OPTION_PREFIX}${shortableOption}`);
|
|
580
|
+
}
|
|
581
|
+
if (shortValue) expanded.push(shortValue);
|
|
582
|
+
remainings.unshift(...expanded);
|
|
583
|
+
groupCount = expanded.length;
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if (isLongOption(arg)) {
|
|
587
|
+
const longOption = arg.slice(2);
|
|
588
|
+
tokens.push({
|
|
589
|
+
kind: "option",
|
|
590
|
+
name: longOption,
|
|
591
|
+
rawName: arg,
|
|
592
|
+
index,
|
|
593
|
+
value: void 0,
|
|
594
|
+
inlineValue: void 0
|
|
595
|
+
});
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (isLongOptionAndValue(arg)) {
|
|
599
|
+
const equalIndex = arg.indexOf(EQUAL_CHAR);
|
|
600
|
+
const longOption = arg.slice(2, equalIndex);
|
|
601
|
+
const value = arg.slice(equalIndex + 1);
|
|
602
|
+
tokens.push({
|
|
603
|
+
kind: "option",
|
|
604
|
+
name: longOption,
|
|
605
|
+
rawName: `${LONG_OPTION_PREFIX}${longOption}`,
|
|
606
|
+
index,
|
|
607
|
+
value,
|
|
608
|
+
inlineValue: true
|
|
609
|
+
});
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
tokens.push({
|
|
613
|
+
kind: "positional",
|
|
614
|
+
index,
|
|
615
|
+
value: arg
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
return tokens;
|
|
619
|
+
}
|
|
620
|
+
__name(parseArgs, "parseArgs");
|
|
621
|
+
function isShortOption(arg) {
|
|
622
|
+
return arg.length === 2 && arg.codePointAt(0) === HYPHEN_CODE && arg.codePointAt(1) !== HYPHEN_CODE;
|
|
623
|
+
}
|
|
624
|
+
__name(isShortOption, "isShortOption");
|
|
625
|
+
function isShortOptionGroup(arg) {
|
|
626
|
+
if (arg.length <= 2) return false;
|
|
627
|
+
if (arg.codePointAt(0) !== HYPHEN_CODE) return false;
|
|
628
|
+
if (arg.codePointAt(1) === HYPHEN_CODE) return false;
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
__name(isShortOptionGroup, "isShortOptionGroup");
|
|
632
|
+
function isLongOption(arg) {
|
|
633
|
+
return hasLongOptionPrefix(arg) && !arg.includes(EQUAL_CHAR, 3);
|
|
634
|
+
}
|
|
635
|
+
__name(isLongOption, "isLongOption");
|
|
636
|
+
function isLongOptionAndValue(arg) {
|
|
637
|
+
return hasLongOptionPrefix(arg) && arg.includes(EQUAL_CHAR, 3);
|
|
638
|
+
}
|
|
639
|
+
__name(isLongOptionAndValue, "isLongOptionAndValue");
|
|
640
|
+
function hasLongOptionPrefix(arg) {
|
|
641
|
+
return arg.length > 2 && ~arg.indexOf(LONG_OPTION_PREFIX);
|
|
642
|
+
}
|
|
643
|
+
__name(hasLongOptionPrefix, "hasLongOptionPrefix");
|
|
644
|
+
function hasOptionValue(value) {
|
|
645
|
+
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
646
|
+
}
|
|
647
|
+
__name(hasOptionValue, "hasOptionValue");
|
|
648
|
+
|
|
649
|
+
// ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/resolver-Q4k2fgTW.js
|
|
650
|
+
var SKIP_POSITIONAL_DEFAULT = -1;
|
|
651
|
+
function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKIP_POSITIONAL_DEFAULT, toKebab = false } = {}) {
|
|
652
|
+
const skipPositionalIndex = typeof skipPositional === "number" ? Math.max(skipPositional, SKIP_POSITIONAL_DEFAULT) : SKIP_POSITIONAL_DEFAULT;
|
|
653
|
+
const rest = [];
|
|
654
|
+
const optionTokens = [];
|
|
655
|
+
const positionalTokens = [];
|
|
656
|
+
let currentLongOption;
|
|
657
|
+
let currentShortOption;
|
|
658
|
+
const expandableShortOptions = [];
|
|
659
|
+
function toShortValue() {
|
|
660
|
+
if (expandableShortOptions.length === 0) return void 0;
|
|
661
|
+
else {
|
|
662
|
+
const value = expandableShortOptions.map((token) => token.name).join("");
|
|
663
|
+
expandableShortOptions.length = 0;
|
|
664
|
+
return value;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
__name(toShortValue, "toShortValue");
|
|
668
|
+
function applyLongOptionValue(value = void 0) {
|
|
669
|
+
if (currentLongOption) {
|
|
670
|
+
currentLongOption.value = value;
|
|
671
|
+
optionTokens.push({ ...currentLongOption });
|
|
672
|
+
currentLongOption = void 0;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
__name(applyLongOptionValue, "applyLongOptionValue");
|
|
676
|
+
function applyShortOptionValue(value = void 0) {
|
|
677
|
+
if (currentShortOption) {
|
|
678
|
+
currentShortOption.value = value || toShortValue();
|
|
679
|
+
optionTokens.push({ ...currentShortOption });
|
|
680
|
+
currentShortOption = void 0;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
__name(applyShortOptionValue, "applyShortOptionValue");
|
|
684
|
+
const schemas = Object.values(args);
|
|
685
|
+
let terminated = false;
|
|
686
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
687
|
+
const token = tokens[i];
|
|
688
|
+
if (token.kind === "positional") {
|
|
689
|
+
if (terminated && token.value) {
|
|
690
|
+
rest.push(token.value);
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
if (currentShortOption) {
|
|
694
|
+
const found = schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean");
|
|
695
|
+
if (found) positionalTokens.push({ ...token });
|
|
696
|
+
} else if (currentLongOption) {
|
|
697
|
+
const found = args[currentLongOption.name]?.type === "boolean";
|
|
698
|
+
if (found) positionalTokens.push({ ...token });
|
|
699
|
+
} else positionalTokens.push({ ...token });
|
|
700
|
+
applyLongOptionValue(token.value);
|
|
701
|
+
applyShortOptionValue(token.value);
|
|
702
|
+
} else if (token.kind === "option") if (token.rawName) {
|
|
703
|
+
if (hasLongOptionPrefix(token.rawName)) {
|
|
704
|
+
applyLongOptionValue();
|
|
705
|
+
if (token.inlineValue) optionTokens.push({ ...token });
|
|
706
|
+
else currentLongOption = { ...token };
|
|
707
|
+
applyShortOptionValue();
|
|
708
|
+
} else if (isShortOption(token.rawName)) if (currentShortOption) {
|
|
709
|
+
if (currentShortOption.index === token.index) if (shortGrouping) {
|
|
710
|
+
currentShortOption.value = token.value;
|
|
711
|
+
optionTokens.push({ ...currentShortOption });
|
|
712
|
+
currentShortOption = { ...token };
|
|
713
|
+
} else expandableShortOptions.push({ ...token });
|
|
714
|
+
else {
|
|
715
|
+
currentShortOption.value = toShortValue();
|
|
716
|
+
optionTokens.push({ ...currentShortOption });
|
|
717
|
+
currentShortOption = { ...token };
|
|
718
|
+
}
|
|
719
|
+
applyLongOptionValue();
|
|
720
|
+
} else {
|
|
721
|
+
currentShortOption = { ...token };
|
|
722
|
+
applyLongOptionValue();
|
|
723
|
+
}
|
|
724
|
+
} else {
|
|
725
|
+
if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
|
|
726
|
+
currentShortOption.value = token.value;
|
|
727
|
+
optionTokens.push({ ...currentShortOption });
|
|
728
|
+
currentShortOption = void 0;
|
|
729
|
+
}
|
|
730
|
+
applyLongOptionValue();
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
if (token.kind === "option-terminator") terminated = true;
|
|
734
|
+
applyLongOptionValue();
|
|
735
|
+
applyShortOptionValue();
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
applyLongOptionValue();
|
|
739
|
+
applyShortOptionValue();
|
|
740
|
+
const values = /* @__PURE__ */ Object.create(null);
|
|
741
|
+
const errors = [];
|
|
742
|
+
function checkTokenName(option, schema, token) {
|
|
743
|
+
return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
|
|
744
|
+
}
|
|
745
|
+
__name(checkTokenName, "checkTokenName");
|
|
746
|
+
const positionalItemCount = tokens.filter((token) => token.kind === "positional").length;
|
|
747
|
+
function getPositionalSkipIndex() {
|
|
748
|
+
return Math.min(skipPositionalIndex, positionalItemCount);
|
|
749
|
+
}
|
|
750
|
+
__name(getPositionalSkipIndex, "getPositionalSkipIndex");
|
|
751
|
+
let positionalsCount = 0;
|
|
752
|
+
for (const [rawArg, schema] of Object.entries(args)) {
|
|
753
|
+
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
754
|
+
if (schema.required) {
|
|
755
|
+
const found = optionTokens.find((token) => {
|
|
756
|
+
return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
|
|
757
|
+
});
|
|
758
|
+
if (!found) {
|
|
759
|
+
errors.push(createRequireError(arg, schema));
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (schema.type === "positional") {
|
|
764
|
+
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
|
|
765
|
+
const positional = positionalTokens[positionalsCount];
|
|
766
|
+
if (positional != null) values[rawArg] = positional.value;
|
|
767
|
+
else errors.push(createRequireError(arg, schema));
|
|
768
|
+
positionalsCount++;
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
for (let i = 0; i < optionTokens.length; i++) {
|
|
772
|
+
const token = optionTokens[i];
|
|
773
|
+
if (checkTokenName(arg, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
|
|
774
|
+
const invalid = validateRequire(token, arg, schema);
|
|
775
|
+
if (invalid) {
|
|
776
|
+
errors.push(invalid);
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
if (schema.type === "boolean") token.value = void 0;
|
|
780
|
+
const [parsedValue, error] = parse(token, arg, schema);
|
|
781
|
+
if (error) errors.push(error);
|
|
782
|
+
else if (schema.multiple) {
|
|
783
|
+
values[rawArg] ||= [];
|
|
784
|
+
values[rawArg].push(parsedValue);
|
|
785
|
+
} else values[rawArg] = parsedValue;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (values[rawArg] == null && schema.default != null) values[rawArg] = schema.default;
|
|
789
|
+
}
|
|
790
|
+
return {
|
|
791
|
+
values,
|
|
792
|
+
positionals: positionalTokens.map((token) => token.value),
|
|
793
|
+
rest,
|
|
794
|
+
error: errors.length > 0 ? new AggregateError(errors) : void 0
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
__name(resolveArgs, "resolveArgs");
|
|
798
|
+
function parse(token, option, schema) {
|
|
799
|
+
switch (schema.type) {
|
|
800
|
+
case "string":
|
|
801
|
+
return typeof token.value === "string" ? [token.value || schema.default, void 0] : [void 0, createTypeError(option, schema)];
|
|
802
|
+
case "boolean":
|
|
803
|
+
return token.value ? [token.value || schema.default, void 0] : [!(schema.negatable && token.name.startsWith("no-")), void 0];
|
|
804
|
+
case "number": {
|
|
805
|
+
if (!isNumeric(token.value)) return [void 0, createTypeError(option, schema)];
|
|
806
|
+
return token.value ? [+token.value, void 0] : [+(schema.default || ""), void 0];
|
|
807
|
+
}
|
|
808
|
+
case "enum": {
|
|
809
|
+
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)];
|
|
810
|
+
return [token.value || schema.default, void 0];
|
|
811
|
+
}
|
|
812
|
+
case "custom": {
|
|
813
|
+
if (typeof schema.parse !== "function") throw new TypeError(`argument '${option}' should have a 'parse' function`);
|
|
814
|
+
try {
|
|
815
|
+
return [schema.parse(token.value || String(schema.default || "")), void 0];
|
|
816
|
+
} catch (error) {
|
|
817
|
+
return [void 0, error];
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
default:
|
|
821
|
+
throw new Error(`Unsupported argument type '${schema.type}' for option '${option}'`);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
__name(parse, "parse");
|
|
825
|
+
function createRequireError(option, schema) {
|
|
826
|
+
const message = schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`;
|
|
827
|
+
return new ArgResolveError(message, option, "required", schema);
|
|
828
|
+
}
|
|
829
|
+
__name(createRequireError, "createRequireError");
|
|
830
|
+
var ArgResolveError = class extends Error {
|
|
831
|
+
static {
|
|
832
|
+
__name(this, "ArgResolveError");
|
|
833
|
+
}
|
|
834
|
+
name;
|
|
835
|
+
schema;
|
|
836
|
+
type;
|
|
837
|
+
constructor(message, name, type, schema) {
|
|
838
|
+
super(message);
|
|
839
|
+
this.name = name;
|
|
840
|
+
this.type = type;
|
|
841
|
+
this.schema = schema;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
function validateRequire(token, option, schema) {
|
|
845
|
+
if (schema.required && schema.type !== "boolean" && !token.value) return createRequireError(option, schema);
|
|
846
|
+
}
|
|
847
|
+
__name(validateRequire, "validateRequire");
|
|
848
|
+
function isNumeric(str) {
|
|
849
|
+
return str.trim() !== "" && !isNaN(str);
|
|
850
|
+
}
|
|
851
|
+
__name(isNumeric, "isNumeric");
|
|
852
|
+
function createTypeError(option, schema) {
|
|
853
|
+
return new ArgResolveError(`Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be '${schema.type}'`, option, "type", schema);
|
|
854
|
+
}
|
|
855
|
+
__name(createTypeError, "createTypeError");
|
|
856
|
+
|
|
857
|
+
// ../../node_modules/.pnpm/gunshi@0.26.3/node_modules/gunshi/lib/cli-DVGNVw3h.js
|
|
858
|
+
async function cli(argv, entry, options = {}) {
|
|
859
|
+
const cliOptions = resolveCliOptions(options, entry);
|
|
860
|
+
const tokens = parseArgs(argv);
|
|
861
|
+
const subCommand = getSubCommand(tokens);
|
|
862
|
+
const { commandName: name, command, callMode } = await resolveCommand(subCommand, entry, cliOptions);
|
|
863
|
+
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
864
|
+
const args = resolveArguments(getCommandArgs(command));
|
|
865
|
+
const { values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
866
|
+
shortGrouping: true,
|
|
867
|
+
toKebab: command.toKebab,
|
|
868
|
+
skipPositional: cliOptions.subCommands.size > 0 ? 0 : -1
|
|
869
|
+
});
|
|
870
|
+
const omitted = !subCommand;
|
|
871
|
+
const ctx = await createCommandContext({
|
|
872
|
+
args,
|
|
873
|
+
values,
|
|
874
|
+
positionals,
|
|
875
|
+
rest,
|
|
876
|
+
argv,
|
|
877
|
+
tokens,
|
|
878
|
+
omitted,
|
|
879
|
+
callMode,
|
|
880
|
+
command,
|
|
881
|
+
cliOptions
|
|
882
|
+
});
|
|
883
|
+
if (values.version) {
|
|
884
|
+
showVersion(ctx);
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
const usageBuffer = [];
|
|
888
|
+
const header = await showHeader(ctx);
|
|
889
|
+
if (header) usageBuffer.push(header);
|
|
890
|
+
if (values.help) {
|
|
891
|
+
const usage = await showUsage(ctx);
|
|
892
|
+
if (usage) usageBuffer.push(usage);
|
|
893
|
+
return usageBuffer.join("\n");
|
|
894
|
+
}
|
|
895
|
+
if (error) {
|
|
896
|
+
await showValidationErrors(ctx, error);
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
await executeCommand(command, ctx, name || "");
|
|
900
|
+
}
|
|
901
|
+
__name(cli, "cli");
|
|
902
|
+
function getCommandArgs(cmd) {
|
|
903
|
+
if (isLazyCommand(cmd)) return cmd.args || create();
|
|
904
|
+
else if (typeof cmd === "object") return cmd.args || create();
|
|
905
|
+
else return create();
|
|
906
|
+
}
|
|
907
|
+
__name(getCommandArgs, "getCommandArgs");
|
|
908
|
+
function resolveArguments(args) {
|
|
909
|
+
return Object.assign(create(), args, COMMON_ARGS);
|
|
910
|
+
}
|
|
911
|
+
__name(resolveArguments, "resolveArguments");
|
|
912
|
+
function resolveCliOptions(options, entry) {
|
|
913
|
+
const subCommands = new Map(options.subCommands);
|
|
914
|
+
if (options.subCommands) {
|
|
915
|
+
if (isLazyCommand(entry)) subCommands.set(entry.commandName, entry);
|
|
916
|
+
else if (typeof entry === "object" && entry.name) subCommands.set(entry.name, entry);
|
|
917
|
+
}
|
|
918
|
+
const resolvedOptions = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, options, { subCommands });
|
|
919
|
+
return resolvedOptions;
|
|
920
|
+
}
|
|
921
|
+
__name(resolveCliOptions, "resolveCliOptions");
|
|
922
|
+
function getSubCommand(tokens) {
|
|
923
|
+
const firstToken = tokens[0];
|
|
924
|
+
return firstToken && firstToken.kind === "positional" && firstToken.index === 0 && firstToken.value ? firstToken.value : "";
|
|
925
|
+
}
|
|
926
|
+
__name(getSubCommand, "getSubCommand");
|
|
927
|
+
async function showUsage(ctx) {
|
|
928
|
+
if (ctx.env.renderUsage === null) return;
|
|
929
|
+
const usage = await (ctx.env.renderUsage || renderUsage)(ctx);
|
|
930
|
+
if (usage) {
|
|
931
|
+
ctx.log(usage);
|
|
932
|
+
return usage;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
__name(showUsage, "showUsage");
|
|
936
|
+
function showVersion(ctx) {
|
|
937
|
+
ctx.log(ctx.env.version);
|
|
938
|
+
}
|
|
939
|
+
__name(showVersion, "showVersion");
|
|
940
|
+
async function showHeader(ctx) {
|
|
941
|
+
if (ctx.env.renderHeader === null) return;
|
|
942
|
+
const header = await (ctx.env.renderHeader || renderHeader)(ctx);
|
|
943
|
+
if (header) {
|
|
944
|
+
ctx.log(header);
|
|
945
|
+
ctx.log();
|
|
946
|
+
return header;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
__name(showHeader, "showHeader");
|
|
950
|
+
async function showValidationErrors(ctx, error) {
|
|
951
|
+
if (ctx.env.renderValidationErrors === null) return;
|
|
952
|
+
const render = ctx.env.renderValidationErrors || renderValidationErrors;
|
|
953
|
+
ctx.log(await render(ctx, error));
|
|
954
|
+
}
|
|
955
|
+
__name(showValidationErrors, "showValidationErrors");
|
|
956
|
+
var CANNOT_RESOLVE_COMMAND = { callMode: "unexpected" };
|
|
957
|
+
async function resolveCommand(sub, entry, options) {
|
|
958
|
+
const omitted = !sub;
|
|
959
|
+
async function doResolveCommand() {
|
|
960
|
+
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
|
|
961
|
+
commandName: entry.commandName,
|
|
962
|
+
command: entry,
|
|
963
|
+
callMode: "entry"
|
|
964
|
+
};
|
|
965
|
+
else return {
|
|
966
|
+
command: { run: entry },
|
|
967
|
+
callMode: "entry"
|
|
968
|
+
};
|
|
969
|
+
else if (typeof entry === "object") return {
|
|
970
|
+
commandName: resolveEntryName(entry),
|
|
971
|
+
command: entry,
|
|
972
|
+
callMode: "entry"
|
|
973
|
+
};
|
|
974
|
+
else return CANNOT_RESOLVE_COMMAND;
|
|
975
|
+
}
|
|
976
|
+
__name(doResolveCommand, "doResolveCommand");
|
|
977
|
+
if (omitted || options.subCommands?.size === 0) return doResolveCommand();
|
|
978
|
+
const cmd = options.subCommands?.get(sub);
|
|
979
|
+
if (cmd == null) return {
|
|
980
|
+
commandName: sub,
|
|
981
|
+
callMode: "unexpected"
|
|
982
|
+
};
|
|
983
|
+
if (isLazyCommand(cmd) && cmd.commandName == null) cmd.commandName = sub;
|
|
984
|
+
else if (typeof cmd === "object" && cmd.name == null) cmd.name = sub;
|
|
985
|
+
return {
|
|
986
|
+
commandName: sub,
|
|
987
|
+
command: cmd,
|
|
988
|
+
callMode: "subCommand"
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
__name(resolveCommand, "resolveCommand");
|
|
992
|
+
function resolveEntryName(entry) {
|
|
993
|
+
return entry.name || ANONYMOUS_COMMAND_NAME;
|
|
994
|
+
}
|
|
995
|
+
__name(resolveEntryName, "resolveEntryName");
|
|
996
|
+
async function executeCommand(cmd, ctx, name) {
|
|
997
|
+
const resolved = isLazyCommand(cmd) ? await resolveLazyCommand(cmd, name, true) : cmd;
|
|
998
|
+
if (resolved.run == null) throw new Error(`'run' not found on Command \`${name}\``);
|
|
999
|
+
await resolved.run(ctx);
|
|
1000
|
+
}
|
|
1001
|
+
__name(executeCommand, "executeCommand");
|
|
1002
|
+
/*! Bundled license information:
|
|
1003
|
+
|
|
1004
|
+
args-tokens/lib/utils-N7UlhLbz.js:
|
|
1005
|
+
(**
|
|
1006
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
1007
|
+
* @license MIT
|
|
1008
|
+
*)
|
|
1009
|
+
*/
|
|
1010
|
+
|
|
1011
|
+
export { cli, define };
|
|
1012
|
+
//# sourceMappingURL=chunk-33ROL4J5.js.map
|
|
1013
|
+
//# sourceMappingURL=chunk-33ROL4J5.js.map
|