@clerc/core 0.35.0 → 0.37.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 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/dist/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
2
+ type Dict<T> = Record<string, T>;
3
+ type MaybeArray$1<T> = T | T[];
4
+ type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
5
+ type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
6
+ type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
7
+ type CamelCase<Word extends string> = Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>>) : Word;
8
+
1
9
  /**
2
10
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
3
11
 
@@ -220,14 +228,6 @@ type LiteralUnion<
220
228
  BaseType extends Primitive,
221
229
  > = LiteralType | (BaseType & Record<never, never>);
222
230
 
223
- type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
224
- type Dict<T> = Record<string, T>;
225
- type MaybeArray$1<T> = T | T[];
226
- type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
227
- type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
228
- type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
229
- type CamelCase<Word extends string> = (Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>>) : Word);
230
-
231
231
  declare const DOUBLE_DASH = "--";
232
232
  type TypeFunction<ReturnType = any> = (value: any) => ReturnType;
233
233
  type TypeFunctionArray<ReturnType> = readonly [TypeFunction<ReturnType>];
@@ -240,19 +240,17 @@ type FlagSchemaBase<TF> = {
240
240
  ```
241
241
  type: String
242
242
  ```
243
-
244
243
  @example Wrap in an array to accept multiple values.
245
244
  ```
246
245
  type: [Boolean]
247
246
  ```
248
-
249
247
  @example Custom function type that uses moment.js to parse string as date.
250
248
  ```
251
249
  type: function CustomDate(value: string) {
252
250
  return moment(value).toDate();
253
251
  }
254
252
  ```
255
- */
253
+ */
256
254
  type: TF;
257
255
  /**
258
256
  A single-character alias for the flag.
@@ -261,7 +259,7 @@ type FlagSchemaBase<TF> = {
261
259
  ```
262
260
  alias: 's'
263
261
  ```
264
- */
262
+ */
265
263
  alias?: string;
266
264
  } & Record<PropertyKey, unknown>;
267
265
  type FlagSchemaDefault<TF, DefaultType = any> = FlagSchemaBase<TF> & {
@@ -273,18 +271,17 @@ type FlagSchemaDefault<TF, DefaultType = any> = FlagSchemaBase<TF> & {
273
271
  ```
274
272
  default: 'hello'
275
273
  ```
276
-
277
274
  @example
278
275
  ```
279
276
  default: () => [1, 2, 3]
280
277
  ```
281
- */
278
+ */
282
279
  default: DefaultType | (() => DefaultType);
283
280
  };
284
- type FlagSchema<TF = FlagType> = (FlagSchemaBase<TF> | FlagSchemaDefault<TF>);
281
+ type FlagSchema<TF = FlagType> = FlagSchemaBase<TF> | FlagSchemaDefault<TF>;
285
282
  type FlagTypeOrSchema<ExtraOptions = Record<string, unknown>> = FlagType | (FlagSchema & ExtraOptions);
286
283
  type Flags$1<ExtraOptions = Record<string, unknown>> = Record<string, FlagTypeOrSchema<ExtraOptions>>;
287
- type InferFlagType<Flag extends FlagTypeOrSchema> = (Flag extends (TypeFunctionArray<infer T> | FlagSchema<TypeFunctionArray<infer T>>) ? (Flag extends FlagSchemaDefault<TypeFunctionArray<T>, infer D> ? T[] | D : T[]) : (Flag extends TypeFunction<infer T> | FlagSchema<TypeFunction<infer T>> ? (Flag extends FlagSchemaDefault<TypeFunction<T>, infer D> ? T | D : T | undefined) : never));
284
+ type InferFlagType<Flag extends FlagTypeOrSchema> = Flag extends (TypeFunctionArray<infer T> | FlagSchema<TypeFunctionArray<infer T>>) ? (Flag extends FlagSchemaDefault<TypeFunctionArray<T>, infer D> ? T[] | D : T[]) : (Flag extends TypeFunction<infer T> | FlagSchema<TypeFunction<infer T>> ? (Flag extends FlagSchemaDefault<TypeFunction<T>, infer D> ? T | D : T | undefined) : never);
288
285
  interface ParsedFlags<Schemas = Record<string, unknown>> {
289
286
  flags: Schemas;
290
287
  unknownFlags: Record<string, (string | boolean)[]>;
@@ -296,8 +293,8 @@ type TypeFlag<Schemas extends Flags$1> = ParsedFlags<{
296
293
  [flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
297
294
  }>;
298
295
 
299
- type StripBrackets<Parameter extends string> = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never);
300
- type ParameterType<Parameter extends string> = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never);
296
+ type StripBrackets<Parameter extends string> = Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never;
297
+ type ParameterType<Parameter extends string> = Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never;
301
298
  type NonNullableParameters<T extends string[] | undefined> = T extends undefined ? [] : NonNullable<T>;
302
299
  type TransformParameters<C extends Command> = {
303
300
  [Parameter in NonNullableParameters<C["parameters"]>[number] as CamelCase<StripBrackets<Parameter>>]: ParameterType<Parameter>;
@@ -315,10 +312,6 @@ type ParseRaw<C extends Command, GF extends GlobalFlagOptions = {}> = NonNullabl
315
312
  };
316
313
  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]>;
317
314
 
318
- interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
319
- setup: (cli: T) => U;
320
- }
321
-
322
315
  type Locales = Dict<Dict<string>>;
323
316
  type TranslateFn = (name: string, ...args: string[]) => string | undefined;
324
317
  interface I18N {
@@ -326,6 +319,10 @@ interface I18N {
326
319
  t: TranslateFn;
327
320
  }
328
321
 
322
+ interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
323
+ setup: (cli: T) => U;
324
+ }
325
+
329
326
  type CommandType = RootType | string;
