@clerc/core 1.1.1 → 1.2.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.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Parser from "@clerc/parser";
|
|
2
|
-
import { DOUBLE_DASH, FlagOptions, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, PARAMETER, ParsedResult, TypeFunction, TypeValue, UNKNOWN_FLAG } from "@clerc/parser";
|
|
2
|
+
import { DOUBLE_DASH, FlagOptions, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, PARAMETER, ParsedResult, TypeFunction, TypeValue, UNKNOWN_FLAG, inferDefault } from "@clerc/parser";
|
|
3
3
|
import { CamelCase, DeepPrettify, LiteralUnion, MaybeArray, PartialRequired, Prettify, UnionToIntersection } from "@clerc/utils";
|
|
4
4
|
|
|
5
5
|
//#region ../advanced-types/src/errors.d.ts
|
|
@@ -210,4 +210,4 @@ declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
|
210
210
|
declare const normalizeFlagValue: (flag: ClercFlagDefinitionValue) => ClercFlagOptions;
|
|
211
211
|
declare const normalizeParameterValue: (parameter: ParameterDefinitionValue) => ParameterOptions;
|
|
212
212
|
//#endregion
|
|
213
|
-
export { BaseContext, Clerc, ClercFlagDefinitionValue, ClercFlagOptions, ClercFlagsDefinition, Command, CommandCustomOptions, CommandHandler, CommandHandlerContext, CommandOptions, CommandWithHandler, CommandsMap, CommandsRecord, ContextStore, type CreateOptions, DOUBLE_DASH, ErrorHandler, FlagCustomOptions, InferParameters, Interceptor, InterceptorContext, InterceptorHandler, InterceptorNext, InterceptorObject, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MakeEmitterEvents, MissingRequiredFlagError, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, ParameterCustomOptions, ParameterDefinitionValue, ParameterOptions, type ParseOptions, type Parser, Plugin, index_d_exports as Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, extractParameterInfo, normalizeFlagValue, normalizeParameterValue, resolveCommand };
|
|
213
|
+
export { BaseContext, Clerc, ClercFlagDefinitionValue, ClercFlagOptions, ClercFlagsDefinition, Command, CommandCustomOptions, CommandHandler, CommandHandlerContext, CommandOptions, CommandWithHandler, CommandsMap, CommandsRecord, ContextStore, type CreateOptions, DOUBLE_DASH, ErrorHandler, FlagCustomOptions, InferParameters, Interceptor, InterceptorContext, InterceptorHandler, InterceptorNext, InterceptorObject, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MakeEmitterEvents, MissingRequiredFlagError, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, ParameterCustomOptions, ParameterDefinitionValue, ParameterOptions, type ParseOptions, type Parser, Plugin, index_d_exports as Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, extractParameterInfo, inferDefault, normalizeFlagValue, normalizeParameterValue, resolveCommand };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./chunk-rq_z9THO.mjs";import{DOUBLE_DASH as t,DOUBLE_DASH as n,InvalidSchemaError as r,KNOWN_FLAG as i,PARAMETER as a,PARAMETER as o,UNKNOWN_FLAG as s,parse as
|
|
1
|
+
import{t as e}from"./chunk-rq_z9THO.mjs";import{DOUBLE_DASH as t,DOUBLE_DASH as n,InvalidSchemaError as r,KNOWN_FLAG as i,PARAMETER as a,PARAMETER as o,UNKNOWN_FLAG as s,inferDefault as c,parse as l}from"@clerc/parser";import{camelCase as u,hasOwn as d,looseIsArray as f,toArray as p}from"@clerc/utils";import{LiteEmit as m}from"lite-emit";var h=class extends Error{},g=e({Enum:()=>_,FlagValidationError:()=>h,Range:()=>v,Regex:()=>y});function _(...e){let t=(t=>{if(!e.includes(t))throw new h(`Invalid value: ${t}. Must be one of: ${e.join(`, `)}`);return t});return t.display=e.join(` | `),t}function v(e,t){let n=(n=>{let r=Number(n);if(Number.isNaN(r)||r<e||r>t)throw new h(`Invalid value: ${n}. Must be a number between ${e} and ${t}`);return r});return n.display=`${e} - ${t}`,n}function y(e,t){let n=(t=>{if(!e.test(t))throw new h(`Invalid value: ${t}. Must match pattern: ${e}`);return t});return n.display=t??`Regex: ${e.toString()}`,n}function b(e,t){for(let n=t.length;n>=0;n--){let r=t.slice(0,n).join(` `);if(e.has(r))return[e.get(r),r]}return[void 0,void 0]}var x=class extends Error{constructor(e,t=`No such command: "${e}".`){super(t),this.commandName=e}},S=class extends Error{constructor(e=`No command specified.`){super(e)}},C=class extends Error{},w=class extends Error{constructor(e){super(`CLI ${e} is required.`)}},T=class extends Error{},E=class extends Error{constructor(e){let t=e.length>1?`s`:``;super(`Missing required flag${t}: ${e.join(`, `)}`)}};function D(e){return typeof e==`function`?{enforce:`normal`,handler:e}:{enforce:e.enforce??`normal`,handler:e.handler}}function O(e){let t=e.map(D),n=t.filter(e=>e.enforce===`pre`),r=t.filter(e=>e.enforce===`normal`),i=t.filter(e=>e.enforce===`post`),a=[...n,...r,...i];return async e=>{let t=0;async function n(){t>=a.length||await a[t++].handler(e,n)}await n()}}const k=typeof Deno<`u`,A=typeof process<`u`&&!k,j=process.versions.electron&&!process.defaultApp,M=e=>typeof e==`function`||f(e)?{type:e}:e,N=e=>typeof e==`string`?{key:e}:e;function P(e){let t=[];for(let n of e){if(n.startsWith(`-`))break;t.push(n)}return t}const F=/^(<|\[)([\w ]+)(\.\.\.)?(\]|>)$/,I=e=>e.startsWith(`<`)&&e.endsWith(`>`)||e.startsWith(`[`)&&e.endsWith(`]`);function L(e){let t=e.match(F);if(!t||!I(e))throw new T(`Invalid parameter definition: ${e}`);return{name:u(t[2]),isRequired:e.startsWith(`<`),isVariadic:!!t[3]}}function R(e,t){let n={},r=!1;for(let[i,a]of e.entries()){let o=N(a),{name:s,isRequired:c,isVariadic:l}=L(o.key);if(d(n,s))throw new T(`Duplicate parameter name: ${s}`);if(l&&i!==e.length-1)throw new T(`Variadic parameter must be the last parameter in the definition.`);if(c){if(r)throw new T(`Required parameter "${s}" cannot appear after an optional parameter.`)}else r=!0;let u=l?t.slice(i):t[i];if(c&&(l?u.length===0:u===void 0))throw new T(`Missing required ${l?`variadic `:``}parameter: ${s}`);o.type?l?n[s]=u.map(e=>o.type(e)):u===void 0?n[s]=u:n[s]=o.type(u):n[s]=u}return n}function z(e,t,r){let i=e.indexOf(n);if(i===-1)return R(e,t);{let n=e.slice(0,i),a=e.slice(i+1);return{...R(n,t),...R(a,r)}}}const B=A?process.argv.slice(j?1:2):k?Deno.args:[];var V=class e{#e=[];#t=new Map;#n=new m;#r={};#i={};#a=[];#o=[];#s=``;#c=``;#l=``;#u=``;constructor({name:e,scriptName:t,description:n,version:r}={}){e&&(this.#s=e),t&&(this.#c=t),n&&(this.#l=n),r&&(this.#u=r)}get _name(){return this.#s||this.#c}get _scriptName(){return this.#c}get _description(){return this.#l}get _version(){return this.#u}get _commands(){return this.#t}get _globalFlags(){return this.#r}get store(){return this.#i}static create(t){return new e(t)}name(e){return this.#s=e,this}scriptName(e){return this.#c=e,this}description(e){return this.#l=e,this}version(e){return this.#u=e,this}use(e){return e.setup(this),this}errorHandler(e){return this.#o.push(e),this}#d(e){if(this.#o.length>0)for(let t of this.#o)t(e);else throw e}#f(e){try{let t=e();return t instanceof Promise?t.catch(e=>{this.#d(e)}):t}catch(e){throw this.#d(e),e}}#p(e,t){if(this.#t.has(e))throw new C(`Command with name "${e}" already exists.`);for(let e of t)if(this.#t.has(e))throw new C(`Command with name "${e}" already exists.`)}command(e,t,n){if(Array.isArray(e)){for(let t of e)this.command(t);return this}let r=typeof t==`string`,i=typeof e==`string`?{name:e,description:r?t:void 0,...r?n:t}:e,a=p(i?.alias??[]);this.#f(()=>this.#p(i.name,a)),this.#t.set(i.name,i);for(let e of a)this.#t.set(e,{...i,__isAlias:!0});return i.handler&&this.on(i.name,i.handler),this}globalFlag(e,t,n){let r=typeof t==`string`;return this.#r[e]={description:r?t:void 0,...r?n:t},this}interceptor(e){return this.#a.push(e),this}on(e,t){return this.#n.on(e,t),this}#m(){if(!this.#c)throw new w(`script name`);if(!this.#u)throw new w(`version`)}#h(e,t){let{flags:n,ignore:r}=t??{};return this.#f(()=>l(e,{flags:{...this.#r,...n},ignore:r}))}async run(){let e=P(this.#e),[t,n]=b(this.#t,e),r=t&&n.length>0?this.#e.slice(n.split(` `).length):this.#e,i=this.#f(()=>this.#h(r,t)),a={},o;try{a=t?.parameters?z(t.parameters,i.parameters,i.doubleDash):{}}catch(e){o=e}let s={command:t,calledAs:n,parameters:a,flags:i.flags,ignored:i.ignored,rawParsed:i,store:{...this.#i}},c={enforce:`post`,handler:async n=>{if(i.missingRequiredFlags.length>0)throw new E(i.missingRequiredFlags);if(o)throw o;if(t)await this.#n.emit(t.name,n);else throw e.length>0?new x(e.join(` `)):new S}},l=O([...this.#a,c]);return this.#f(()=>l(s))}parse(e=B){this.#f(()=>this.#m()),Array.isArray(e)&&(e={argv:e});let{argv:t=B,run:n=!0}=e;return this.#e=t,n?this.run():this}};const H=(e,t)=>({...e,handler:t});function U(){let e=!1;return t=>t===o&&!e?(e=!0,!1):e}const W=e=>e;export{V as Clerc,t as DOUBLE_DASH,C as InvalidCommandError,T as InvalidParametersError,r as InvalidSchemaError,i as KNOWN_FLAG,E as MissingRequiredFlagError,w as MissingRequiredMetadataError,S as NoCommandSpecifiedError,x as NoSuchCommandError,a as PARAMETER,g as Types,s as UNKNOWN_FLAG,U as createStopAtFirstParameter,H as defineCommand,W as definePlugin,L as extractParameterInfo,c as inferDefault,M as normalizeFlagValue,N as normalizeParameterValue,b as resolveCommand};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc core",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"lite-emit": "^4.0.0",
|
|
41
|
-
"@clerc/
|
|
42
|
-
"@clerc/
|
|
41
|
+
"@clerc/parser": "1.2.0",
|
|
42
|
+
"@clerc/utils": "1.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"is-platform": "^1.0.0",
|
|
46
|
-
"@clerc/advanced-types": "1.
|
|
46
|
+
"@clerc/advanced-types": "1.2.0"
|
|
47
47
|
}
|
|
48
48
|
}
|