@clerc/core 0.18.0 → 0.19.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/dist/index.js CHANGED
@@ -212,7 +212,7 @@ var __privateSet = (obj, member, value, setter) => {
212
212
  setter ? setter.call(obj, value) : member.set(obj, value);
213
213
  return value;
214
214
  };
215
- var _name, _description, _version, _inspectors, _commands, _commandEmitter, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get;
215
+ var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get;
216
216
  const SingleCommand = Symbol("SingleCommand");
217
217
  const _Clerc = class {
218
218
  constructor() {
@@ -224,6 +224,7 @@ const _Clerc = class {
224
224
  __privateAdd(this, _inspectors, []);
225
225
  __privateAdd(this, _commands, {});
226
226
  __privateAdd(this, _commandEmitter, new LiteEmit());
227
+ __privateAdd(this, _usedNames, []);
227
228
  }
228
229
  get _name() {
229
230
  return __privateGet(this, _name);
@@ -280,11 +281,12 @@ const _Clerc = class {
280
281
  const nameList = [commandToSave.name];
281
282
  commandToSave.alias && nameList.push(...toArray(commandToSave.alias));
282
283
  for (const name2 of nameList) {
283
- if (Object.keys(__privateGet(this, _commands)).includes(name2) || Object.values(__privateGet(this, _commands)).some(({ alias }) => alias ? toArray(alias).includes(name2) : false)) {
284
+ if (__privateGet(this, _usedNames).includes(name2)) {
284
285
  throw new CommandExistsError(name2);
285
286
  }
286
287
  }
287
288
  __privateGet(this, _commands)[name] = commandToSave;
289
+ __privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
288
290
  isCommandObject && handler && this.on(nameOrCommand.name, handler);
289
291
  return this;
290
292
  }
@@ -318,7 +320,7 @@ const _Clerc = class {
318
320
  const command = getCommand();
319
321
  const isCommandResolved = !!command;
320
322
  const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
321
- const { _: args, flags } = parsed;
323
+ const { _: args, flags, unknownFlags } = parsed;
322
324
  let parameters = __privateGet(this, _isSingleCommand, isSingleCommand_get) || !isCommandResolved ? args : args.slice(command.name.split(" ").length);
323
325
  let commandParameters = (command == null ? void 0 : command.parameters) || [];
324
326
  const hasEof = commandParameters.indexOf("--");
@@ -326,7 +328,7 @@ const _Clerc = class {
326
328
  const mapping = /* @__PURE__ */ Object.create(null);
327
329
  if (hasEof > -1 && eofParameters.length > 0) {
328
330
  commandParameters = commandParameters.slice(0, hasEof);
329
- const eofArguments = parsed._["--"];
331
+ const eofArguments = args["--"];
330
332
  parameters = parameters.slice(0, -eofArguments.length || void 0);
331
333
  mapErrors.push(mapParametersToArguments(
332
334
  mapping,
@@ -345,7 +347,7 @@ const _Clerc = class {
345
347
  parameters
346
348
  ));
347
349
  }
348
- const mergedFlags = { ...parsed.flags, ...parsed.unknownFlags };
350
+ const mergedFlags = { ...flags, ...unknownFlags };
349
351
  const context = {
350
352
  name: command == null ? void 0 : command.name,
351
353
  resolved: isCommandResolved,
@@ -353,7 +355,7 @@ const _Clerc = class {
353
355
  raw: { ...parsed, parameters, mergedFlags },
354
356
  parameters: mapping,
355
357
  flags,
356
- unknownFlags: parsed.unknownFlags,
358
+ unknownFlags,
357
359
  cli: this
358
360
  };
359
361
  return context;
@@ -390,6 +392,7 @@ _version = new WeakMap();
390
392
  _inspectors = new WeakMap();
391
393
  _commands = new WeakMap();
392
394
  _commandEmitter = new WeakMap();
395
+ _usedNames = new WeakMap();
393
396
  _isSingleCommand = new WeakSet();
394
397
  isSingleCommand_get = function() {
395
398
  return __privateGet(this, _commands)[SingleCommand] !== void 0;
package/dist/index.mjs CHANGED
@@ -212,7 +212,7 @@ var __privateSet = (obj, member, value, setter) => {
212
212
  setter ? setter.call(obj, value) : member.set(obj, value);
213
213
  return value;
214
214
  };
215
- var _name, _description, _version, _inspectors, _commands, _commandEmitter, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get;
215
+ var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get;
216
216
  const SingleCommand = Symbol("SingleCommand");
217
217
  const _Clerc = class {
218
218
  constructor() {
@@ -224,6 +224,7 @@ const _Clerc = class {
224
224
  __privateAdd(this, _inspectors, []);
225
225
  __privateAdd(this, _commands, {});
226
226
  __privateAdd(this, _commandEmitter, new LiteEmit());
227
+ __privateAdd(this, _usedNames, []);
227
228
  }
228
229
  get _name() {
229
230
  return __privateGet(this, _name);
@@ -280,11 +281,12 @@ const _Clerc = class {
280
281
  const nameList = [commandToSave.name];
281
282
  commandToSave.alias && nameList.push(...toArray(commandToSave.alias));
282
283
  for (const name2 of nameList) {
283
- if (Object.keys(__privateGet(this, _commands)).includes(name2) || Object.values(__privateGet(this, _commands)).some(({ alias }) => alias ? toArray(alias).includes(name2) : false)) {
284
+ if (__privateGet(this, _usedNames).includes(name2)) {
284
285
  throw new CommandExistsError(name2);
285
286
  }
286
287
  }
287
288
  __privateGet(this, _commands)[name] = commandToSave;
289
+ __privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
288
290
  isCommandObject && handler && this.on(nameOrCommand.name, handler);
289
291
  return this;
290
292
  }
@@ -318,7 +320,7 @@ const _Clerc = class {
318
320
  const command = getCommand();
319
321
  const isCommandResolved = !!command;
320
322
  const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
321
- const { _: args, flags } = parsed;
323
+ const { _: args, flags, unknownFlags } = parsed;
322
324
  let parameters = __privateGet(this, _isSingleCommand, isSingleCommand_get) || !isCommandResolved ? args : args.slice(command.name.split(" ").length);
323
325
  let commandParameters = (command == null ? void 0 : command.parameters) || [];
324
326
  const hasEof = commandParameters.indexOf("--");
@@ -326,7 +328,7 @@ const _Clerc = class {
326
328
  const mapping = /* @__PURE__ */ Object.create(null);
327
329
  if (hasEof > -1 && eofParameters.length > 0) {
328
330
  commandParameters = commandParameters.slice(0, hasEof);
329
- const eofArguments = parsed._["--"];
331
+ const eofArguments = args["--"];
330
332
  parameters = parameters.slice(0, -eofArguments.length || void 0);
331
333
  mapErrors.push(mapParametersToArguments(
332
334
  mapping,
@@ -345,7 +347,7 @@ const _Clerc = class {
345
347
  parameters
346
348
  ));
347
349
  }
348
- const mergedFlags = { ...parsed.flags, ...parsed.unknownFlags };
350
+ const mergedFlags = { ...flags, ...unknownFlags };
349
351
  const context = {
350
352
  name: command == null ? void 0 : command.name,
351
353
  resolved: isCommandResolved,
@@ -353,7 +355,7 @@ const _Clerc = class {
353
355
  raw: { ...parsed, parameters, mergedFlags },
354
356
  parameters: mapping,
355
357
  flags,
356
- unknownFlags: parsed.unknownFlags,
358
+ unknownFlags,
357
359
  cli: this
358
360
  };
359
361
  return context;
@@ -390,6 +392,7 @@ _version = new WeakMap();
390
392
  _inspectors = new WeakMap();
391
393
  _commands = new WeakMap();
392
394
  _commandEmitter = new WeakMap();
395
+ _usedNames = new WeakMap();
393
396
  _isSingleCommand = new WeakSet();
394
397
  isSingleCommand_get = function() {
395
398
  return __privateGet(this, _commands)[SingleCommand] !== void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/core",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
5
  "description": "Clerc core",
6
6
  "keywords": [
@@ -50,7 +50,7 @@
50
50
  "is-platform": "^0.2.0",
51
51
  "lite-emit": "^1.4.0",
52
52
  "type-flag": "^3.0.0",
53
- "@clerc/utils": "0.18.0"
53
+ "@clerc/utils": "0.19.0"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "puild",