330
327
  type FlagOptions = FlagSchema & {
331
328
  description: string;
@@ -381,7 +378,7 @@ type InspectorContext<C extends Commands = Commands> = HandlerContext<C> & {
381
378
  flags: FallbackType<TypeFlag<NonNullable<C[keyof C]["flags"]>>["flags"], Dict<any>>;
382
379
  };
383
380
  type Inspector<C extends Commands = Commands> = InspectorFn<C> | InspectorObject<C>;
384
- type InspectorFn<C extends Commands = Commands> = (ctx: InspectorContext<C>, next: () => void) => (() => void) | void;
381
+ type InspectorFn<C extends Commands = Commands> = (ctx: InspectorContext<C>, next: () => void) => void;
385
382
  interface InspectorObject<C extends Commands = Commands> {
386
383
  enforce?: "pre" | "post";
387
384
  fn: InspectorFn<C>;
@@ -401,6 +398,10 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
401
398
  get _flags(): GF;
402
399
  /**
403
400
  * Create a new cli
401
+ *
402
+ * @param name
403
+ * @param description
404
+ * @param version
404
405
  * @returns
405
406
  * @example
406
407
  * ```ts
@@ -410,6 +411,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
410
411
  static create(name?: string, description?: string, version?: string): Clerc<{}, {}>;
411
412
  /**
412
413
  * Set the name of the cli
414
+ *
413
415
  * @param name
414
416
  * @returns
415
417
  * @example
@@ -421,6 +423,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
421
423
  name(name: string): this;
422
424
  /**
423
425
  * Set the description of the cli
426
+ *
424
427
  * @param description
425
428
  * @returns
426
429
  * @example
@@ -432,6 +435,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
432
435
  description(description: string): this;
433
436
  /**
434
437
  * Set the version of the cli
438
+ *
435
439
  * @param version
436
440
  * @returns
437
441
  * @example
@@ -444,6 +448,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
444
448
  /**
445
449
  * Set the Locale
446
450
  * You must call this method once after you created the Clerc instance.
451
+ *
447
452
  * @param locale
448
453
  * @returns
449
454
  * @example
@@ -457,6 +462,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
457
462
  /**
458
463
  * Set the fallback Locale
459
464
  * You must call this method once after you created the Clerc instance.
465
+ *
460
466
  * @param fallbackLocale
461
467
  * @returns
462
468
  * @example
@@ -469,6 +475,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
469
475
  fallbackLocale(fallbackLocale: string): this;
470
476
  /**
471
477
  * Register a error handler
478
+ *
472
479
  * @param handler
473
480
  * @returns
474
481
  * @example
@@ -480,6 +487,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
480
487
  errorHandler(handler: (err: any) => void): this;
481
488
  /**
482
489
  * Register a command
490
+ *
483
491
  * @param name
484
492
  * @param description
485
493
  * @param options
@@ -514,6 +522,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
514
522
  command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags>(name: N, description: string, options?: O & CommandOptions<[...P], A, F>): this & Clerc<C & Record<N, Command<N, O>>, GF>;
515
523
  /**
516
524
  * Register a global flag
525
+ *
517
526
  * @param name
518
527
  * @param description
519
528
  * @param options
@@ -530,6 +539,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
530
539
  flag<N extends string, O extends GlobalFlagOption>(name: N, description: string, options: O): this & Clerc<C, GF & Record<N, O>>;
531
540
  /**
532
541
  * Register a handler
542
+ *
533
543
  * @param name
534
544
  * @param handler
535
545
  * @returns
@@ -545,6 +555,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
545
555
  on<K extends LiteralUnion<keyof CM, string | RootType>, CM extends this["_commands"] = this["_commands"]>(name: K, handler: Handler<CM, K, this["_flags"]>): this;
546
556
  /**
547
557
  * Use a plugin
558
+ *
548
559
  * @param plugin
549
560
  * @returns
550
561
  * @example
@@ -556,6 +567,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
556
567
  use<T extends Clerc, U extends Clerc>(plugin: Plugin<T, U>): this & Clerc<C & U["_commands"]> & U;
557
568
  /**
558
569
  * Register a inspector
570
+ *
559
571
  * @param inspector
560
572
  * @returns
561
573
  * @example
@@ -570,7 +582,9 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
570
582
  inspector(inspector: Inspector): this;
571
583
  /**
572
584
  * Parse the command line arguments
585
+ *
573
586
  * @param args
587
+ * @param optionsOrArgv
574
588
  * @returns
575
589
  * @example
576
590
  * ```ts
@@ -581,6 +595,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
581
595
  parse(optionsOrArgv?: string[] | ParseOptions): this;
582
596
  /**
583
597
  * Run matched command
598
+ *
584
599
  * @returns
585
600
  * @example
586
601
  * ```ts
@@ -592,13 +607,6 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
592
607
  runMatchedCommand(): this;
593
608
  }
594
609
 
595
- type MaybeArray<T> = T | T[];
596
-
597
- declare const definePlugin: <T extends Clerc<{}, {}>, U extends Clerc<{}, {}>>(p: Plugin<T, U>) => Plugin<T, U>;
598
- declare const defineHandler: <C extends Clerc<{}, {}>, K extends keyof C["_commands"]>(_cli: C, _key: K, handler: Handler<C["_commands"], K>) => Handler<C["_commands"], K>;
599
- declare const defineInspector: <C extends Clerc<{}, {}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
600
- 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>>;
601
-
602
610
  declare class CommandExistsError extends Error {
603
611
  commandName: string;
604
612
  constructor(commandName: string, t: TranslateFn);
@@ -632,6 +640,13 @@ declare class LocaleNotCalledFirstError extends Error {
632
640
  constructor(t: TranslateFn);
633
641
  }
634
642
 
643
+ type MaybeArray<T> = T | T[];
644
+
645
+ declare const definePlugin: <T extends Clerc<{}, {}>, U extends Clerc<{}, {}>>(p: Plugin<T, U>) => Plugin<T, U>;
646
+ declare const defineHandler: <C extends Clerc<{}, {}>, K extends keyof C["_commands"]>(_cli: C, _key: K, handler: Handler<C["_commands"], K>) => Handler<C["_commands"], K>;
647
+ declare const defineInspector: <C extends Clerc<{}, {}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
648
+ 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>>;
649
+
635
650
  declare function resolveFlattenCommands(commands: Commands, t: TranslateFn): Map<string[] | typeof Root, CommandAlias>;
636
651
  declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
637
652
  declare const resolveArgv: () => string[];
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{format as ae}from"node:util";import"@clerc/core";class Pe{constructor(){this.listenerMap={},this.wildcardListeners=new Set}on(t,s){return t==="*"?(this.wildcardListeners.add(s),this):(this.listenerMap[t]||(this.listenerMap[t]=new Set),this.listenerMap[t].add(s),this)}emit(t,...s){return this.listenerMap[t]&&(this.wildcardListeners.forEach(r=>r(t,...s)),this.listenerMap[t].forEach(r=>r(...s))),this}off(t,s){var r,n;return t==="**"?(this.listenerMap={},this.wildcardListeners.clear(),this):t==="*"?(s?this.wildcardListeners.delete(s):this.wildcardListeners.clear(),this):(s?(r=this.listenerMap[t])==null||r.delete(s):(n=this.listenerMap[t])==null||n.clear(),this)}}const Ie="known-flag",xe="unknown-flag",Re="argument",{stringify:A}=JSON,$e=/\B([A-Z])/g,qe=e=>e.replace($e,"-$1").toLowerCase(),{hasOwnProperty:Te}=Object.prototype,L=(e,t)=>Te.call(e,t),je=e=>Array.isArray(e),ie=e=>typeof e=="function"?[e,!1]:je(e)?[e[0],!0]:ie(e.type),Ge=(e,t)=>e===Boolean?t!=="false":t,He=(e,t)=>typeof t=="boolean"?t:e===Number&&t===""?Number.NaN:e(t),Ue=/[\s.:=]/,Ve=e=>{const t=`Flag name ${A(e)}`;if(e.length===0)throw new Error(`${t} cannot be empty`);if(e.length===1)throw new Error(`${t} must be longer than a character`);const s=e.match(Ue);if(s)throw new Error(`${t} cannot contain ${A(s==null?void 0:s[0])}`)},Je=e=>{const t={},s=(r,n)=>{if(L(t,r))throw new Error(`Duplicate flags named ${A(r)}`);t[r]=n};for(const r in e){if(!L(e,r))continue;Ve(r);const n=e[r],o=[[],...ie(n),n];s(r,o);const a=qe(r);if(r!==a&&s(a,o),"alias"in n&&typeof n.alias=="string"){const{alias:i}=n,c=`Flag alias ${A(i)} for flag ${A(r)}`;if(i.length===0)throw new Error(`${c} cannot be empty`);if(i.length>1)throw new Error(`${c} must be a single character`);s(i,o)}}return t},ze=(e,t)=>{const s={};for(const r in e){if(!L(e,r))continue;const[n,,o,a]=t[r];if(n.length===0&&"default"in a){let{default:i}=a;typeof i=="function"&&(i=i()),s[r]=i}else s[r]=o?n:n.pop()}return s},T="--",Ke=/[.:=]/,Ze=/^-{1,2}\w/,Qe=e=>{if(!Ze.test(e))return;const t=!e.startsWith(T);let s=e.slice(t?1:2),r;const n=s.match(Ke);if(n){const{index:o}=n;r=s.slice(o+1),s=s.slice(0,o)}return[s,r,t]},Xe=(e,{onFlag:t,onArgument:s})=>{let r;const n=(o,a)=>{if(typeof r!="function")return!0;r(o,a),r=void 0};for(let o=0;o<e.length;o+=1){const a=e[o];if(a===T){n();const c=e.slice(o+1);s==null||s(c,[o],!0);break}const i=Qe(a);if(i){if(n(),!t)continue;const[c,l,p]=i;if(p)for(let d=0;d<c.length;d+=1){n();const C=d===c.length-1;r=t(c[d],C?l:void 0,[o,d+1,C])}else r=t(c,l,[o])}else n(a,[o])&&(s==null||s([a],[o]))}n()},Ye=(e,t)=>{for(const[s,r,n]of t.reverse()){if(r){const o=e[s];let a=o.slice(0,r);if(n||(a+=o.slice(r+1)),a!=="-"){e[s]=a;continue}}e.splice(s,1)}},ce=(e,t=process.argv.slice(2),{ignore:s}={})=>{const r=[],n=Je(e),o={},a=[];return a[T]=[],Xe(t,{onFlag(i,c,l){const p=L(n,i);if(!(s!=null&&s(p?Ie:xe,i,c))){if(p){const[d,C]=n[i],y=Ge(C,c),S=(B,q)=>{r.push(l),q&&r.push(q),d.push(He(C,B||""))};return y===void 0?S:S(y)}L(o,i)||(o[i]=[]),o[i].push(c===void 0?!0:c),r.push(l)}},onArgument(i,c,l){s!=null&&s(Re,t[c[0]])||(a.push(...i),l?(a[T]=i,t.splice(c[0])):r.push(c))}}),Ye(t,r),{flags:ze(e,n),unknownFlags:o,_:a}};function H(e){return e!==null&&typeof e=="object"}function U(e,t,s=".",r){if(!H(t))return U(e,{},s,r);const n=Object.assign({},t);for(const o in e){if(o==="__proto__"||o==="constructor")continue;const a=e[o];a!=null&&(r&&r(n,o,a,s)||(Array.isArray(a)&&Array.isArray(n[o])?n[o]=[...a,...n[o]]:H(a)&&H(n[o])?n[o]=U(a,n[o],(s?`${s}.`:"")+o.toString(),r):n[o]=a))}return n}function et(e){return(...t)=>t.reduce((s,r)=>U(s,r,"",e),{})}const tt=et(),ue=e=>Array.isArray(e)?e:[e],st=e=>e.replace(/[\W_]([a-z\d])?/gi,(t,s)=>s?s.toUpperCase():""),rt=(e,t)=>t.length!==e.length?!1:e.every((s,r)=>s===t[r]),ot=(e,t)=>t.length>e.length?!1:rt(e.slice(0,t.length),t),W=JSON.stringify;class le extends Error{constructor(t,s){super(s("core.commandExists",W(t))),this.commandName=t}}class he extends Error{constructor(t,s){super(s("core.noSuchCommand",W(t))),this.commandName=t}}class de extends Error{constructor(t){super(t("core.noCommandGiven"))}}class fe extends Error{constructor(t,s,r){super(r("core.commandNameConflict",W(t),W(s))),this.n1=t,this.n2=s}}class me extends Error{constructor(t){super(t("core.nameNotSet"))}}class pe extends Error{constructor(t){super(t("core.descriptionNotSet"))}}class Ce extends Error{constructor(t){super(t("core.versionNotSet"))}}class we extends Error{constructor(t,s){super(s("core.badNameFormat",W(t))),this.commandName=t}}class V extends Error{constructor(t){super(t("core.localeMustBeCalledFirst"))}}const ge=typeof Deno!="undefined",nt=typeof process!="undefined"&&!ge,at=process.versions.electron&&!process.defaultApp;function Ee(e,t,s,r){if(s.alias){const n=ue(s.alias);for(const o of n){if(o in t)throw new fe(t[o].name,s.name,r);e.set(typeof o=="symbol"?o:o.split(" "),{...s,__isAlias:!0})}}}function _e(e,t){const s=new Map;e[m]&&(s.set(m,e[m]),Ee(s,e,e[m],t));for(const r of Object.values(e))Ee(s,e,r,t),s.set(r.name.split(" "),r);return s}function ve(e,t,s){const r=_e(e,s);for(const[n,o]of r.entries()){const a=ce((o==null?void 0:o.flags)||{},[...t]),{_:i}=a;if(n!==m&&ot(i,n))return[o,n]}return r.has(m)?[r.get(m),m]:[void 0,void 0]}const J=()=>nt?process.argv.slice(at?1:2):ge?Deno.args:[];function Me(e){const t={pre:[],normal:[],post:[]};for(const r of e){const n=typeof r=="object"?r:{fn:r},{enforce:o,fn:a}=n;o==="post"||o==="pre"?t[o].push(a):t.normal.push(a)}const s=[...t.pre,...t.normal,...t.post];return r=>{const n=[];let o=0;const a=i=>{o=i;const c=s[i],l=c(r,a.bind(null,i+1));l&&n.push(l)};if(a(0),o+1===s.length)for(const i of n)i()}}const it=/\s\s+/,Fe=e=>e===m?!0:!(e.startsWith(" ")||e.endsWith(" "))&&!it.test(e),ct=(e,t)=>t?`[${e}]`:`<${e}>`,ut="<Root>",ye=e=>Array.isArray(e)?e.join(" "):typeof e=="string"?e:ut,Be=()=>process.env.CLERC_LOCALE?process.env.CLERC_LOCALE:Intl.DateTimeFormat().resolvedOptions().locale,Ne=e=>e.filter(t=>!t.startsWith("-")),{stringify:N}=JSON;function z(e,t){const s=[];let r,n;for(const o of e){if(n)throw new Error(t("core.spreadParameterMustBeLast",N(n)));const a=o[0],i=o[o.length-1];let c;if(a==="<"&&i===">"&&(c=!0,r))throw new Error(t("core.requiredParameterMustBeBeforeOptional",N(o),N(r)));if(a==="["&&i==="]"&&(c=!1,r=o),c===void 0)throw new Error(t("core.parameterMustBeWrappedInBrackets",N(o)));let l=o.slice(1,-1);const p=l.slice(-3)==="...";p&&(n=o,l=l.slice(0,-3)),s.push({name:l,required:c,spread:p})}return s}function K(e,t,s,r){for(let n=0;n<t.length;n+=1){const{name:o,required:a,spread:i}=t[n],c=st(o);if(c in e)throw new Error(r("core.parameterIsUsedMoreThanOnce",N(o)));const l=i?s.slice(n):s[n];if(i&&(n=t.length),a&&(!l||i&&l.length===0))throw new Error(r("core.missingRequiredParameter",N(o)));e[c]=l}}const lt={en:{"core.commandExists":'Command "%s" exists.',"core.noSuchCommand":"No such command: %s.","core.noCommandGiven":"No command given.","core.commandNameConflict":"Command name %s conflicts with %s. Maybe caused by alias.","core.nameNotSet":"Name not set.","core.descriptionNotSet":"Description not set.","core.versionNotSet":"Version not set.","core.badNameFormat":"Bad name format: %s.","core.localeMustBeCalledFirst":"locale() or fallbackLocale() must be called at first.","core.cliParseMustBeCalled":"cli.parse() must be called.","core.spreadParameterMustBeLast":"Invalid Parameter: Spread parameter %s must be last.","core.requiredParameterCannotComeAfterOptionalParameter":"Invalid Parameter: Required parameter %s cannot come after optional parameter %s.","core.parameterMustBeWrappedInBrackets":"Invalid Parameter: Parameter %s must be wrapped in <> (required parameter) or [] (optional parameter).","core.parameterIsUsedMoreThanOnce":"Invalid Parameter: Parameter %s is used more than once.","core.missingRequiredParameter":"Missing required parameter %s."},"zh-CN":{"core.commandExists":'\u547D\u4EE4 "%s" \u5DF2\u5B58\u5728\u3002',"core.noSuchCommand":"\u627E\u4E0D\u5230\u547D\u4EE4: %s\u3002","core.noCommandGiven":"\u6CA1\u6709\u8F93\u5165\u547D\u4EE4\u3002","core.commandNameConflict":"\u547D\u4EE4\u540D\u79F0 %s \u548C %s \u51B2\u7A81\u3002 \u53EF\u80FD\u662F\u7531\u4E8E\u522B\u540D\u5BFC\u81F4\u7684\u3002","core.nameNotSet":"\u672A\u8BBE\u7F6ECLI\u540D\u79F0\u3002","core.descriptionNotSet":"\u672A\u8BBE\u7F6ECLI\u63CF\u8FF0\u3002","core.versionNotSet":"\u672A\u8BBE\u7F6ECLI\u7248\u672C\u3002","core.badNameFormat":"\u9519\u8BEF\u7684\u547D\u4EE4\u540D\u5B57\u683C\u5F0F: %s\u3002","core.localeMustBeCalledFirst":"locale() \u6216 fallbackLocale() \u5FC5\u987B\u5728\u6700\u5F00\u59CB\u8C03\u7528\u3002","core.cliParseMustBeCalled":"cli.parse() \u5FC5\u987B\u88AB\u8C03\u7528\u3002","core.spreadParameterMustBeLast":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5C55\u5F00\u53C2\u6570 %s \u5FC5\u987B\u5728\u6700\u540E\u3002","core.requiredParameterCannotComeAfterOptionalParameter":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5FC5\u586B\u53C2\u6570 %s \u4E0D\u80FD\u5728\u53EF\u9009\u53C2\u6570 %s \u4E4B\u540E\u3002","core.parameterMustBeWrappedInBrackets":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u5FC5\u987B\u88AB <> (\u5FC5\u586B\u53C2\u6570) \u6216 [] (\u53EF\u9009\u53C2\u6570) \u5305\u88F9\u3002","core.parameterIsUsedMoreThanOnce":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u88AB\u4F7F\u7528\u4E86\u591A\u6B21\u3002","core.missingRequiredParameter":"\u7F3A\u5C11\u5FC5\u586B\u53C2\u6570 %s\u3002"}};var Z=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},u=(e,t,s)=>(Z(e,t,"read from private field"),s?s.call(e):t.get(e)),h=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},w=(e,t,s,r)=>(Z(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),f=(e,t,s)=>(Z(e,t,"access private method"),s),_,v,M,D,b,j,O,k,P,I,x,R,$,F,Q,ke,X,Se,Y,Ae,g,E,ee,Le,te,We,se,De,G,re,oe,be;const m=Symbol.for("Clerc.Root"),Oe=class{constructor(e,t,s){h(this,Q),h(this,X),h(this,Y),h(this,g),h(this,ee),h(this,te),h(this,se),h(this,G),h(this,oe),h(this,_,""),h(this,v,""),h(this,M,""),h(this,D,[]),h(this,b,{}),h(this,j,new Pe),h(this,O,{}),h(this,k,new Set),h(this,P,void 0),h(this,I,[]),h(this,x,!1),h(this,R,"en"),h(this,$,"en"),h(this,F,{}),this.i18n={add:r=>{w(this,F,tt(u(this,F),r))},t:(r,...n)=>{const o=u(this,F)[u(this,$)]||u(this,F)[u(this,R)],a=u(this,F)[u(this,R)];return o[r]?ae(o[r],...n):a[r]?ae(a[r],...n):void 0}},w(this,_,e||u(this,_)),w(this,v,t||u(this,v)),w(this,M,s||u(this,M)),w(this,$,Be()),f(this,Y,Ae).call(this)}get _name(){return u(this,_)}get _description(){return u(this,v)}get _version(){return u(this,M)}get _inspectors(){return u(this,D)}get _commands(){return u(this,b)}get _flags(){return u(this,O)}static create(e,t,s){return new Oe(e,t,s)}name(e){return f(this,g,E).call(this),w(this,_,e),this}description(e){return f(this,g,E).call(this),w(this,v,e),this}version(e){return f(this,g,E).call(this),w(this,M,e),this}locale(e){if(u(this,x))throw new V(this.i18n.t);return w(this,$,e),this}fallbackLocale(e){if(u(this,x))throw new V(this.i18n.t);return w(this,R,e),this}errorHandler(e){return u(this,I).push(e),this}command(e,t,s={}){return f(this,G,re).call(this,()=>f(this,ee,Le).call(this,e,t,s)),this}flag(e,t,s){return u(this,O)[e]={description:t,...s},this}on(e,t){return u(this,j).on(e,t),this}use(e){return f(this,g,E).call(this),e.setup(this)}inspector(e){return f(this,g,E).call(this),u(this,D).push(e),this}parse(e=J()){f(this,g,E).call(this);const{argv:t,run:s}=Array.isArray(e)?{argv:e,run:!0}:{argv:J(),...e};return w(this,P,[...t]),f(this,te,We).call(this),s&&this.runMatchedCommand(),this}runMatchedCommand(){return f(this,G,re).call(this,()=>f(this,oe,be).call(this)),process.title=u(this,_),this}};let ht=Oe;_=new WeakMap,v=new WeakMap,M=new WeakMap,D=new WeakMap,b=new WeakMap,j=new WeakMap,O=new WeakMap,k=new WeakMap,P=new WeakMap,I=new WeakMap,x=new WeakMap,R=new WeakMap,$=new WeakMap,F=new WeakMap,Q=new WeakSet,ke=function(){return u(this,k).has(m)},X=new WeakSet,Se=function(){return Object.prototype.hasOwnProperty.call(this._commands,m)},Y=new WeakSet,Ae=function(){this.i18n.add(lt)},g=new WeakSet,E=function(){w(this,x,!0)},ee=new WeakSet,Le=function(e,t,s={}){f(this,g,E).call(this);const{t:r}=this.i18n,o=(d=>!(typeof d=="string"||d===m))(e),a=o?e.name:e;if(!Fe(a))throw new we(a,r);const{handler:i=void 0,...c}=o?e:{name:a,description:t,...s},l=[c.name],p=c.alias?ue(c.alias):[];c.alias&&l.push(...p);for(const d of l)if(u(this,k).has(d))throw new le(ye(d),r);return u(this,b)[a]=c,u(this,k).add(c.name),p.forEach(d=>u(this,k).add(d)),o&&i&&this.on(e.name,i),this},te=new WeakSet,We=function(){const{t:e}=this.i18n;if(!u(this,_))throw new me(e);if(!u(this,v))throw new pe(e);if(!u(this,M))throw new Ce(e)},se=new WeakSet,De=function(e){const t=u(this,P),{t:s}=this.i18n,[r,n]=e(),o=!!r,a={...u(this,O),...r==null?void 0:r.flags},i=ce(a,[...t]),{_:c,flags:l,unknownFlags:p}=i;let d=!o||r.name===m?c:c.slice(r.name.split(" ").length),C=(r==null?void 0:r.parameters)||[];const y=C.indexOf("--"),S=C.slice(y+1)||[],B=Object.create(null);if(y>-1&&S.length>0){C=C.slice(0,y);const ne=c["--"];d=d.slice(0,-ne.length||void 0),K(B,z(C,s),d,s),K(B,z(S,s),ne,s)}else K(B,z(C,s),d,s);const q={...l,...p};return{name:r==null?void 0:r.name,called:Array.isArray(n)?n.join(" "):n,resolved:o,hasRootOrAlias:u(this,Q,ke),hasRoot:u(this,X,Se),raw:{...i,parameters:d,mergedFlags:q},parameters:B,flags:l,unknownFlags:p,cli:this}},G=new WeakSet,re=function(e){try{e()}catch(t){if(u(this,I).length>0)u(this,I).forEach(s=>s(t));else throw t}},oe=new WeakSet,be=function(){f(this,g,E).call(this);const{t:e}=this.i18n,t=u(this,P);if(!t)throw new Error(e("core.cliParseMustBeCalled"));const s=()=>ve(u(this,b),t,e),r=()=>f(this,se,De).call(this,s),n={enforce:"post",fn:i=>{const[c]=s(),l=Ne(t).join(" ");if(!c)throw l?new he(l,e):new de(e);u(this,j).emit(c.name,i)}},o=[...u(this,D),n];Me(o)(r())};const dt=e=>e,ft=(e,t,s)=>s,mt=(e,t)=>t,pt=(e,t)=>({...e,handler:t});export{ht as Clerc,le as CommandExistsError,fe as CommandNameConflictError,pe as DescriptionNotSetError,we as InvalidCommandNameError,V as LocaleNotCalledFirstError,me as NameNotSetError,de as NoCommandGivenError,he as NoSuchCommandError,m as Root,Ce as VersionNotSetError,Me as compose,pt as defineCommand,ft as defineHandler,mt as defineInspector,dt as definePlugin,Be as detectLocale,ye as formatCommandName,Fe as isValidName,J as resolveArgv,ve as resolveCommand,_e as resolveFlattenCommands,Ne as stripFlags,ct as withBrackets};
1
+ import{format as ae}from"node:util";import"@clerc/core";const ie=e=>Array.isArray(e)?e:[e],be=e=>e.replace(/[\W_]([a-z\d])?/gi,(t,s)=>s?s.toUpperCase():""),xe=(e,t)=>t.length!==e.length?!1:e.every((s,r)=>s===t[r]),Re=(e,t)=>t.length>e.length?!1:xe(e.slice(0,t.length),t);function H(e){return e!==null&&typeof e=="object"}function U(e,t,s=".",r){if(!H(t))return U(e,{},s,r);const n=Object.assign({},t);for(const o in e){if(o==="__proto__"||o==="constructor")continue;const a=e[o];a!=null&&(r&&r(n,o,a,s)||(Array.isArray(a)&&Array.isArray(n[o])?n[o]=[...a,...n[o]]:H(a)&&H(n[o])?n[o]=U(a,n[o],(s?`${s}.`:"")+o.toString(),r):n[o]=a))}return n}function $e(e){return(...t)=>t.reduce((s,r)=>U(s,r,"",e),{})}const qe=$e();class Te{constructor(){this.listenerMap={},this.wildcardListeners=new Set}on(t,s){return t==="*"?(this.wildcardListeners.add(s),this):(this.listenerMap[t]||(this.listenerMap[t]=new Set),this.listenerMap[t].add(s),this)}emit(t,...s){return this.listenerMap[t]&&(this.wildcardListeners.forEach(r=>r.apply(null,[t,...s])),this.listenerMap[t].forEach(r=>r(...s))),this}off(t,s){var r,n;return t===void 0?(this.listenerMap={},this.wildcardListeners.clear(),this):t==="*"?(s?this.wildcardListeners.delete(s):this.wildcardListeners.clear(),this):(s?(r=this.listenerMap[t])==null||r.delete(s):(n=this.listenerMap[t])==null||n.clear(),this)}}const je="known-flag",Ge="unknown-flag",He="argument",{stringify:A}=JSON,Ue=/\B([A-Z])/g,Ve=e=>e.replace(Ue,"-$1").toLowerCase(),{hasOwnProperty:Je}=Object.prototype,L=(e,t)=>Je.call(e,t),ze=e=>Array.isArray(e),ce=e=>typeof e=="function"?[e,!1]:ze(e)?[e[0],!0]:ce(e.type),Ke=(e,t)=>e===Boolean?t!=="false":t,Ze=(e,t)=>typeof t=="boolean"?t:e===Number&&t===""?Number.NaN:e(t),Qe=/[\s.:=]/,Xe=e=>{const t=`Flag name ${A(e)}`;if(e.length===0)throw new Error(`${t} cannot be empty`);if(e.length===1)throw new Error(`${t} must be longer than a character`);const s=e.match(Qe);if(s)throw new Error(`${t} cannot contain ${A(s==null?void 0:s[0])}`)},Ye=e=>{const t={},s=(r,n)=>{if(L(t,r))throw new Error(`Duplicate flags named ${A(r)}`);t[r]=n};for(const r in e){if(!L(e,r))continue;Xe(r);const n=e[r],o=[[],...ce(n),n];s(r,o);const a=Ve(r);if(r!==a&&s(a,o),"alias"in n&&typeof n.alias=="string"){const{alias:u}=n,i=`Flag alias ${A(u)} for flag ${A(r)}`;if(u.length===0)throw new Error(`${i} cannot be empty`);if(u.length>1)throw new Error(`${i} must be a single character`);s(u,o)}}return t},et=(e,t)=>{const s={};for(const r in e){if(!L(e,r))continue;const[n,,o,a]=t[r];if(n.length===0&&"default"in a){let{default:u}=a;typeof u=="function"&&(u=u()),s[r]=u}else s[r]=o?n:n.pop()}return s},T="--",tt=/[.:=]/,st=/^-{1,2}\w/,rt=e=>{if(!st.test(e))return;const t=!e.startsWith(T);let s=e.slice(t?1:2),r;const n=s.match(tt);if(n){const{index:o}=n;r=s.slice(o+1),s=s.slice(0,o)}return[s,r,t]},ot=(e,{onFlag:t,onArgument:s})=>{let r;const n=(o,a)=>{if(typeof r!="function")return!0;r(o,a),r=void 0};for(let o=0;o<e.length;o+=1){const a=e[o];if(a===T){n();const i=e.slice(o+1);s==null||s(i,[o],!0);break}const u=rt(a);if(u){if(n(),!t)continue;const[i,l,m]=u;if(m)for(let d=0;d<i.length;d+=1){n();const w=d===i.length-1;r=t(i[d],w?l:void 0,[o,d+1,w])}else r=t(i,l,[o])}else n(a,[o])&&(s==null||s([a],[o]))}n()},nt=(e,t)=>{for(const[s,r,n]of t.reverse()){if(r){const o=e[s];let a=o.slice(0,r);if(n||(a+=o.slice(r+1)),a!=="-"){e[s]=a;continue}}e.splice(s,1)}},ue=(e,t=process.argv.slice(2),{ignore:s}={})=>{const r=[],n=Ye(e),o={},a=[];return a[T]=[],ot(t,{onFlag(u,i,l){const m=L(n,u);if(!(s!=null&&s(m?je:Ge,u,i))){if(m){const[d,w]=n[u],E=Ke(w,i),N=(q,M)=>{r.push(l),M&&r.push(M),d.push(Ze(w,q||""))};return E===void 0?N:N(E)}L(o,u)||(o[u]=[]),o[u].push(i===void 0?!0:i),r.push(l)}},onArgument(u,i,l){s!=null&&s(He,t[i[0]])||(a.push(...u),l?(a[T]=u,t.splice(i[0])):r.push(i))}}),nt(t,r),{flags:et(e,n),unknownFlags:o,_:a}},W=JSON.stringify;class le extends Error{constructor(t,s){super(s("core.commandExists",W(t))),this.commandName=t}}class he extends Error{constructor(t,s){super(s("core.noSuchCommand",W(t))),this.commandName=t}}class de extends Error{constructor(t){super(t("core.noCommandGiven"))}}class fe extends Error{constructor(t,s,r){super(r("core.commandNameConflict",W(t),W(s))),this.n1=t,this.n2=s}}class pe extends Error{constructor(t){super(t("core.nameNotSet"))}}class me extends Error{constructor(t){super(t("core.descriptionNotSet"))}}class Ce extends Error{constructor(t){super(t("core.versionNotSet"))}}class we extends Error{constructor(t,s){super(s("core.badNameFormat",W(t))),this.commandName=t}}class V extends Error{constructor(t){super(t("core.localeMustBeCalledFirst"))}}const at={en:{"core.commandExists":'Command "%s" exists.',"core.noSuchCommand":"No such command: %s.","core.noCommandGiven":"No command given.","core.commandNameConflict":"Command name %s conflicts with %s. Maybe caused by alias.","core.nameNotSet":"Name not set.","core.descriptionNotSet":"Description not set.","core.versionNotSet":"Version not set.","core.badNameFormat":"Bad name format: %s.","core.localeMustBeCalledFirst":"locale() or fallbackLocale() must be called at first.","core.cliParseMustBeCalled":"cli.parse() must be called.","core.spreadParameterMustBeLast":"Invalid Parameter: Spread parameter %s must be last.","core.requiredParameterCannotComeAfterOptionalParameter":"Invalid Parameter: Required parameter %s cannot come after optional parameter %s.","core.parameterMustBeWrappedInBrackets":"Invalid Parameter: Parameter %s must be wrapped in <> (required parameter) or [] (optional parameter).","core.parameterIsUsedMoreThanOnce":"Invalid Parameter: Parameter %s is used more than once.","core.missingRequiredParameter":"Missing required parameter %s."},"zh-CN":{"core.commandExists":'\u547D\u4EE4 "%s" \u5DF2\u5B58\u5728\u3002',"core.noSuchCommand":"\u627E\u4E0D\u5230\u547D\u4EE4: %s\u3002","core.noCommandGiven":"\u6CA1\u6709\u8F93\u5165\u547D\u4EE4\u3002","core.commandNameConflict":"\u547D\u4EE4\u540D\u79F0 %s \u548C %s \u51B2\u7A81\u3002 \u53EF\u80FD\u662F\u7531\u4E8E\u522B\u540D\u5BFC\u81F4\u7684\u3002","core.nameNotSet":"\u672A\u8BBE\u7F6ECLI\u540D\u79F0\u3002","core.descriptionNotSet":"\u672A\u8BBE\u7F6ECLI\u63CF\u8FF0\u3002","core.versionNotSet":"\u672A\u8BBE\u7F6ECLI\u7248\u672C\u3002","core.badNameFormat":"\u9519\u8BEF\u7684\u547D\u4EE4\u540D\u5B57\u683C\u5F0F: %s\u3002","core.localeMustBeCalledFirst":"locale() \u6216 fallbackLocale() \u5FC5\u987B\u5728\u6700\u5F00\u59CB\u8C03\u7528\u3002","core.cliParseMustBeCalled":"cli.parse() \u5FC5\u987B\u88AB\u8C03\u7528\u3002","core.spreadParameterMustBeLast":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5C55\u5F00\u53C2\u6570 %s \u5FC5\u987B\u5728\u6700\u540E\u3002","core.requiredParameterCannotComeAfterOptionalParameter":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5FC5\u586B\u53C2\u6570 %s \u4E0D\u80FD\u5728\u53EF\u9009\u53C2\u6570 %s \u4E4B\u540E\u3002","core.parameterMustBeWrappedInBrackets":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u5FC5\u987B\u88AB <> (\u5FC5\u586B\u53C2\u6570) \u6216 [] (\u53EF\u9009\u53C2\u6570) \u5305\u88F9\u3002","core.parameterIsUsedMoreThanOnce":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u88AB\u4F7F\u7528\u4E86\u591A\u6B21\u3002","core.missingRequiredParameter":"\u7F3A\u5C11\u5FC5\u586B\u53C2\u6570 %s\u3002"}},{stringify:k}=JSON;function J(e,t){const s=[];let r,n;for(const o of e){if(n)throw new Error(t("core.spreadParameterMustBeLast",k(n)));const a=o[0],u=o[o.length-1];let i;if(a==="<"&&u===">"&&(i=!0,r))throw new Error(t("core.requiredParameterMustBeBeforeOptional",k(o),k(r)));if(a==="["&&u==="]"&&(i=!1,r=o),i===void 0)throw new Error(t("core.parameterMustBeWrappedInBrackets",k(o)));let l=o.slice(1,-1);const m=l.slice(-3)==="...";m&&(n=o,l=l.slice(0,-3)),s.push({name:l,required:i,spread:m})}return s}function z(e,t,s,r){for(let n=0;n<t.length;n+=1){const{name:o,required:a,spread:u}=t[n],i=be(o);if(i in e)throw new Error(r("core.parameterIsUsedMoreThanOnce",k(o)));const l=u?s.slice(n):s[n];if(u&&(n=t.length),a&&(!l||u&&l.length===0))throw new Error(r("core.missingRequiredParameter",k(o)));e[i]=l}}const ge=typeof Deno!="undefined",it=typeof process!="undefined"&&!ge,ct=process.versions.electron&&!process.defaultApp;function Ee(e,t,s,r){if(s.alias){const n=ie(s.alias);for(const o of n){if(o in t)throw new fe(t[o].name,s.name,r);e.set(typeof o=="symbol"?o:o.split(" "),{...s,__isAlias:!0})}}}function _e(e,t){const s=new Map;e[p]&&(s.set(p,e[p]),Ee(s,e,e[p],t));for(const r of Object.values(e))Ee(s,e,r,t),s.set(r.name.split(" "),r);return s}function ve(e,t,s){var r;const n=_e(e,s);for(const[o,a]of n.entries()){const u=ue((r=a==null?void 0:a.flags)!=null?r:{},[...t]),{_:i}=u;if(o!==p&&Re(i,o))return[a,o]}return n.has(p)?[n.get(p),p]:[void 0,void 0]}const K=()=>it?process.argv.slice(ct?1:2):ge?Deno.args:[];function Me(e){const t={pre:[],normal:[],post:[]};for(const r of e){const n=typeof r=="object"?r:{fn:r},{enforce:o,fn:a}=n;o==="post"||o==="pre"?t[o].push(a):t.normal.push(a)}const s=[...t.pre,...t.normal,...t.post];return r=>{return n(0);function n(o){const a=s[o];return a(r,n.bind(null,o+1))}}}const ut=/\s\s+/,Fe=e=>e===p?!0:!(e.startsWith(" ")||e.endsWith(" "))&&!ut.test(e),lt=(e,t)=>t?`[${e}]`:`<${e}>`,ht="<Root>",ye=e=>Array.isArray(e)?e.join(" "):typeof e=="string"?e:ht,Be=()=>process.env.CLERC_LOCALE?process.env.CLERC_LOCALE:Intl.DateTimeFormat().resolvedOptions().locale,Ne=e=>e.filter(t=>!t.startsWith("-"));var Z=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},c=(e,t,s)=>(Z(e,t,"read from private field"),s?s.call(e):t.get(e)),h=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},C=(e,t,s,r)=>(Z(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),f=(e,t,s)=>(Z(e,t,"access private method"),s),v,F,y,D,O,j,P,S,I,b,x,R,$,B,Q,ke,X,Se,Y,Ae,g,_,ee,Le,te,We,se,De,G,re,oe,Oe;const p=Symbol.for("Clerc.Root"),Pe=class{constructor(e,t,s){h(this,Q),h(this,X),h(this,Y),h(this,g),h(this,ee),h(this,te),h(this,se),h(this,G),h(this,oe),h(this,v,""),h(this,F,""),h(this,y,""),h(this,D,[]),h(this,O,{}),h(this,j,new Te),h(this,P,{}),h(this,S,new Set),h(this,I,void 0),h(this,b,[]),h(this,x,!1),h(this,R,"en"),h(this,$,"en"),h(this,B,{}),this.i18n={add:r=>{C(this,B,qe(c(this,B),r))},t:(r,...n)=>{const o=c(this,B)[c(this,$)]||c(this,B)[c(this,R)],a=c(this,B)[c(this,R)];return o[r]?ae(o[r],...n):a[r]?ae(a[r],...n):void 0}},C(this,v,e!=null?e:c(this,v)),C(this,F,t!=null?t:c(this,F)),C(this,y,s!=null?s:c(this,y)),C(this,$,Be()),f(this,Y,Ae).call(this)}get _name(){return c(this,v)}get _description(){return c(this,F)}get _version(){return c(this,y)}get _inspectors(){return c(this,D)}get _commands(){return c(this,O)}get _flags(){return c(this,P)}static create(e,t,s){return new Pe(e,t,s)}name(e){return f(this,g,_).call(this),C(this,v,e),this}description(e){return f(this,g,_).call(this),C(this,F,e),this}version(e){return f(this,g,_).call(this),C(this,y,e),this}locale(e){if(c(this,x))throw new V(this.i18n.t);return C(this,$,e),this}fallbackLocale(e){if(c(this,x))throw new V(this.i18n.t);return C(this,R,e),this}errorHandler(e){return c(this,b).push(e),this}command(e,t,s={}){return f(this,G,re).call(this,()=>f(this,ee,Le).call(this,e,t,s)),this}flag(e,t,s){return c(this,P)[e]={description:t,...s},this}on(e,t){return c(this,j).on(e,t),this}use(e){return f(this,g,_).call(this),e.setup(this)}inspector(e){return f(this,g,_).call(this),c(this,D).push(e),this}parse(e=K()){f(this,g,_).call(this);const{argv:t,run:s}=Array.isArray(e)?{argv:e,run:!0}:{argv:K(),...e};return C(this,I,[...t]),f(this,te,We).call(this),s&&this.runMatchedCommand(),this}runMatchedCommand(){return f(this,G,re).call(this,()=>f(this,oe,Oe).call(this)),process.title=c(this,v),this}};let dt=Pe;v=new WeakMap,F=new WeakMap,y=new WeakMap,D=new WeakMap,O=new WeakMap,j=new WeakMap,P=new WeakMap,S=new WeakMap,I=new WeakMap,b=new WeakMap,x=new WeakMap,R=new WeakMap,$=new WeakMap,B=new WeakMap,Q=new WeakSet,ke=function(){return c(this,S).has(p)},X=new WeakSet,Se=function(){return Object.prototype.hasOwnProperty.call(this._commands,p)},Y=new WeakSet,Ae=function(){this.i18n.add(at)},g=new WeakSet,_=function(){C(this,x,!0)},ee=new WeakSet,Le=function(e,t,s={}){f(this,g,_).call(this);const{t:r}=this.i18n,o=(d=>!(typeof d=="string"||d===p))(e),a=o?e.name:e;if(!Fe(a))throw new we(a,r);const{handler:u=void 0,...i}=o?e:{name:a,description:t,...s},l=[i.name],m=i.alias?ie(i.alias):[];i.alias&&l.push(...m);for(const d of l)if(c(this,S).has(d))throw new le(ye(d),r);return c(this,O)[a]=i,c(this,S).add(i.name),m.forEach(d=>c(this,S).add(d)),o&&u&&this.on(e.name,u),this},te=new WeakSet,We=function(){const{t:e}=this.i18n;if(!c(this,v))throw new pe(e);if(!c(this,F))throw new me(e);if(!c(this,y))throw new Ce(e)},se=new WeakSet,De=function(e){var t;const s=c(this,I),{t:r}=this.i18n,[n,o]=e(),a=!!n,u={...c(this,P),...n==null?void 0:n.flags},i=ue(u,[...s]),{_:l,flags:m,unknownFlags:d}=i;let w=!a||n.name===p?l:l.slice(n.name.split(" ").length),E=(t=n==null?void 0:n.parameters)!=null?t:[];const N=E.indexOf("--"),q=E.slice(N+1)||[],M=Object.create(null);if(N>-1&&q.length>0){E=E.slice(0,N);const ne=l["--"];w=w.slice(0,-ne.length||void 0),z(M,J(E,r),w,r),z(M,J(q,r),ne,r)}else z(M,J(E,r),w,r);const Ie={...m,...d};return{name:n==null?void 0:n.name,called:Array.isArray(o)?o.join(" "):o,resolved:a,hasRootOrAlias:c(this,Q,ke),hasRoot:c(this,X,Se),raw:{...i,parameters:w,mergedFlags:Ie},parameters:M,flags:m,unknownFlags:d,cli:this}},G=new WeakSet,re=function(e){try{e()}catch(t){if(c(this,b).length>0)c(this,b).forEach(s=>s(t));else throw t}},oe=new WeakSet,Oe=function(){f(this,g,_).call(this);const{t:e}=this.i18n,t=c(this,I);if(!t)throw new Error(e("core.cliParseMustBeCalled"));const s=()=>ve(c(this,O),t,e),r=()=>f(this,se,De).call(this,s),n={enforce:"post",fn:u=>{const[i]=s(),l=Ne(t).join(" ");if(!i)throw l?new he(l,e):new de(e);c(this,j).emit(i.name,u)}},o=[...c(this,D),n];Me(o)(r())};const ft=e=>e,pt=(e,t,s)=>s,mt=(e,t)=>t,Ct=(e,t)=>({...e,handler:t});export{dt as Clerc,le as CommandExistsError,fe as CommandNameConflictError,me as DescriptionNotSetError,we as InvalidCommandNameError,V as LocaleNotCalledFirstError,pe as NameNotSetError,de as NoCommandGivenError,he as NoSuchCommandError,p as Root,Ce as VersionNotSetError,Me as compose,Ct as defineCommand,pt as defineHandler,mt as defineInspector,ft as definePlugin,Be as detectLocale,ye as formatCommandName,Fe as isValidName,K as resolveArgv,ve as resolveCommand,_e as resolveFlattenCommands,Ne as stripFlags,lt as withBrackets};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/core",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "description": "Clerc core",
6
6
  "keywords": [
@@ -49,10 +49,10 @@
49
49
  "devDependencies": {
50
50
  "defu": "^6.1.2",
51
51
  "is-platform": "^1.0.0",
52
- "lite-emit": "^1.4.0",
53
- "type-fest": "^3.6.0",
52
+ "lite-emit": "^2.0.0",
53
+ "type-fest": "^3.8.0",
54
54
  "type-flag": "^3.0.0",
55
- "@clerc/utils": "0.35.0"
55
+ "@clerc/utils": "0.37.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "puild --minify",