@clerc/core
Advanced tools
Comparing version 0.19.0 to 0.20.0
@@ -124,3 +124,3 @@ import * as _clerc_utils from '@clerc/utils'; | ||
resolved: N extends keyof C ? true : boolean; | ||
isSingleCommand: boolean; | ||
hasSingleCommand: boolean; | ||
raw: Raw<C, N>; | ||
@@ -292,14 +292,5 @@ parameters: TransformParameters<C, N>; | ||
declare class SingleCommandError extends Error { | ||
constructor(); | ||
} | ||
declare class SingleCommandAliasError extends Error { | ||
constructor(); | ||
} | ||
declare class CommandExistsError extends Error { | ||
constructor(name: string); | ||
} | ||
declare class CommonCommandExistsError extends Error { | ||
constructor(); | ||
} | ||
declare class NoSuchCommandError extends Error { | ||
@@ -327,7 +318,7 @@ constructor(name: string); | ||
declare function resolveFlattenCommands(commands: CommandRecord): Map<string[], CommandAlias<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>>; | ||
declare function resolveCommand(commands: CommandRecord, name: string | string[] | SingleCommandType): Command | undefined; | ||
declare function resolveFlattenCommands(commands: CommandRecord): Map<string[] | typeof SingleCommand, CommandAlias<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>>; | ||
declare function resolveCommand(commands: CommandRecord, name: string | string[] | SingleCommandType): Command<string | SingleCommandType> | undefined; | ||
declare function resolveSubcommandsByParent(commands: CommandRecord, parent: string | string[], depth?: number): Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[]; | ||
declare const resolveRootCommands: (commands: CommandRecord) => Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[]; | ||
declare function resolveParametersBeforeFlag(argv: string[], isSingleCommand: boolean): string[]; | ||
declare function resolveParametersBeforeFlag(argv: string[]): string[]; | ||
declare const resolveArgv: () => string[]; | ||
@@ -345,2 +336,2 @@ declare function compose(inspectors: Inspector[]): (getCtx: () => InspectorContext) => void; | ||
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, CommonCommandExistsError, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, SingleCommand, SingleCommandAliasError, SingleCommandError, SingleCommandType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent }; | ||
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, SingleCommand, SingleCommandType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent }; |
@@ -6,12 +6,2 @@ import { LiteEmit } from 'lite-emit'; | ||
class SingleCommandError extends Error { | ||
constructor() { | ||
super("Single command mode enabled."); | ||
} | ||
} | ||
class SingleCommandAliasError extends Error { | ||
constructor() { | ||
super("Single command cannot have alias."); | ||
} | ||
} | ||
class CommandExistsError extends Error { | ||
@@ -22,7 +12,2 @@ constructor(name) { | ||
} | ||
class CommonCommandExistsError extends Error { | ||
constructor() { | ||
super("Common command exists."); | ||
} | ||
} | ||
class NoSuchCommandError extends Error { | ||
@@ -66,2 +51,5 @@ constructor(name) { | ||
const commandsMap = /* @__PURE__ */ new Map(); | ||
if (commands[SingleCommand]) { | ||
commandsMap.set(SingleCommand, commands[SingleCommand]); | ||
} | ||
for (const command of Object.values(commands)) { | ||
@@ -90,3 +78,8 @@ if (command.alias) { | ||
commandsMap.forEach((v, k) => { | ||
if (arrayStartsWith(nameArr, k) && (!currentName || k.length > currentName.length)) { | ||
if (k === SingleCommand) { | ||
current = commandsMap.get(SingleCommand); | ||
currentName = SingleCommand; | ||
return; | ||
} | ||
if (arrayStartsWith(nameArr, k) && (!currentName || currentName === SingleCommand || k.length > currentName.length)) { | ||
current = v; | ||
@@ -106,6 +99,3 @@ currentName = k; | ||
const resolveRootCommands = (commands) => resolveSubcommandsByParent(commands, "", 1); | ||
function resolveParametersBeforeFlag(argv, isSingleCommand) { | ||
if (isSingleCommand) { | ||
return []; | ||
} | ||
function resolveParametersBeforeFlag(argv) { | ||
const parameters = []; | ||
@@ -220,8 +210,6 @@ for (const arg of argv) { | ||
}; | ||
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get; | ||
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _hasSingleCommand; | ||
const SingleCommand = Symbol("SingleCommand"); | ||
const _Clerc = class { | ||
constructor() { | ||
__privateAdd(this, _isSingleCommand); | ||
__privateAdd(this, _hasCommands); | ||
__privateAdd(this, _name, ""); | ||
@@ -234,2 +222,3 @@ __privateAdd(this, _description, ""); | ||
__privateAdd(this, _usedNames, []); | ||
__privateAdd(this, _hasSingleCommand, false); | ||
} | ||
@@ -266,3 +255,3 @@ get _name() { | ||
} | ||
command(nameOrCommand, description, options) { | ||
command(nameOrCommand, description, options = {}) { | ||
const checkIsCommandObject = (nameOrCommand2) => !(typeof nameOrCommand2 === "string" || nameOrCommand2 === SingleCommand); | ||
@@ -272,5 +261,3 @@ const isCommandObject = checkIsCommandObject(nameOrCommand); | ||
if (__privateGet(this, _commands)[name]) { | ||
if (name === SingleCommand) { | ||
throw new CommandExistsError("SingleCommand"); | ||
} | ||
throw new CommandExistsError(typeof name === "symbol" ? "" : name); | ||
} | ||
@@ -280,11 +267,2 @@ if (isInvalidName(name)) { | ||
} | ||
if (__privateGet(this, _isSingleCommand, isSingleCommand_get)) { | ||
throw new SingleCommandError(); | ||
} | ||
if (name === SingleCommand && __privateGet(this, _hasCommands, hasCommands_get)) { | ||
throw new CommonCommandExistsError(); | ||
} | ||
if (name === SingleCommand && (isCommandObject ? nameOrCommand : options).alias) { | ||
throw new SingleCommandAliasError(); | ||
} | ||
const { handler = void 0, ...commandToSave } = isCommandObject ? nameOrCommand : { name, description, ...options }; | ||
@@ -298,2 +276,5 @@ const nameList = [commandToSave.name]; | ||
} | ||
if (nameList.includes(SingleCommand)) { | ||
__privateSet(this, _hasSingleCommand, true); | ||
} | ||
__privateGet(this, _commands)[name] = commandToSave; | ||
@@ -325,5 +306,5 @@ __privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []); | ||
} | ||
const name = resolveParametersBeforeFlag(argv, __privateGet(this, _isSingleCommand, isSingleCommand_get)); | ||
const name = resolveParametersBeforeFlag(argv); | ||
const stringName = name.join(" "); | ||
const getCommand = () => __privateGet(this, _isSingleCommand, isSingleCommand_get) ? __privateGet(this, _commands)[SingleCommand] : resolveCommand(__privateGet(this, _commands), name); | ||
const getCommand = () => resolveCommand(__privateGet(this, _commands), name); | ||
const mapErrors = []; | ||
@@ -336,3 +317,3 @@ const getContext = () => { | ||
const { _: args, flags, unknownFlags } = parsed; | ||
let parameters = __privateGet(this, _isSingleCommand, isSingleCommand_get) || !isCommandResolved ? args : args.slice(command.name.split(" ").length); | ||
let parameters = !isCommandResolved || command.name === SingleCommand ? args : args.slice(command.name.split(" ").length); | ||
let commandParameters = (command == null ? void 0 : command.parameters) || []; | ||
@@ -367,3 +348,3 @@ const hasEof = commandParameters.indexOf("--"); | ||
resolved: isCommandResolved, | ||
isSingleCommand: __privateGet(this, _isSingleCommand, isSingleCommand_get), | ||
hasSingleCommand: __privateGet(this, _hasSingleCommand), | ||
raw: { ...parsed, parameters, mergedFlags }, | ||
@@ -410,10 +391,3 @@ parameters: mapping, | ||
_usedNames = new WeakMap(); | ||
_isSingleCommand = new WeakSet(); | ||
isSingleCommand_get = function() { | ||
return __privateGet(this, _commands)[SingleCommand] !== void 0; | ||
}; | ||
_hasCommands = new WeakSet(); | ||
hasCommands_get = function() { | ||
return Object.keys(__privateGet(this, _commands)).length > 0; | ||
}; | ||
_hasSingleCommand = new WeakMap(); | ||
@@ -425,2 +399,2 @@ const definePlugin = (p) => p; | ||
export { Clerc, CommandExistsError, CommandNameConflictError, CommonCommandExistsError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, SingleCommandAliasError, SingleCommandError, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent }; | ||
export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent }; |
{ | ||
"name": "@clerc/core", | ||
"version": "0.19.0", | ||
"version": "0.20.0", | ||
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)", | ||
@@ -53,3 +53,3 @@ "description": "Clerc core", | ||
"type-flag": "^3.0.0", | ||
"@clerc/utils": "0.19.0" | ||
"@clerc/utils": "0.20.0" | ||
}, | ||
@@ -56,0 +56,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42492
1083
+ Added@clerc/utils@0.20.0(transitive)
- Removed@clerc/utils@0.19.0(transitive)
Updated@clerc/utils@0.20.0