Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clerc/core

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clerc/core - npm Package Compare versions

Comparing version 0.26.0 to 0.27.1

13

dist/index.d.ts

@@ -264,7 +264,11 @@ /**

};
type StripBrackets<Parameter extends string> = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never);
type ParameterType<Parameter extends string> = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never);
type CommandRecord = Dict<Command> & {
[Root]?: Command;
};
interface ParseOptions {
argv?: string[];
run?: boolean;
}
type StripBrackets<Parameter extends string> = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never);
type ParameterType<Parameter extends string> = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never);
type MakeEventMap<T extends CommandRecord> = {

@@ -457,3 +461,4 @@ [K in keyof T]: [InspectorContext];

*/
parse(argv?: string[]): this;
parse(optionsOrArgv?: string[] | ParseOptions): this;
runMatchedCommand(): this;
}

@@ -509,2 +514,2 @@

export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, Root, RootType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, formatCommandName, isInvalidName, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent, withBrackets };
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, PossibleInputKind, Root, RootType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, formatCommandName, isInvalidName, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent, withBrackets };

@@ -1,1 +0,1 @@

class fe{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 ue="known-flag",pe="unknown-flag",de="argument",{stringify:A}=JSON,me=/\B([A-Z])/g,ge=e=>e.replace(me,"-$1").toLowerCase(),{hasOwnProperty:we}=Object.prototype,k=(e,t)=>we.call(e,t),ve=e=>Array.isArray(e),T=e=>typeof e=="function"?[e,!1]:ve(e)?[e[0],!0]:T(e.type),ye=(e,t)=>e===Boolean?t!=="false":t,Ee=(e,t)=>typeof t=="boolean"?t:e===Number&&t===""?Number.NaN:e(t),_e=/[\s.:=]/,Ce=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(_e);if(s)throw new Error(`${t} cannot contain ${A(s==null?void 0:s[0])}`)},Ne=e=>{const t={},s=(r,n)=>{if(k(t,r))throw new Error(`Duplicate flags named ${A(r)}`);t[r]=n};for(const r in e){if(!k(e,r))continue;Ce(r);const n=e[r],o=[[],...T(n),n];s(r,o);const a=ge(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},$e=(e,t)=>{const s={};for(const r in e){if(!k(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},O="--",Me=/[.:=]/,Ae=/^-{1,2}\w/,ke=e=>{if(!Ae.test(e))return;const t=!e.startsWith(O);let s=e.slice(t?1:2),r;const n=s.match(Me);if(n){const{index:o}=n;r=s.slice(o+1),s=s.slice(0,o)}return[s,r,t]},be=(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===O){n();const c=e.slice(o+1);s==null||s(c,[o],!0);break}const i=ke(a);if(i){if(n(),!t)continue;const[c,l,f]=i;if(f)for(let p=0;p<c.length;p+=1){n();const d=p===c.length-1;r=t(c[p],d?l:void 0,[o,p+1,d])}else r=t(c,l,[o])}else n(a,[o])&&(s==null||s([a],[o]))}n()},Se=(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)}},xe=(e,t=process.argv.slice(2),{ignore:s}={})=>{const r=[],n=Ne(e),o={},a=[];return a[O]=[],be(t,{onFlag(i,c,l){const f=k(n,i);if(!(s!=null&&s(f?ue:pe,i,c))){if(f){const[p,d]=n[i],$=ye(d,c),M=(w,m)=>{r.push(l),m&&r.push(m),p.push(Ee(d,w||""))};return $===void 0?M:M($)}k(o,i)||(o[i]=[]),o[i].push(c===void 0?!0:c),r.push(l)}},onArgument(i,c,l){s!=null&&s(de,t[c[0]])||(a.push(...i),l?(a[O]=i,t.splice(c[0])):r.push(c))}}),Se(t,r),{flags:$e(e,n),unknownFlags:o,_:a}},W=e=>Array.isArray(e)?e:[e],Oe=e=>e.replace(/-([a-z])/g,(t,s)=>s.toUpperCase()),Ie=(e,t)=>t.length!==e.length?!1:e.every((s,r)=>s===t[r]),q=(e,t)=>t.length>e.length?!1:Ie(e.slice(0,t.length),t);class G extends Error{constructor(t){super(`Command "${t}" exists.`),this.commandName=t}}class V extends Error{constructor(t){super(`No such command: ${t}`),this.commandName=t}}class H extends Error{constructor(){super("No command given.")}}class J extends Error{constructor(t,s){super(`Command name ${t} conflicts with ${s}. Maybe caused by alias.`),this.n1=t,this.n2=s}}class U extends Error{constructor(){super("Name not set.")}}class z extends Error{constructor(){super("Description not set.")}}class K extends Error{constructor(){super("Version not set.")}}class Z extends Error{constructor(t){super(`Bad name format: ${t}`),this.commandName=t}}function Re(){return typeof process!="undefined"}function We(){return typeof Deno!="undefined"}function Q(e,t,s){if(s.alias){const r=W(s.alias);for(const n of r){if(n in t)throw new J(t[n].name,s.name);e.set(typeof n=="symbol"?n:n.split(" "),{...s,__isAlias:!0})}}}function X(e){const t=new Map;e[u]&&(t.set(u,e[u]),Q(t,e,e[u]));for(const s of Object.values(e))Q(t,e,s),t.set(s.name.split(" "),s);return t}function Y(e,t){if(t===u)return e[u];const s=W(t),r=X(e);let n,o;return r.forEach((a,i)=>{if(i===u){n=r.get(u),o=u;return}q(s,i)&&(!o||o===u||i.length>o.length)&&(n=a,o=i)}),n}function ee(e,t,s=1/0){const r=t===""?[]:Array.isArray(t)?t:t.split(" ");return Object.values(e).filter(n=>{const o=n.name.split(" ");return q(o,r)&&o.length-r.length<=s})}const Fe=e=>ee(e,"",1);function te(e){const t=[];for(const s of e){if(s.startsWith("-"))break;t.push(s)}return t}const se=()=>Re()?process.argv.slice(2):We()?Deno.args:[];function re(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 ne=e=>typeof e=="string"&&(e.startsWith(" ")||e.endsWith(" ")),Le=(e,t)=>t?`[${e}]`:`<${e}>`,Pe="<Root>",oe=e=>Array.isArray(e)?e.join(" "):typeof e=="string"?e:Pe,{stringify:_}=JSON;function F(e){const t=[];let s,r;for(const n of e){if(r)throw new Error(`Invalid parameter: Spread parameter ${_(r)} must be last`);const o=n[0],a=n[n.length-1];let i;if(o==="<"&&a===">"&&(i=!0,s))throw new Error(`Invalid parameter: Required parameter ${_(n)} cannot come after optional parameter ${_(s)}`);if(o==="["&&a==="]"&&(i=!1,s=n),i===void 0)throw new Error(`Invalid parameter: ${_(n)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let c=n.slice(1,-1);const l=c.slice(-3)==="...";l&&(r=n,c=c.slice(0,-3)),t.push({name:c,required:i,spread:l})}return t}function L(e,t,s){for(let r=0;r<t.length;r+=1){const{name:n,required:o,spread:a}=t[r],i=Oe(n);if(i in e)return new Error(`Invalid parameter: ${_(n)} is used more than once.`);const c=a?s.slice(r):s[r];if(a&&(r=t.length),o&&(!c||a&&c.length===0))return new Error(`Error: Missing required parameter ${_(n)}`);e[i]=c}}var ie=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},h=(e,t,s)=>(ie(e,t,"read from private field"),s?s.call(e):t.get(e)),g=(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)=>(ie(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),v,y,E,b,S,I,N,P,ae,B,ce;const u=Symbol("Root"),le=class{constructor(e,t,s){g(this,P),g(this,B),g(this,v,""),g(this,y,""),g(this,E,""),g(this,b,[]),g(this,S,{}),g(this,I,new fe),g(this,N,new Set),C(this,v,e||h(this,v)),C(this,y,t||h(this,y)),C(this,E,s||h(this,E))}get _name(){return h(this,v)}get _description(){return h(this,y)}get _version(){return h(this,E)}get _inspectors(){return h(this,b)}get _commands(){return h(this,S)}static create(e,t,s){return new le(e,t,s)}name(e){return C(this,v,e),this}description(e){return C(this,y,e),this}version(e){return C(this,E,e),this}command(e,t,s={}){const n=(f=>!(typeof f=="string"||f===u))(e),o=n?e.name:e;if(ne(o))throw new Z(o);const{handler:a=void 0,...i}=n?e:{name:o,description:t,...s},c=[i.name],l=i.alias?W(i.alias):[];i.alias&&c.push(...l);for(const f of c)if(h(this,N).has(f))throw new G(oe(f));return h(this,S)[o]=i,h(this,N).add(i.name),l.forEach(f=>h(this,N).add(f)),n&&a&&this.on(e.name,a),this}on(e,t){return h(this,I).on(e,t),this}use(e){return e.setup(this)}inspector(e){return h(this,b).push(e),this}parse(e=se()){if(!h(this,v))throw new U;if(!h(this,y))throw new z;if(!h(this,E))throw new K;const t=te(e),s=t.join(" "),r=()=>Y(h(this,S),t),n=[],o=()=>{n.length=0;const l=r(),f=!!l,p=xe((l==null?void 0:l.flags)||{},[...e]),{_:d,flags:$,unknownFlags:M}=p;let w=!f||l.name===u?d:d.slice(l.name.split(" ").length),m=(l==null?void 0:l.parameters)||[];const R=m.indexOf("--"),D=m.slice(R+1)||[],x=Object.create(null);if(R>-1&&D.length>0){m=m.slice(0,R);const j=d["--"];w=w.slice(0,-j.length||void 0),n.push(L(x,F(m),w)),n.push(L(x,F(D),j))}else n.push(L(x,F(m),w));const he={...$,...M};return{name:l==null?void 0:l.name,called:t.length===0&&(l==null?void 0:l.name)?u:s,resolved:f,hasRootOrAlias:h(this,P,ae),hasRoot:h(this,B,ce),raw:{...p,parameters:w,mergedFlags:he},parameters:x,flags:$,unknownFlags:M,cli:this}},a={enforce:"post",fn:()=>{const l=r(),f=o(),p=n.filter(Boolean);if(p.length>0)throw p[0];if(!l)throw s?new V(s):new H;h(this,I).emit(l.name,f)}},i=[...h(this,b),a];return re(i)(o),this}};let Be=le;v=new WeakMap,y=new WeakMap,E=new WeakMap,b=new WeakMap,S=new WeakMap,I=new WeakMap,N=new WeakMap,P=new WeakSet,ae=function(){return h(this,N).has(u)},B=new WeakSet,ce=function(){return Object.prototype.hasOwnProperty.call(this._commands,u)};const De=e=>e,je=(e,t,s)=>s,Te=(e,t)=>t,qe=(e,t)=>({...e,handler:t});export{Be as Clerc,G as CommandExistsError,J as CommandNameConflictError,z as DescriptionNotSetError,Z as InvalidCommandNameError,U as NameNotSetError,H as NoCommandGivenError,V as NoSuchCommandError,u as Root,K as VersionNotSetError,re as compose,qe as defineCommand,je as defineHandler,Te as defineInspector,De as definePlugin,oe as formatCommandName,ne as isInvalidName,se as resolveArgv,Y as resolveCommand,X as resolveFlattenCommands,te as resolveParametersBeforeFlag,Fe as resolveRootCommands,ee as resolveSubcommandsByParent,Le as withBrackets};
class me{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 ge="known-flag",we="unknown-flag",ve="argument",{stringify:S}=JSON,Ee=/\B([A-Z])/g,ye=e=>e.replace(Ee,"-$1").toLowerCase(),{hasOwnProperty:_e}=Object.prototype,k=(e,t)=>_e.call(e,t),Ce=e=>Array.isArray(e),H=e=>typeof e=="function"?[e,!1]:Ce(e)?[e[0],!0]:H(e.type),Me=(e,t)=>e===Boolean?t!=="false":t,Ne=(e,t)=>typeof t=="boolean"?t:e===Number&&t===""?Number.NaN:e(t),$e=/[\s.:=]/,Se=e=>{const t=`Flag name ${S(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($e);if(s)throw new Error(`${t} cannot contain ${S(s==null?void 0:s[0])}`)},ke=e=>{const t={},s=(r,n)=>{if(k(t,r))throw new Error(`Duplicate flags named ${S(r)}`);t[r]=n};for(const r in e){if(!k(e,r))continue;Se(r);const n=e[r],o=[[],...H(n),n];s(r,o);const a=ye(r);if(r!==a&&s(a,o),"alias"in n&&typeof n.alias=="string"){const{alias:i}=n,c=`Flag alias ${S(i)} for flag ${S(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},Ae=(e,t)=>{const s={};for(const r in e){if(!k(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},I="--",be=/[.:=]/,xe=/^-{1,2}\w/,Ie=e=>{if(!xe.test(e))return;const t=!e.startsWith(I);let s=e.slice(t?1:2),r;const n=s.match(be);if(n){const{index:o}=n;r=s.slice(o+1),s=s.slice(0,o)}return[s,r,t]},Oe=(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===I){n();const c=e.slice(o+1);s==null||s(c,[o],!0);break}const i=Ie(a);if(i){if(n(),!t)continue;const[c,l,f]=i;if(f)for(let p=0;p<c.length;p+=1){n();const m=p===c.length-1;r=t(c[p],m?l:void 0,[o,p+1,m])}else r=t(c,l,[o])}else n(a,[o])&&(s==null||s([a],[o]))}n()},We=(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)}},Re=(e,t=process.argv.slice(2),{ignore:s}={})=>{const r=[],n=ke(e),o={},a=[];return a[I]=[],Oe(t,{onFlag(i,c,l){const f=k(n,i);if(!(s!=null&&s(f?ge:we,i,c))){if(f){const[p,m]=n[i],N=Me(m,c),$=(w,g)=>{r.push(l),g&&r.push(g),p.push(Ne(m,w||""))};return N===void 0?$:$(N)}k(o,i)||(o[i]=[]),o[i].push(c===void 0?!0:c),r.push(l)}},onArgument(i,c,l){s!=null&&s(ve,t[c[0]])||(a.push(...i),l?(a[I]=i,t.splice(c[0])):r.push(c))}}),We(t,r),{flags:Ae(e,n),unknownFlags:o,_:a}},L=e=>Array.isArray(e)?e:[e],Le=e=>e.replace(/-([a-z])/g,(t,s)=>s.toUpperCase()),Fe=(e,t)=>t.length!==e.length?!1:e.every((s,r)=>s===t[r]),J=(e,t)=>t.length>e.length?!1:Fe(e.slice(0,t.length),t);class U extends Error{constructor(t){super(`Command "${t}" exists.`),this.commandName=t}}class z extends Error{constructor(t){super(`No such command: ${t}`),this.commandName=t}}class K extends Error{constructor(){super("No command given.")}}class Z extends Error{constructor(t,s){super(`Command name ${t} conflicts with ${s}. Maybe caused by alias.`),this.n1=t,this.n2=s}}class Q extends Error{constructor(){super("Name not set.")}}class X extends Error{constructor(){super("Description not set.")}}class Y extends Error{constructor(){super("Version not set.")}}class ee extends Error{constructor(t){super(`Bad name format: ${t}`),this.commandName=t}}const te=typeof Deno!="undefined",Pe=typeof process!="undefined"&&!te,Be=process.versions.electron&&!process.defaultApp;function se(e,t,s){if(s.alias){const r=L(s.alias);for(const n of r){if(n in t)throw new Z(t[n].name,s.name);e.set(typeof n=="symbol"?n:n.split(" "),{...s,__isAlias:!0})}}}function re(e){const t=new Map;e[u]&&(t.set(u,e[u]),se(t,e,e[u]));for(const s of Object.values(e))se(t,e,s),t.set(s.name.split(" "),s);return t}function ne(e,t){if(t===u)return e[u];const s=L(t),r=re(e);let n,o;return r.forEach((a,i)=>{if(i===u){n=r.get(u),o=u;return}J(s,i)&&(!o||o===u||i.length>o.length)&&(n=a,o=i)}),n}function oe(e,t,s=1/0){const r=t===""?[]:Array.isArray(t)?t:t.split(" ");return Object.values(e).filter(n=>{const o=n.name.split(" ");return J(o,r)&&o.length-r.length<=s})}const De=e=>oe(e,"",1);function ie(e){const t=[];for(const s of e){if(s.startsWith("-"))break;t.push(s)}return t}const F=()=>Pe?process.argv.slice(Be?1:2):te?Deno.args:[];function ae(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 ce=e=>typeof e=="string"&&(e.startsWith(" ")||e.endsWith(" ")),Te=(e,t)=>t?`[${e}]`:`<${e}>`,je="<Root>",le=e=>Array.isArray(e)?e.join(" "):typeof e=="string"?e:je,{stringify:C}=JSON;function P(e){const t=[];let s,r;for(const n of e){if(r)throw new Error(`Invalid parameter: Spread parameter ${C(r)} must be last`);const o=n[0],a=n[n.length-1];let i;if(o==="<"&&a===">"&&(i=!0,s))throw new Error(`Invalid parameter: Required parameter ${C(n)} cannot come after optional parameter ${C(s)}`);if(o==="["&&a==="]"&&(i=!1,s=n),i===void 0)throw new Error(`Invalid parameter: ${C(n)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let c=n.slice(1,-1);const l=c.slice(-3)==="...";l&&(r=n,c=c.slice(0,-3)),t.push({name:c,required:i,spread:l})}return t}function B(e,t,s){for(let r=0;r<t.length;r+=1){const{name:n,required:o,spread:a}=t[r],i=Le(n);if(i in e)return new Error(`Invalid parameter: ${C(n)} is used more than once.`);const c=a?s.slice(r):s[r];if(a&&(r=t.length),o&&(!c||a&&c.length===0))return new Error(`Error: Missing required parameter ${C(n)}`);e[i]=c}}var D=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},h=(e,t,s)=>(D(e,t,"read from private field"),s?s.call(e):t.get(e)),d=(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)},v=(e,t,s,r)=>(D(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),qe=(e,t,s)=>(D(e,t,"access private method"),s),E,y,_,A,b,O,M,W,T,he,j,fe,q,ue;const u=Symbol("Root"),pe=class{constructor(e,t,s){d(this,T),d(this,j),d(this,q),d(this,E,""),d(this,y,""),d(this,_,""),d(this,A,[]),d(this,b,{}),d(this,O,new me),d(this,M,new Set),d(this,W,void 0),v(this,E,e||h(this,E)),v(this,y,t||h(this,y)),v(this,_,s||h(this,_))}get _name(){return h(this,E)}get _description(){return h(this,y)}get _version(){return h(this,_)}get _inspectors(){return h(this,A)}get _commands(){return h(this,b)}static create(e,t,s){return new pe(e,t,s)}name(e){return v(this,E,e),this}description(e){return v(this,y,e),this}version(e){return v(this,_,e),this}command(e,t,s={}){const n=(f=>!(typeof f=="string"||f===u))(e),o=n?e.name:e;if(ce(o))throw new ee(o);const{handler:a=void 0,...i}=n?e:{name:o,description:t,...s},c=[i.name],l=i.alias?L(i.alias):[];i.alias&&c.push(...l);for(const f of c)if(h(this,M).has(f))throw new U(le(f));return h(this,b)[o]=i,h(this,M).add(i.name),l.forEach(f=>h(this,M).add(f)),n&&a&&this.on(e.name,a),this}on(e,t){return h(this,O).on(e,t),this}use(e){return e.setup(this)}inspector(e){return h(this,A).push(e),this}parse(e=F()){const{argv:t,run:s}=Array.isArray(e)?{argv:e,run:!0}:{argv:F(),...e};return v(this,W,t),qe(this,q,ue).call(this),s&&this.runMatchedCommand(),this}runMatchedCommand(){const e=h(this,W);if(!e)throw new Error("cli.parse() must be called.");const t=ie(e),s=t.join(" "),r=()=>ne(h(this,b),t),n=[],o=()=>{n.length=0;const l=r(),f=!!l,p=Re((l==null?void 0:l.flags)||{},[...e]),{_:m,flags:N,unknownFlags:$}=p;let w=!f||l.name===u?m:m.slice(l.name.split(" ").length),g=(l==null?void 0:l.parameters)||[];const R=g.indexOf("--"),G=g.slice(R+1)||[],x=Object.create(null);if(R>-1&&G.length>0){g=g.slice(0,R);const V=m["--"];w=w.slice(0,-V.length||void 0),n.push(B(x,P(g),w)),n.push(B(x,P(G),V))}else n.push(B(x,P(g),w));const de={...N,...$};return{name:l==null?void 0:l.name,called:t.length===0&&(l==null?void 0:l.name)?u:s,resolved:f,hasRootOrAlias:h(this,T,he),hasRoot:h(this,j,fe),raw:{...p,parameters:w,mergedFlags:de},parameters:x,flags:N,unknownFlags:$,cli:this}},a={enforce:"post",fn:()=>{const l=r(),f=o(),p=n.filter(Boolean);if(p.length>0)throw p[0];if(!l)throw s?new z(s):new K;h(this,O).emit(l.name,f)}},i=[...h(this,A),a];return ae(i)(o),this}};let Ge=pe;E=new WeakMap,y=new WeakMap,_=new WeakMap,A=new WeakMap,b=new WeakMap,O=new WeakMap,M=new WeakMap,W=new WeakMap,T=new WeakSet,he=function(){return h(this,M).has(u)},j=new WeakSet,fe=function(){return Object.prototype.hasOwnProperty.call(this._commands,u)},q=new WeakSet,ue=function(){if(!h(this,E))throw new Q;if(!h(this,y))throw new X;if(!h(this,_))throw new Y};const Ve=e=>e,He=(e,t,s)=>s,Je=(e,t)=>t,Ue=(e,t)=>({...e,handler:t});export{Ge as Clerc,U as CommandExistsError,Z as CommandNameConflictError,X as DescriptionNotSetError,ee as InvalidCommandNameError,Q as NameNotSetError,K as NoCommandGivenError,z as NoSuchCommandError,u as Root,Y as VersionNotSetError,ae as compose,Ue as defineCommand,He as defineHandler,Je as defineInspector,Ve as definePlugin,le as formatCommandName,ce as isInvalidName,F as resolveArgv,ne as resolveCommand,re as resolveFlattenCommands,ie as resolveParametersBeforeFlag,De as resolveRootCommands,oe as resolveSubcommandsByParent,Te as withBrackets};
{
"name": "@clerc/core",
"version": "0.26.0",
"version": "0.27.1",
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",

@@ -29,7 +29,7 @@ "description": "Clerc core",

"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
"import": "./dist/index.js"
}
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",

@@ -51,7 +51,7 @@ "typesVersions": {

"devDependencies": {
"is-platform": "^0.2.0",
"is-platform": "^1.0.0",
"lite-emit": "^1.4.0",
"type-fest": "^3.5.3",
"type-flag": "^3.0.0",
"@clerc/utils": "0.26.0"
"@clerc/utils": "0.27.1"
},

@@ -58,0 +58,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc