@clerc/core 0.41.0 → 0.42.0
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/LICENSE +21 -21
- package/README.md +1 -1
- package/dist/index.d.ts +43 -43
- package/dist/index.js +34 -34
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Ray <https://github.com/so1ve>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Ray <https://github.com/so1ve>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@clerc/core)
|
|
4
4
|
|
|
5
|
-
See [Clerc](https://github.com/
|
|
5
|
+
See [Clerc](https://github.com/clercjs/clerc) for documentation.
|
|
6
6
|
|
|
7
7
|
## 📝 License
|
|
8
8
|
|
package/dist/index.d.ts
CHANGED
|
@@ -92,10 +92,10 @@ type ParseRaw<C extends Command, GF extends GlobalFlagOptions = {}> = NonNullabl
|
|
|
92
92
|
type ParseParameters<C extends Commands = Commands, N extends keyof C = keyof C> = Equals<TransformParameters<C[N]>, {}> extends true ? N extends keyof C ? TransformParameters<C[N]> : Dict<string | string[] | undefined> : TransformParameters<C[N]>;
|
|
93
93
|
|
|
94
94
|
type Locales = Dict<Dict<string>>;
|
|
95
|
-
type
|
|
95
|
+
type TranslateFunction = (name: string, ...arguments_: string[]) => string | undefined;
|
|
96
96
|
interface I18N {
|
|
97
97
|
add: (locales: Locales) => void;
|
|
98
|
-
t:
|
|
98
|
+
t: TranslateFunction;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
|
|
@@ -148,19 +148,19 @@ interface HandlerContext<C extends Commands = Commands, N extends keyof C = keyo
|
|
|
148
148
|
flags: Simplify<ParseFlag<C, N, GF> & Record<string, any>>;
|
|
149
149
|
cli: Clerc<C, GF>;
|
|
150
150
|
}
|
|
151
|
-
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (
|
|
152
|
-
type HandlerInCommand<C extends HandlerContext> = (
|
|
151
|
+
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (context: HandlerContext<C, K, GF>) => void;
|
|
152
|
+
type HandlerInCommand<C extends HandlerContext> = (context: {
|
|
153
153
|
[K in keyof C]: C[K];
|
|
154
154
|
}) => void;
|
|
155
155
|
type FallbackType<T, U> = {} extends T ? U : T;
|
|
156
156
|
type InspectorContext<C extends Commands = Commands> = HandlerContext<C> & {
|
|
157
157
|
flags: FallbackType<TypeFlag<NonNullable<C[keyof C]["flags"]>>["flags"], Dict<any>>;
|
|
158
158
|
};
|
|
159
|
-
type Inspector<C extends Commands = Commands> =
|
|
160
|
-
type
|
|
159
|
+
type Inspector<C extends Commands = Commands> = InspectorFunction<C> | InspectorObject<C>;
|
|
160
|
+
type InspectorFunction<C extends Commands = Commands> = (context: InspectorContext<C>, next: () => void) => void;
|
|
161
161
|
interface InspectorObject<C extends Commands = Commands> {
|
|
162
162
|
enforce?: "pre" | "post";
|
|
163
|
-
fn:
|
|
163
|
+
fn: InspectorFunction<C>;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
declare const Root: unique symbol;
|
|
@@ -282,14 +282,14 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
282
282
|
*
|
|
283
283
|
* ```ts
|
|
284
284
|
* Clerc.create().errorHandler((err) => {
|
|
285
|
-
*
|
|
285
|
+
* console.log(err);
|
|
286
286
|
* });
|
|
287
287
|
* ```
|
|
288
288
|
*
|
|
289
289
|
* @param handler
|
|
290
290
|
* @returns
|
|
291
291
|
*/
|
|
292
|
-
errorHandler(handler: (
|
|
292
|
+
errorHandler(handler: (error: any) => void): this;
|
|
293
293
|
/**
|
|
294
294
|
* Register a command
|
|
295
295
|
*
|
|
@@ -297,13 +297,13 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
297
297
|
*
|
|
298
298
|
* ```ts
|
|
299
299
|
* Clerc.create().command("test", "test command", {
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
300
|
+
* alias: "t",
|
|
301
|
+
* flags: {
|
|
302
|
+
* foo: {
|
|
303
|
+
* alias: "f",
|
|
304
|
+
* description: "foo flag",
|
|
305
|
+
* },
|
|
306
|
+
* },
|
|
307
307
|
* });
|
|
308
308
|
* ```
|
|
309
309
|
*
|
|
@@ -311,12 +311,12 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
311
311
|
*
|
|
312
312
|
* ```ts
|
|
313
313
|
* Clerc.create().command("", "root", {
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
314
|
+
* flags: {
|
|
315
|
+
* foo: {
|
|
316
|
+
* alias: "f",
|
|
317
|
+
* description: "foo flag",
|
|
318
|
+
* },
|
|
319
|
+
* },
|
|
320
320
|
* });
|
|
321
321
|
* ```
|
|
322
322
|
*
|
|
@@ -334,8 +334,8 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
334
334
|
*
|
|
335
335
|
* ```ts
|
|
336
336
|
* Clerc.create().flag("help", "help", {
|
|
337
|
-
*
|
|
338
|
-
*
|
|
337
|
+
* alias: "h",
|
|
338
|
+
* type: Boolean,
|
|
339
339
|
* });
|
|
340
340
|
* ```
|
|
341
341
|
*
|
|
@@ -352,10 +352,10 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
352
352
|
*
|
|
353
353
|
* ```ts
|
|
354
354
|
* Clerc.create()
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
355
|
+
* .command("test", "test command")
|
|
356
|
+
* .on("test", (ctx) => {
|
|
357
|
+
* console.log(ctx);
|
|
358
|
+
* });
|
|
359
359
|
* ```
|
|
360
360
|
*
|
|
361
361
|
* @param name
|
|
@@ -383,8 +383,8 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
383
383
|
*
|
|
384
384
|
* ```ts
|
|
385
385
|
* Clerc.create().inspector((ctx, next) => {
|
|
386
|
-
*
|
|
387
|
-
*
|
|
386
|
+
* console.log(ctx);
|
|
387
|
+
* next();
|
|
388
388
|
* });
|
|
389
389
|
* ```
|
|
390
390
|
*
|
|
@@ -422,35 +422,35 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
422
422
|
|
|
423
423
|
declare class CommandExistsError extends Error {
|
|
424
424
|
commandName: string;
|
|
425
|
-
constructor(commandName: string, t:
|
|
425
|
+
constructor(commandName: string, t: TranslateFunction);
|
|
426
426
|
}
|
|
427
427
|
declare class NoSuchCommandError extends Error {
|
|
428
428
|
commandName: string;
|
|
429
|
-
constructor(commandName: string, t:
|
|
429
|
+
constructor(commandName: string, t: TranslateFunction);
|
|
430
430
|
}
|
|
431
431
|
declare class NoCommandGivenError extends Error {
|
|
432
|
-
constructor(t:
|
|
432
|
+
constructor(t: TranslateFunction);
|
|
433
433
|
}
|
|
434
434
|
declare class CommandNameConflictError extends Error {
|
|
435
435
|
n1: string;
|
|
436
436
|
n2: string;
|
|
437
|
-
constructor(n1: string, n2: string, t:
|
|
437
|
+
constructor(n1: string, n2: string, t: TranslateFunction);
|
|
438
438
|
}
|
|
439
439
|
declare class ScriptNameNotSetError extends Error {
|
|
440
|
-
constructor(t:
|
|
440
|
+
constructor(t: TranslateFunction);
|
|
441
441
|
}
|
|
442
442
|
declare class DescriptionNotSetError extends Error {
|
|
443
|
-
constructor(t:
|
|
443
|
+
constructor(t: TranslateFunction);
|
|
444
444
|
}
|
|
445
445
|
declare class VersionNotSetError extends Error {
|
|
446
|
-
constructor(t:
|
|
446
|
+
constructor(t: TranslateFunction);
|
|
447
447
|
}
|
|
448
448
|
declare class InvalidCommandNameError extends Error {
|
|
449
449
|
commandName: string;
|
|
450
|
-
constructor(commandName: string, t:
|
|
450
|
+
constructor(commandName: string, t: TranslateFunction);
|
|
451
451
|
}
|
|
452
452
|
declare class LocaleNotCalledFirstError extends Error {
|
|
453
|
-
constructor(t:
|
|
453
|
+
constructor(t: TranslateFunction);
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
type MaybeArray<T> = T | T[];
|
|
@@ -460,14 +460,14 @@ declare const defineHandler: <C extends Clerc<{}, {}>, K extends keyof C["_comma
|
|
|
460
460
|
declare const defineInspector: <C extends Clerc<{}, {}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
|
|
461
461
|
declare const defineCommand: <N extends string | typeof Root, O extends CommandOptions<[...P], MaybeArray<string | typeof Root>, Flags>, P extends string[]>(command: Command<N, O & CommandOptions<[...P], MaybeArray<string | typeof Root>, Flags>>, handler?: HandlerInCommand<HandlerContext<Record<N, Command<N, O>> & Record<never, never>, N, {}>> | undefined) => CommandWithHandler<N, O & CommandOptions<[...P], MaybeArray<string | typeof Root>, Flags>>;
|
|
462
462
|
|
|
463
|
-
declare function resolveFlattenCommands(commands: Commands, t:
|
|
464
|
-
declare function resolveCommand(commands: Commands, argv: string[], t:
|
|
463
|
+
declare function resolveFlattenCommands(commands: Commands, t: TranslateFunction): Map<string[] | typeof Root, CommandAlias>;
|
|
464
|
+
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFunction): [Command<string | RootType> | undefined, string[] | RootType | undefined];
|
|
465
465
|
declare const resolveArgv: () => string[];
|
|
466
|
-
declare function compose(inspectors: Inspector[]): (
|
|
466
|
+
declare function compose(inspectors: Inspector[]): (context: InspectorContext) => void;
|
|
467
467
|
declare const isValidName: (name: CommandType) => boolean;
|
|
468
468
|
declare const withBrackets: (s: string, isOptional?: boolean) => string;
|
|
469
469
|
declare const formatCommandName: (name: string | string[] | RootType) => string;
|
|
470
470
|
declare const detectLocale: () => string;
|
|
471
471
|
declare const stripFlags: (argv: string[]) => string[];
|
|
472
472
|
|
|
473
|
-
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext,
|
|
473
|
+
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFunction, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, ScriptNameNotSetError, TranslateFunction, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, isValidName, resolveArgv, resolveCommand, resolveFlattenCommands, stripFlags, withBrackets };
|
package/dist/index.js
CHANGED
|
@@ -144,15 +144,15 @@ function parseParameters(parameters, t) {
|
|
|
144
144
|
return parsedParameters;
|
|
145
145
|
}
|
|
146
146
|
function mapParametersToArguments(mapping, parameters, cliArguments, t) {
|
|
147
|
-
for (let
|
|
148
|
-
const { name, required, spread } = parameters[
|
|
147
|
+
for (let index = 0; index < parameters.length; index += 1) {
|
|
148
|
+
const { name, required, spread } = parameters[index];
|
|
149
149
|
const camelCaseName = camelCase(name);
|
|
150
150
|
if (camelCaseName in mapping) {
|
|
151
151
|
throw new Error(t("core.parameterIsUsedMoreThanOnce", stringify(name)));
|
|
152
152
|
}
|
|
153
|
-
const value = spread ? cliArguments.slice(
|
|
153
|
+
const value = spread ? cliArguments.slice(index) : cliArguments[index];
|
|
154
154
|
if (spread) {
|
|
155
|
-
|
|
155
|
+
index = parameters.length;
|
|
156
156
|
}
|
|
157
157
|
if (required && (!value || spread && value.length === 0)) {
|
|
158
158
|
throw new Error(t("core.missingRequiredParameter", stringify(name)));
|
|
@@ -196,11 +196,11 @@ function resolveCommand(commands, argv, t) {
|
|
|
196
196
|
const commandsMap = resolveFlattenCommands(commands, t);
|
|
197
197
|
for (const [name, command] of commandsMap.entries()) {
|
|
198
198
|
const parsed = typeFlag((_a = command == null ? void 0 : command.flags) != null ? _a : /* @__PURE__ */ Object.create(null), [...argv]);
|
|
199
|
-
const { _:
|
|
199
|
+
const { _: arguments_ } = parsed;
|
|
200
200
|
if (name === Root) {
|
|
201
201
|
continue;
|
|
202
202
|
}
|
|
203
|
-
if (arrayStartsWith(
|
|
203
|
+
if (arrayStartsWith(arguments_, name)) {
|
|
204
204
|
return [command, name];
|
|
205
205
|
}
|
|
206
206
|
}
|
|
@@ -228,16 +228,16 @@ function compose(inspectors) {
|
|
|
228
228
|
inspectorMap.normal.push(fn);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
const
|
|
231
|
+
const mergedInspectorFunctions = [
|
|
232
232
|
...inspectorMap.pre,
|
|
233
233
|
...inspectorMap.normal,
|
|
234
234
|
...inspectorMap.post
|
|
235
235
|
];
|
|
236
|
-
return (
|
|
236
|
+
return (context) => {
|
|
237
237
|
return dispatch(0);
|
|
238
|
-
function dispatch(
|
|
239
|
-
const inspector =
|
|
240
|
-
return inspector(
|
|
238
|
+
function dispatch(index) {
|
|
239
|
+
const inspector = mergedInspectorFunctions[index];
|
|
240
|
+
return inspector(context, dispatch.bind(null, index + 1));
|
|
241
241
|
}
|
|
242
242
|
};
|
|
243
243
|
}
|
|
@@ -247,7 +247,7 @@ const withBrackets = (s, isOptional) => isOptional ? `[${s}]` : `<${s}>`;
|
|
|
247
247
|
const ROOT = "<Root>";
|
|
248
248
|
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT;
|
|
249
249
|
const detectLocale = () => process.env.CLERC_LOCALE ? process.env.CLERC_LOCALE : Intl.DateTimeFormat().resolvedOptions().locale;
|
|
250
|
-
const stripFlags = (argv) => argv.filter((
|
|
250
|
+
const stripFlags = (argv) => argv.filter((argument) => !argument.startsWith("-"));
|
|
251
251
|
|
|
252
252
|
var __accessCheck = (obj, member, msg) => {
|
|
253
253
|
if (!member.has(obj))
|
|
@@ -303,10 +303,10 @@ const _Clerc = class {
|
|
|
303
303
|
add: (locales2) => {
|
|
304
304
|
__privateSet(this, _locales, defu(__privateGet(this, _locales), locales2));
|
|
305
305
|
},
|
|
306
|
-
t: (name, ...
|
|
306
|
+
t: (name, ...arguments_) => {
|
|
307
307
|
const localeObject = __privateGet(this, _locales)[__privateGet(this, _locale)] || __privateGet(this, _locales)[__privateGet(this, _defaultLocale)];
|
|
308
308
|
const defaultLocaleObject = __privateGet(this, _locales)[__privateGet(this, _defaultLocale)];
|
|
309
|
-
return localeObject[name] ? format(localeObject[name], ...
|
|
309
|
+
return localeObject[name] ? format(localeObject[name], ...arguments_) : defaultLocaleObject[name] ? format(defaultLocaleObject[name], ...arguments_) : void 0;
|
|
310
310
|
}
|
|
311
311
|
};
|
|
312
312
|
__privateSet(this, _scriptName, scriptName != null ? scriptName : __privateGet(this, _scriptName));
|
|
@@ -472,7 +472,7 @@ const _Clerc = class {
|
|
|
472
472
|
*
|
|
473
473
|
* ```ts
|
|
474
474
|
* Clerc.create().errorHandler((err) => {
|
|
475
|
-
*
|
|
475
|
+
* console.log(err);
|
|
476
476
|
* });
|
|
477
477
|
* ```
|
|
478
478
|
*
|
|
@@ -494,8 +494,8 @@ const _Clerc = class {
|
|
|
494
494
|
*
|
|
495
495
|
* ```ts
|
|
496
496
|
* Clerc.create().flag("help", "help", {
|
|
497
|
-
*
|
|
498
|
-
*
|
|
497
|
+
* alias: "h",
|
|
498
|
+
* type: Boolean,
|
|
499
499
|
* });
|
|
500
500
|
* ```
|
|
501
501
|
*
|
|
@@ -518,10 +518,10 @@ const _Clerc = class {
|
|
|
518
518
|
*
|
|
519
519
|
* ```ts
|
|
520
520
|
* Clerc.create()
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
521
|
+
* .command("test", "test command")
|
|
522
|
+
* .on("test", (ctx) => {
|
|
523
|
+
* console.log(ctx);
|
|
524
|
+
* });
|
|
525
525
|
* ```
|
|
526
526
|
*
|
|
527
527
|
* @param name
|
|
@@ -555,8 +555,8 @@ const _Clerc = class {
|
|
|
555
555
|
*
|
|
556
556
|
* ```ts
|
|
557
557
|
* Clerc.create().inspector((ctx, next) => {
|
|
558
|
-
*
|
|
559
|
-
*
|
|
558
|
+
* console.log(ctx);
|
|
559
|
+
* next();
|
|
560
560
|
* });
|
|
561
561
|
* ```
|
|
562
562
|
*
|
|
@@ -698,15 +698,15 @@ getContext_fn = function(getCommand) {
|
|
|
698
698
|
...command == null ? void 0 : command.flags
|
|
699
699
|
};
|
|
700
700
|
const parsed = typeFlag(flagsMerged, [...argv]);
|
|
701
|
-
const { _:
|
|
702
|
-
let parameters = !isCommandResolved || command.name === Root ?
|
|
701
|
+
const { _: arguments_, flags, unknownFlags } = parsed;
|
|
702
|
+
let parameters = !isCommandResolved || command.name === Root ? arguments_ : arguments_.slice(command.name.split(" ").length);
|
|
703
703
|
let commandParameters = (_a = command == null ? void 0 : command.parameters) != null ? _a : [];
|
|
704
704
|
const hasEof = commandParameters.indexOf("--");
|
|
705
705
|
const eofParameters = commandParameters.slice(hasEof + 1) || [];
|
|
706
706
|
const mapping = /* @__PURE__ */ Object.create(null);
|
|
707
707
|
if (hasEof > -1 && eofParameters.length > 0) {
|
|
708
708
|
commandParameters = commandParameters.slice(0, hasEof);
|
|
709
|
-
const eofArguments =
|
|
709
|
+
const eofArguments = arguments_["--"];
|
|
710
710
|
parameters = parameters.slice(0, -eofArguments.length || void 0);
|
|
711
711
|
mapParametersToArguments(
|
|
712
712
|
mapping,
|
|
@@ -744,16 +744,16 @@ getContext_fn = function(getCommand) {
|
|
|
744
744
|
return context;
|
|
745
745
|
};
|
|
746
746
|
_callWithErrorHandling = new WeakSet();
|
|
747
|
-
callWithErrorHandling_fn = function(
|
|
747
|
+
callWithErrorHandling_fn = function(function_) {
|
|
748
748
|
try {
|
|
749
|
-
|
|
750
|
-
} catch (
|
|
749
|
+
function_();
|
|
750
|
+
} catch (error) {
|
|
751
751
|
if (__privateGet(this, _errorHandlers).length > 0) {
|
|
752
|
-
for (const
|
|
753
|
-
|
|
752
|
+
for (const callback of __privateGet(this, _errorHandlers)) {
|
|
753
|
+
callback(error);
|
|
754
754
|
}
|
|
755
755
|
} else {
|
|
756
|
-
throw
|
|
756
|
+
throw error;
|
|
757
757
|
}
|
|
758
758
|
}
|
|
759
759
|
};
|
|
@@ -769,14 +769,14 @@ runMatchedCommand_fn = function() {
|
|
|
769
769
|
const getContext = () => __privateMethod(this, _getContext, getContext_fn).call(this, getCommand);
|
|
770
770
|
const emitHandler = {
|
|
771
771
|
enforce: "post",
|
|
772
|
-
fn: (
|
|
772
|
+
fn: (context) => {
|
|
773
773
|
const [command] = getCommand();
|
|
774
774
|
const stringName = stripFlags(argv).join(" ");
|
|
775
775
|
if (!command) {
|
|
776
776
|
const error = stringName ? new NoSuchCommandError(stringName, t) : new NoCommandGivenError(t);
|
|
777
777
|
throw error;
|
|
778
778
|
}
|
|
779
|
-
__privateGet(this, _commandEmitter).emit(command.name,
|
|
779
|
+
__privateGet(this, _commandEmitter).emit(command.name, context);
|
|
780
780
|
}
|
|
781
781
|
};
|
|
782
782
|
const inspectors = [...__privateGet(this, _inspectors), emitHandler];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc core",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"cli",
|
|
13
13
|
"terminal"
|
|
14
14
|
],
|
|
15
|
-
"homepage": "https://github.com/
|
|
15
|
+
"homepage": "https://github.com/clercjs/clerc/tree/main/packages/core#readme",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/
|
|
18
|
+
"url": "git+https://github.com/clercjs/clerc.git",
|
|
19
19
|
"directory": "/"
|
|
20
20
|
},
|
|
21
21
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/clercjs/clerc/issues"
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"sideEffects": false,
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"defu": "^6.1.2",
|
|
51
51
|
"is-platform": "^1.0.0",
|
|
52
52
|
"lite-emit": "^2.2.0",
|
|
53
|
-
"type-fest": "^
|
|
53
|
+
"type-fest": "^4.0.0",
|
|
54
54
|
"type-flag": "^3.0.0",
|
|
55
|
-
"@clerc/utils": "0.
|
|
55
|
+
"@clerc/utils": "0.42.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "pkgroll",
|