clerc 0.3.3 → 0.3.4

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/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ var liteEmit = require('lite-emit');
6
6
  var mri = require('mri');
7
7
  var typeFlag = require('type-flag');
8
8
  var isPlatform = require('is-platform');
9
+ var utils = require('@clerc/utils');
9
10
 
10
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
12
 
@@ -20,13 +21,10 @@ class CommonCommandExistsError extends Error {
20
21
  class NoSuchCommandError extends Error {
21
22
  }
22
23
 
23
- const mustArray = (a) => Array.isArray(a) ? a : [a];
24
- const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
25
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
26
24
  const resolveFlagAlias = (_command) => Object.entries((_command == null ? void 0 : _command.flags) || {}).reduce((acc, [name, command]) => {
27
25
  if (command.alias) {
28
- const item = mustArray(command.alias).map(kebabCase);
29
- acc[kebabCase(name)] = item;
26
+ const item = utils.mustArray(command.alias).map(utils.kebabCase);
27
+ acc[utils.kebabCase(name)] = item;
30
28
  }
31
29
  return acc;
32
30
  }, {});
@@ -42,7 +40,7 @@ function resolveCommand(commands, name) {
42
40
  return commands[SingleCommand];
43
41
  }
44
42
  const possibleCommands = Object.values(commands).filter(
45
- (c) => c.name === name || mustArray(c.alias || []).map(String).includes(name)
43
+ (c) => c.name === name || utils.mustArray(c.alias || []).map(String).includes(name)
46
44
  );
47
45
  if (possibleCommands.length > 1) {
48
46
  throw new Error(`Multiple commands found with name "${name}"`);
@@ -134,6 +132,7 @@ class Clerc {
134
132
  raw: parsedWithType,
135
133
  parameters,
136
134
  flags,
135
+ unknownFlags: parsedWithType.unknownFlags,
137
136
  cli: this
138
137
  };
139
138
  const handlerContext = inspectorContext;
@@ -159,13 +158,10 @@ exports.CommonCommandExistsError = CommonCommandExistsError;
159
158
  exports.NoSuchCommandError = NoSuchCommandError;
160
159
  exports.SingleCommand = SingleCommand;
161
160
  exports.SingleCommandError = SingleCommandError;
162
- exports.camelCase = camelCase;
163
161
  exports.compose = compose;
164
162
  exports.defineHandler = defineHandler;
165
163
  exports.defineInspector = defineInspector;
166
164
  exports.definePlugin = definePlugin;
167
- exports.kebabCase = kebabCase;
168
- exports.mustArray = mustArray;
169
165
  exports.resolveArgv = resolveArgv;
170
166
  exports.resolveCommand = resolveCommand;
171
167
  exports.resolveFlagAlias = resolveFlagAlias;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { MaybeArray, Dict, LiteralUnion } from '@clerc/utils';
2
+
1
3
  declare const DOUBLE_DASH = "--";
2
4
  declare type TypeFunction<ReturnType = any> = (value: any) => ReturnType;
3
5
  declare type TypeFunctionArray<ReturnType> = readonly [TypeFunction<ReturnType>];
@@ -66,23 +68,6 @@ declare type TypeFlag<Schemas extends Flags> = ParsedFlags<{
66
68
  [flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
67
69
  }>;
68
70
 
69
- /**
70
- * Copied from type-fest
71
- */
72
- declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
73
- /**
74
- * Copied from type-fest
75
- */
76
- declare type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
77
- declare type Dict<T> = Record<string, T>;
78
- declare type MustArray<T> = T extends any[] ? T : [T];
79
- declare type MaybeArray<T> = T | T[];
80
- declare type GetLength<T extends any[]> = T extends {
81
- length: infer L extends number;
82
- } ? L : never;
83
- declare type GetTail<T extends any[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
84
- declare type EnhanceSingle<T, E extends Dict<any>> = T & E;
85
- declare type Enhance<T, E extends Dict<any> | Dict<any>[]> = GetLength<MustArray<E>> extends 0 ? T : Enhance<EnhanceSingle<T, MustArray<E>[0]>, GetTail<MustArray<E>>>;
86
71
  declare type FlagOptions = FlagSchema & {
87
72
  description: string;
88
73
  required?: boolean;
@@ -112,6 +97,7 @@ interface HandlerContext<C extends CommandRecord = CommandRecord, N extends keyo
112
97
  isSingleCommand: boolean;
113
98
  raw: ParsedFlags;
114
99
  parameters: PossibleInputKind[];
100
+ unknownFlags: ParsedFlags["unknownFlags"];
115
101
  flags: TypeFlag<NonNullableFlag<C[N]["flags"]>>["flags"];
116
102
  cli: Clerc<C>;
117
103
  }
@@ -276,15 +262,10 @@ declare class CommonCommandExistsError extends Error {
276
262
  declare class NoSuchCommandError extends Error {
277
263
  }
278
264
 
279
- declare const mustArray: <T>(a: MaybeArray<T>) => T[];
280
- declare type CamelCase<T extends string> = T extends `${infer A}-${infer B}${infer C}` ? `${A}${Capitalize<B>}${CamelCase<C>}` : T;
281
- declare const camelCase: <T extends string>(s: T) => CamelCase<T>;
282
- declare type KebabCase<T extends string, A extends string = ""> = T extends `${infer F}${infer R}` ? KebabCase<R, `${A}${F extends Lowercase<F> ? "" : "-"}${Lowercase<F>}`> : A;
283
- declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
284
265
  declare const resolveFlagAlias: (_command: Command) => Dict<string[]>;
285
266
  declare const resolveFlagDefault: (_command: Command) => Dict<any>;
286
267
  declare function resolveCommand(commands: CommandRecord, name: string | SingleCommandType): Command | undefined;
287
268
  declare const resolveArgv: () => string[];
288
269
  declare function compose(inspectors: Inspector[]): (ctx: InspectorContext) => void;
289
270
 
290
- export { CamelCase, Clerc, Command, CommandExistsError, CommandOptions, CommandRecord, CommonCommandExistsError, Dict, Enhance, FallbackType, Flag, FlagOptions, Handler, HandlerContext, Inspector, InspectorContext, KebabCase, LiteralUnion, MakeEventMap, MaybeArray, NoSuchCommandError, Plugin, PossibleInputKind, Primitive, SingleCommand, SingleCommandError, SingleCommandType, camelCase, compose, defineHandler, defineInspector, definePlugin, kebabCase, mustArray, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };
271
+ export { Clerc, Command, CommandExistsError, CommandOptions, CommandRecord, CommonCommandExistsError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, Inspector, InspectorContext, MakeEventMap, NoSuchCommandError, Plugin, PossibleInputKind, SingleCommand, SingleCommandError, SingleCommandType, compose, defineHandler, defineInspector, definePlugin, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { LiteEmit } from 'lite-emit';
2
2
  import mri from 'mri';
3
3
  import { typeFlag } from 'type-flag';
4
4
  import { isNode, isDeno } from 'is-platform';
5
+ import { mustArray, kebabCase } from '@clerc/utils';
5
6
 
6
7
  class SingleCommandError extends Error {
7
8
  }
@@ -12,9 +13,6 @@ class CommonCommandExistsError extends Error {
12
13
  class NoSuchCommandError extends Error {
13
14
  }
14
15
 
15
- const mustArray = (a) => Array.isArray(a) ? a : [a];
16
- const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
17
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
18
16
  const resolveFlagAlias = (_command) => Object.entries((_command == null ? void 0 : _command.flags) || {}).reduce((acc, [name, command]) => {
19
17
  if (command.alias) {
20
18
  const item = mustArray(command.alias).map(kebabCase);
@@ -126,6 +124,7 @@ class Clerc {
126
124
  raw: parsedWithType,
127
125
  parameters,
128
126
  flags,
127
+ unknownFlags: parsedWithType.unknownFlags,
129
128
  cli: this
130
129
  };
131
130
  const handlerContext = inspectorContext;
@@ -145,4 +144,4 @@ const definePlugin = (p) => p;
145
144
  const defineHandler = (_cli, _key, handler) => handler;
146
145
  const defineInspector = (_cli, inspector) => inspector;
147
146
 
148
- export { Clerc, CommandExistsError, CommonCommandExistsError, NoSuchCommandError, SingleCommand, SingleCommandError, camelCase, compose, defineHandler, defineInspector, definePlugin, kebabCase, mustArray, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };
147
+ export { Clerc, CommandExistsError, CommonCommandExistsError, NoSuchCommandError, SingleCommand, SingleCommandError, compose, defineHandler, defineInspector, definePlugin, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clerc",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
5
  "description": "Clerc is a simple and easy-to-use cli framework.",
6
6
  "keywords": [
@@ -39,6 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
+ "@clerc/utils": "0.3.4",
42
43
  "is-platform": "^0.2.0",
43
44
  "lite-emit": "^1.4.0",
44
45
  "mri": "^1.2.0",