clerc 0.32.0 → 0.32.1
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 +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{format as Wu}from"node:util";import Bu from"tty";class WD{constructor(){this.listenerMap={},this.wildcardListeners=new Set}on(e,t){return e==="*"?(this.wildcardListeners.add(t),this):(this.listenerMap[e]||(this.listenerMap[e]=new Set),this.listenerMap[e].add(t),this)}emit(e,...t){return this.listenerMap[e]&&(this.wildcardListeners.forEach(n=>n(e,...t)),this.listenerMap[e].forEach(n=>n(...t))),this}off(e,t){var n,s;return e==="**"?(this.listenerMap={},this.wildcardListeners.clear(),this):e==="*"?(t?this.wildcardListeners.delete(t):this.wildcardListeners.clear(),this):(t?(n=this.listenerMap[e])==null||n.delete(t):(s=this.listenerMap[e])==null||s.clear(),this)}}const PD="known-flag",HD="unknown-flag",UD="argument",{stringify:G}=JSON,YD=/\B([A-Z])/g,qD=D=>D.replace(YD,"-$1").toLowerCase(),{hasOwnProperty:zD}=Object.prototype,V=(D,e)=>zD.call(D,e),GD=D=>Array.isArray(D),Pu=D=>typeof D=="function"?[D,!1]:GD(D)?[D[0],!0]:Pu(D.type),VD=(D,e)=>D===Boolean?e!=="false":e,ZD=(D,e)=>typeof e=="boolean"?e:D===Number&&e===""?Number.NaN:D(e),JD=/[\s.:=]/,KD=D=>{const e=`Flag name ${G(D)}`;if(D.length===0)throw new Error(`${e} cannot be empty`);if(D.length===1)throw new Error(`${e} must be longer than a character`);const t=D.match(JD);if(t)throw new Error(`${e} cannot contain ${G(t==null?void 0:t[0])}`)},QD=D=>{const e={},t=(n,s)=>{if(V(e,n))throw new Error(`Duplicate flags named ${G(n)}`);e[n]=s};for(const n in D){if(!V(D,n))continue;KD(n);const s=D[n],r=[[],...Pu(s),s];t(n,r);const u=qD(n);if(n!==u&&t(u,r),"alias"in s&&typeof s.alias=="string"){const{alias:a}=s,o=`Flag alias ${G(a)} for flag ${G(n)}`;if(a.length===0)throw new Error(`${o} cannot be empty`);if(a.length>1)throw new Error(`${o} must be a single character`);t(a,r)}}return e},XD=(D,e)=>{const t={};for(const n in D){if(!V(D,n))continue;const[s,,r,u]=e[n];if(s.length===0&&"default"in u){let{default:a}=u;typeof a=="function"&&(a=a()),t[n]=a}else t[n]=r?s:s.pop()}return t},ru="--",ue=/[.:=]/,De=/^-{1,2}\w/,ee=D=>{if(!De.test(D))return;const e=!D.startsWith(ru);let t=D.slice(e?1:2),n;const s=t.match(ue);if(s){const{index:r}=s;n=t.slice(r+1),t=t.slice(0,r)}return[t,n,e]},te=(D,{onFlag:e,onArgument:t})=>{let n;const s=(r,u)=>{if(typeof n!="function")return!0;n(r,u),n=void 0};for(let r=0;r<D.length;r+=1){const u=D[r];if(u===ru){s();const o=D.slice(r+1);t==null||t(o,[r],!0);break}const a=ee(u);if(a){if(s(),!e)continue;const[o,F,i]=a;if(i)for(let c=0;c<o.length;c+=1){s();const C=c===o.length-1;n=e(o[c],C?F:void 0,[r,c+1,C])}else n=e(o,F,[r])}else s(u,[r])&&(t==null||t([u],[r]))}s()},ne=(D,e)=>{for(const[t,n,s]of e.reverse()){if(n){const r=D[t];let u=r.slice(0,n);if(s||(u+=r.slice(n+1)),u!=="-"){D[t]=u;continue}}D.splice(t,1)}},re=(D,e=process.argv.slice(2),{ignore:t}={})=>{const n=[],s=QD(D),r={},u=[];return u[ru]=[],te(e,{onFlag(a,o,F){const i=V(s,a);if(!(t!=null&&t(i?PD:HD,a,o))){if(i){const[c,C]=s[a],E=VD(C,o),l=(B,h)=>{n.push(F),h&&n.push(h),c.push(ZD(C,B||""))};return E===void 0?l:l(E)}V(r,a)||(r[a]=[]),r[a].push(o===void 0?!0:o),n.push(F)}},onArgument(a,o,F){t!=null&&t(UD,e[o[0]])||(u.push(...a),F?(u[ru]=a,e.splice(o[0])):n.push(o))}}),ne(e,n),{flags:XD(D,s),unknownFlags:r,_:u}};function hu(D){return D!==null&&typeof D=="object"}function pu(D,e,t=".",n){if(!hu(e))return pu(D,{},t,n);const s=Object.assign({},e);for(const r in D){if(r==="__proto__"||r==="constructor")continue;const u=D[r];u!=null&&(n&&n(s,r,u,t)||(Array.isArray(u)&&Array.isArray(s[r])?s[r]=[...u,...s[r]]:hu(u)&&hu(s[r])?s[r]=pu(u,s[r],(t?`${t}.`:"")+r.toString(),n):s[r]=u))}return s}function se(D){return(...e)=>e.reduce((t,n)=>pu(t,n,"",D),{})}const oe=se(),su=D=>Array.isArray(D)?D:[D],ae=D=>D.replace(/[\W_]([a-z\d])?/gi,(e,t)=>t?t.toUpperCase():""),Hu=(D,e)=>e.length!==D.length?!1:D.every((t,n)=>t===e[n]),Uu=(D,e)=>e.length>D.length?!1:Hu(D.slice(0,e.length),e),Z=JSON.stringify;class Yu extends Error{constructor(e,t){super(t("core.commandExists",Z(e))),this.commandName=e}}class ou extends Error{constructor(e,t){super(t("core.noSuchCommand",Z(e))),this.commandName=e}}class au extends Error{constructor(e){super(e("core.noCommandGiven"))}}class qu extends Error{constructor(e,t,n){super(n("core.commandNameConflict",Z(e),Z(t))),this.n1=e,this.n2=t}}class zu extends Error{constructor(e){super(e("core.nameNotSet"))}}class Gu extends Error{constructor(e){super(e("core.descriptionNotSet"))}}class Vu extends Error{constructor(e){super(e("core.versionNotSet"))}}class Zu extends Error{constructor(e,t){super(t("core.badNameFormat",Z(e))),this.commandName=e}}class du extends Error{constructor(e){super(e("core.localeMustBeCalledFirst"))}}const Ju=typeof Deno!="undefined",Fe=typeof process!="undefined"&&!Ju,ie=process.versions.electron&&!process.defaultApp;function Ku(D,e,t,n){if(t.alias){const s=su(t.alias);for(const r of s){if(r in e)throw new qu(e[r].name,t.name,n);D.set(typeof r=="symbol"?r:r.split(" "),{...t,__isAlias:!0})}}}function gu(D,e){const t=new Map;D[p]&&(t.set(p,D[p]),Ku(t,D,D[p],e));for(const n of Object.values(D))Ku(t,D,n,e),t.set(n.name.split(" "),n);return t}function Qu(D,e,t){if(e===p)return[D[p],p];const n=su(e),s=gu(D,t);let r,u;return s.forEach((a,o)=>{if(o===p){r=D[p],u=p;return}Uu(n,o)&&(!u||u===p||o.length>u.length)&&(r=a,u=o)}),[r,u]}function Xu(D,e,t){if(e===p)return[D[p],p];const n=su(e),s=gu(D,t);let r,u;return s.forEach((a,o)=>{o===p||u===p||Hu(n,o)&&(r=a,u=o)}),[r,u]}function uD(D,e,t=1/0){const n=e===""?[]:Array.isArray(e)?e:e.split(" ");return Object.values(D).filter(s=>{const r=s.name.split(" ");return Uu(r,n)&&r.length-n.length<=t})}const Ce=D=>uD(D,"",1);function DD(D){const e=[];for(const t of D){if(t.startsWith("-"))break;e.push(t)}return e}const fu=()=>Fe?process.argv.slice(ie?1:2):Ju?Deno.args:[];function eD(D){const e={pre:[],normal:[],post:[]};for(const n of D){const s=typeof n=="object"?n:{fn:n},{enforce:r,fn:u}=s;r==="post"||r==="pre"?e[r].push(u):e.normal.push(u)}const t=[...e.pre,...e.normal,...e.post];return n=>{const s=[];r(0);for(let u=s.length-1;u>=0;u--)s[u]();function r(u){const a=t[u],o=a(n(),r.bind(null,u+1));o&&s.push(o)}}}const le=/\s\s+/,tD=D=>D===p?!0:!(D.startsWith(" ")||D.endsWith(" "))&&!le.test(D),nD=(D,e)=>e?`[${D}]`:`<${D}>`,ce="<Root>",U=D=>Array.isArray(D)?D.join(" "):typeof D=="string"?D:ce,rD=()=>process.env.CLERC_LOCALE?process.env.CLERC_LOCALE:Intl.DateTimeFormat().resolvedOptions().locale,{stringify:Y}=JSON;function Au(D,e){const t=[];let n,s;for(const r of D){if(s)throw new Error(e("core.spreadParameterMustBeLast",Y(s)));const u=r[0],a=r[r.length-1];let o;if(u==="<"&&a===">"&&(o=!0,n))throw new Error(e("core.requiredParameterMustBeBeforeOptional",Y(r),Y(n)));if(u==="["&&a==="]"&&(o=!1,n=r),o===void 0)throw new Error(e("core.parameterMustBeWrappedInBrackets",Y(r)));let F=r.slice(1,-1);const i=F.slice(-3)==="...";i&&(s=r,F=F.slice(0,-3)),t.push({name:F,required:o,spread:i})}return t}function xu(D,e,t,n){for(let s=0;s<e.length;s+=1){const{name:r,required:u,spread:a}=e[s],o=ae(r);if(o in D)throw new Error(n("core.parameterIsUsedMoreThanOnce",Y(r)));const F=a?t.slice(s):t[s];if(a&&(s=e.length),u&&(!F||a&&F.length===0))throw new Error(n("core.missingRequiredParameter",Y(r)));D[o]=F}}const Ee={en:{"core.commandExists":'Command "%s" exists.',"core.noSuchCommand":"No such command: %s.","core.noCommandGiven":"No command given.","core.commandNameConflict":"Command name %s conflicts with %s. Maybe caused by alias.","core.nameNotSet":"Name not set.","core.descriptionNotSet":"Description not set.","core.versionNotSet":"Version not set.","core.badNameFormat":"Bad name format: %s.","core.localeMustBeCalledFirst":"locale() or fallbackLocale() must be called at first.","core.cliParseMustBeCalled":"cli.parse() must be called.","core.spreadParameterMustBeLast":"Invalid Parameter: Spread parameter %s must be last.","core.requiredParameterCannotComeAfterOptionalParameter":"Invalid Parameter: Required parameter %s cannot come after optional parameter %s.","core.parameterMustBeWrappedInBrackets":"Invalid Parameter: Parameter %s must be wrapped in <> (required parameter) or [] (optional parameter).","core.parameterIsUsedMoreThanOnce":"Invalid Parameter: Parameter %s is used more than once.","core.missingRequiredParameter":"Missing required parameter %s."},"zh-CN":{"core.commandExists":'\u547D\u4EE4 "%s" \u5DF2\u5B58\u5728\u3002',"core.noSuchCommand":"\u627E\u4E0D\u5230\u547D\u4EE4: %s\u3002","core.noCommandGiven":"\u6CA1\u6709\u8F93\u5165\u547D\u4EE4\u3002","core.commandNameConflict":"\u547D\u4EE4\u540D\u79F0 %s \u548C %s \u51B2\u7A81\u3002 \u53EF\u80FD\u662F\u7531\u4E8E\u522B\u540D\u5BFC\u81F4\u7684\u3002","core.nameNotSet":"\u672A\u8BBE\u7F6ECLI\u540D\u79F0\u3002","core.descriptionNotSet":"\u672A\u8BBE\u7F6ECLI\u63CF\u8FF0\u3002","core.versionNotSet":"\u672A\u8BBE\u7F6ECLI\u7248\u672C\u3002","core.badNameFormat":"\u9519\u8BEF\u7684\u547D\u4EE4\u540D\u5B57\u683C\u5F0F: %s\u3002","core.localeMustBeCalledFirst":"locale() \u6216 fallbackLocale() \u5FC5\u987B\u5728\u6700\u5F00\u59CB\u8C03\u7528\u3002","core.cliParseMustBeCalled":"cli.parse() \u5FC5\u987B\u88AB\u8C03\u7528\u3002","core.spreadParameterMustBeLast":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5C55\u5F00\u53C2\u6570 %s \u5FC5\u987B\u5728\u6700\u540E\u3002","core.requiredParameterCannotComeAfterOptionalParameter":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5FC5\u586B\u53C2\u6570 %s \u4E0D\u80FD\u5728\u53EF\u9009\u53C2\u6570 %s \u4E4B\u540E\u3002","core.parameterMustBeWrappedInBrackets":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u5FC5\u987B\u88AB <> (\u5FC5\u586B\u53C2\u6570) \u6216 [] (\u53EF\u9009\u53C2\u6570) \u5305\u88F9\u3002","core.parameterIsUsedMoreThanOnce":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u88AB\u4F7F\u7528\u4E86\u591A\u6B21\u3002","core.missingRequiredParameter":"\u7F3A\u5C11\u5FC5\u586B\u53C2\u6570 %s\u3002"}};var $u=(D,e,t)=>{if(!e.has(D))throw TypeError("Cannot "+t)},m=(D,e,t)=>($u(D,e,"read from private field"),t?t.call(D):e.get(D)),x=(D,e,t)=>{if(e.has(D))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(D):e.set(D,t)},w=(D,e,t,n)=>($u(D,e,"write to private field"),n?n.call(D,t):e.set(D,t),t),$=(D,e,t)=>($u(D,e,"access private method"),t),k,I,R,J,K,Fu,q,Q,X,uu,Du,eu,j,Su,sD,wu,oD,bu,aD,M,T,yu,FD,vu,iD,Ou,CD,iu,Mu,_u,lD;const p=Symbol.for("Clerc.Root"),cD=class{constructor(D,e,t){x(this,Su),x(this,wu),x(this,bu),x(this,M),x(this,yu),x(this,vu),x(this,Ou),x(this,iu),x(this,_u),x(this,k,""),x(this,I,""),x(this,R,""),x(this,J,[]),x(this,K,{}),x(this,Fu,new WD),x(this,q,new Set),x(this,Q,void 0),x(this,X,[]),x(this,uu,!1),x(this,Du,"en"),x(this,eu,"en"),x(this,j,{}),this.i18n={add:n=>{w(this,j,oe(m(this,j),n))},t:(n,...s)=>{const r=m(this,j)[m(this,eu)]||m(this,j)[m(this,Du)],u=m(this,j)[m(this,Du)];return r[n]?Wu(r[n],...s):u[n]?Wu(u[n],...s):void 0}},w(this,k,D||m(this,k)),w(this,I,e||m(this,I)),w(this,R,t||m(this,R)),w(this,eu,rD()),$(this,bu,aD).call(this)}get _name(){return m(this,k)}get _description(){return m(this,I)}get _version(){return m(this,R)}get _inspectors(){return m(this,J)}get _commands(){return m(this,K)}static create(D,e,t){return new cD(D,e,t)}name(D){return $(this,M,T).call(this),w(this,k,D),this}description(D){return $(this,M,T).call(this),w(this,I,D),this}version(D){return $(this,M,T).call(this),w(this,R,D),this}locale(D){if(m(this,uu))throw new du(this.i18n.t);return w(this,eu,D),this}fallbackLocale(D){if(m(this,uu))throw new du(this.i18n.t);return w(this,Du,D),this}errorHandler(D){return m(this,X).push(D),this}command(D,e,t={}){return $(this,iu,Mu).call(this,()=>$(this,yu,FD).call(this,D,e,t)),this}on(D,e){return m(this,Fu).on(D,e),this}use(D){return $(this,M,T).call(this),D.setup(this)}inspector(D){return $(this,M,T).call(this),m(this,J).push(D),this}parse(D=fu()){$(this,M,T).call(this);const{argv:e,run:t}=Array.isArray(D)?{argv:D,run:!0}:{argv:fu(),...D};return w(this,Q,[...e]),$(this,vu,iD).call(this),t&&this.runMatchedCommand(),this}runMatchedCommand(){return $(this,iu,Mu).call(this,()=>$(this,_u,lD).call(this)),process.title=m(this,k),this}};let me=cD;k=new WeakMap,I=new WeakMap,R=new WeakMap,J=new WeakMap,K=new WeakMap,Fu=new WeakMap,q=new WeakMap,Q=new WeakMap,X=new WeakMap,uu=new WeakMap,Du=new WeakMap,eu=new WeakMap,j=new WeakMap,Su=new WeakSet,sD=function(){return m(this,q).has(p)},wu=new WeakSet,oD=function(){return Object.prototype.hasOwnProperty.call(this._commands,p)},bu=new WeakSet,aD=function(){this.i18n.add(Ee)},M=new WeakSet,T=function(){w(this,uu,!0)},yu=new WeakSet,FD=function(D,e,t={}){$(this,M,T).call(this);const{t:n}=this.i18n,s=(i=>!(typeof i=="string"||i===p))(D),r=s?D.name:D;if(!tD(r))throw new Zu(r,n);const{handler:u=void 0,...a}=s?D:{name:r,description:e,...t},o=[a.name],F=a.alias?su(a.alias):[];a.alias&&o.push(...F);for(const i of o)if(m(this,q).has(i))throw new Yu(U(i),n);return m(this,K)[r]=a,m(this,q).add(a.name),F.forEach(i=>m(this,q).add(i)),s&&u&&this.on(D.name,u),this},vu=new WeakSet,iD=function(){const{t:D}=this.i18n;if(!m(this,k))throw new zu(D);if(!m(this,I))throw new Gu(D);if(!m(this,R))throw new Vu(D)},Ou=new WeakSet,CD=function(D){const e=m(this,Q),{t}=this.i18n,[n,s]=D(),r=!!n,u=re((n==null?void 0:n.flags)||{},[...e]),{_:a,flags:o,unknownFlags:F}=u;let i=!r||n.name===p?a:a.slice(n.name.split(" ").length),c=(n==null?void 0:n.parameters)||[];const C=c.indexOf("--"),E=c.slice(C+1)||[],l=Object.create(null);if(C>-1&&E.length>0){c=c.slice(0,C);const h=a["--"];i=i.slice(0,-h.length||void 0),xu(l,Au(c,t),i,t),xu(l,Au(E,t),h,t)}else xu(l,Au(c,t),i,t);const B={...o,...F};return{name:n==null?void 0:n.name,called:Array.isArray(s)?s.join(" "):s,resolved:r,hasRootOrAlias:m(this,Su,sD),hasRoot:m(this,wu,oD),raw:{...u,parameters:i,mergedFlags:B},parameters:l,flags:o,unknownFlags:F,cli:this}},iu=new WeakSet,Mu=function(D){try{D()}catch(e){if(m(this,X).length>0)m(this,X).forEach(t=>t(e));else throw e}},_u=new WeakSet,lD=function(){$(this,M,T).call(this);const{t:D}=this.i18n,e=m(this,Q);if(!e)throw new Error(D("core.cliParseMustBeCalled"));const t=DD(e),n=t.join(" "),s=()=>Qu(m(this,K),t,D),r=()=>$(this,Ou,CD).call(this,s),u={enforce:"post",fn:()=>{const[o]=s(),F=r();if(!o)throw n?new ou(n,D):new au(D);m(this,Fu).emit(o.name,F)}},a=[...m(this,J),u];eD(a)(r)};const W=D=>D,Be=(D,e,t)=>t,he=(D,e)=>e,pe=(D,e)=>({...D,handler:e}),de=D=>`
|
|
1
|
+
import{format as Wu}from"node:util";import Bu from"tty";class WD{constructor(){this.listenerMap={},this.wildcardListeners=new Set}on(e,t){return e==="*"?(this.wildcardListeners.add(t),this):(this.listenerMap[e]||(this.listenerMap[e]=new Set),this.listenerMap[e].add(t),this)}emit(e,...t){return this.listenerMap[e]&&(this.wildcardListeners.forEach(n=>n(e,...t)),this.listenerMap[e].forEach(n=>n(...t))),this}off(e,t){var n,s;return e==="**"?(this.listenerMap={},this.wildcardListeners.clear(),this):e==="*"?(t?this.wildcardListeners.delete(t):this.wildcardListeners.clear(),this):(t?(n=this.listenerMap[e])==null||n.delete(t):(s=this.listenerMap[e])==null||s.clear(),this)}}const PD="known-flag",HD="unknown-flag",UD="argument",{stringify:G}=JSON,YD=/\B([A-Z])/g,qD=D=>D.replace(YD,"-$1").toLowerCase(),{hasOwnProperty:zD}=Object.prototype,V=(D,e)=>zD.call(D,e),GD=D=>Array.isArray(D),Pu=D=>typeof D=="function"?[D,!1]:GD(D)?[D[0],!0]:Pu(D.type),VD=(D,e)=>D===Boolean?e!=="false":e,ZD=(D,e)=>typeof e=="boolean"?e:D===Number&&e===""?Number.NaN:D(e),JD=/[\s.:=]/,KD=D=>{const e=`Flag name ${G(D)}`;if(D.length===0)throw new Error(`${e} cannot be empty`);if(D.length===1)throw new Error(`${e} must be longer than a character`);const t=D.match(JD);if(t)throw new Error(`${e} cannot contain ${G(t==null?void 0:t[0])}`)},QD=D=>{const e={},t=(n,s)=>{if(V(e,n))throw new Error(`Duplicate flags named ${G(n)}`);e[n]=s};for(const n in D){if(!V(D,n))continue;KD(n);const s=D[n],r=[[],...Pu(s),s];t(n,r);const u=qD(n);if(n!==u&&t(u,r),"alias"in s&&typeof s.alias=="string"){const{alias:a}=s,o=`Flag alias ${G(a)} for flag ${G(n)}`;if(a.length===0)throw new Error(`${o} cannot be empty`);if(a.length>1)throw new Error(`${o} must be a single character`);t(a,r)}}return e},XD=(D,e)=>{const t={};for(const n in D){if(!V(D,n))continue;const[s,,r,u]=e[n];if(s.length===0&&"default"in u){let{default:a}=u;typeof a=="function"&&(a=a()),t[n]=a}else t[n]=r?s:s.pop()}return t},ru="--",ue=/[.:=]/,De=/^-{1,2}\w/,ee=D=>{if(!De.test(D))return;const e=!D.startsWith(ru);let t=D.slice(e?1:2),n;const s=t.match(ue);if(s){const{index:r}=s;n=t.slice(r+1),t=t.slice(0,r)}return[t,n,e]},te=(D,{onFlag:e,onArgument:t})=>{let n;const s=(r,u)=>{if(typeof n!="function")return!0;n(r,u),n=void 0};for(let r=0;r<D.length;r+=1){const u=D[r];if(u===ru){s();const o=D.slice(r+1);t==null||t(o,[r],!0);break}const a=ee(u);if(a){if(s(),!e)continue;const[o,F,i]=a;if(i)for(let c=0;c<o.length;c+=1){s();const C=c===o.length-1;n=e(o[c],C?F:void 0,[r,c+1,C])}else n=e(o,F,[r])}else s(u,[r])&&(t==null||t([u],[r]))}s()},ne=(D,e)=>{for(const[t,n,s]of e.reverse()){if(n){const r=D[t];let u=r.slice(0,n);if(s||(u+=r.slice(n+1)),u!=="-"){D[t]=u;continue}}D.splice(t,1)}},re=(D,e=process.argv.slice(2),{ignore:t}={})=>{const n=[],s=QD(D),r={},u=[];return u[ru]=[],te(e,{onFlag(a,o,F){const i=V(s,a);if(!(t!=null&&t(i?PD:HD,a,o))){if(i){const[c,C]=s[a],E=VD(C,o),l=(B,h)=>{n.push(F),h&&n.push(h),c.push(ZD(C,B||""))};return E===void 0?l:l(E)}V(r,a)||(r[a]=[]),r[a].push(o===void 0?!0:o),n.push(F)}},onArgument(a,o,F){t!=null&&t(UD,e[o[0]])||(u.push(...a),F?(u[ru]=a,e.splice(o[0])):n.push(o))}}),ne(e,n),{flags:XD(D,s),unknownFlags:r,_:u}};function hu(D){return D!==null&&typeof D=="object"}function pu(D,e,t=".",n){if(!hu(e))return pu(D,{},t,n);const s=Object.assign({},e);for(const r in D){if(r==="__proto__"||r==="constructor")continue;const u=D[r];u!=null&&(n&&n(s,r,u,t)||(Array.isArray(u)&&Array.isArray(s[r])?s[r]=[...u,...s[r]]:hu(u)&&hu(s[r])?s[r]=pu(u,s[r],(t?`${t}.`:"")+r.toString(),n):s[r]=u))}return s}function se(D){return(...e)=>e.reduce((t,n)=>pu(t,n,"",D),{})}const oe=se(),su=D=>Array.isArray(D)?D:[D],ae=D=>D.replace(/[\W_]([a-z\d])?/gi,(e,t)=>t?t.toUpperCase():""),Hu=(D,e)=>e.length!==D.length?!1:D.every((t,n)=>t===e[n]),Uu=(D,e)=>e.length>D.length?!1:Hu(D.slice(0,e.length),e),Z=JSON.stringify;class Yu extends Error{constructor(e,t){super(t("core.commandExists",Z(e))),this.commandName=e}}class ou extends Error{constructor(e,t){super(t("core.noSuchCommand",Z(e))),this.commandName=e}}class au extends Error{constructor(e){super(e("core.noCommandGiven"))}}class qu extends Error{constructor(e,t,n){super(n("core.commandNameConflict",Z(e),Z(t))),this.n1=e,this.n2=t}}class zu extends Error{constructor(e){super(e("core.nameNotSet"))}}class Gu extends Error{constructor(e){super(e("core.descriptionNotSet"))}}class Vu extends Error{constructor(e){super(e("core.versionNotSet"))}}class Zu extends Error{constructor(e,t){super(t("core.badNameFormat",Z(e))),this.commandName=e}}class du extends Error{constructor(e){super(e("core.localeMustBeCalledFirst"))}}const Ju=typeof Deno!="undefined",Fe=typeof process!="undefined"&&!Ju,ie=process.versions.electron&&!process.defaultApp;function Ku(D,e,t,n){if(t.alias){const s=su(t.alias);for(const r of s){if(r in e)throw new qu(e[r].name,t.name,n);D.set(typeof r=="symbol"?r:r.split(" "),{...t,__isAlias:!0})}}}function gu(D,e){const t=new Map;D[p]&&(t.set(p,D[p]),Ku(t,D,D[p],e));for(const n of Object.values(D))Ku(t,D,n,e),t.set(n.name.split(" "),n);return t}function Qu(D,e,t){if(e===p)return[D[p],p];const n=su(e),s=gu(D,t);let r,u;return s.forEach((a,o)=>{if(o===p){r=D[p],u=p;return}Uu(n,o)&&(!u||u===p||o.length>u.length)&&(r=a,u=o)}),[r,u]}function Xu(D,e,t){if(e===p)return[D[p],p];const n=su(e),s=gu(D,t);let r,u;return s.forEach((a,o)=>{o===p||u===p||Hu(n,o)&&(r=a,u=o)}),[r,u]}function uD(D,e,t=1/0){const n=e===""?[]:Array.isArray(e)?e:e.split(" ");return Object.values(D).filter(s=>{const r=s.name.split(" ");return Uu(r,n)&&r.length-n.length<=t})}const Ce=D=>uD(D,"",1);function DD(D){const e=[];for(const t of D){if(t.startsWith("-"))break;e.push(t)}return e}const fu=()=>Fe?process.argv.slice(ie?1:2):Ju?Deno.args:[];function eD(D){const e={pre:[],normal:[],post:[]};for(const n of D){const s=typeof n=="object"?n:{fn:n},{enforce:r,fn:u}=s;r==="post"||r==="pre"?e[r].push(u):e.normal.push(u)}const t=[...e.pre,...e.normal,...e.post];return n=>{const s=[];let r=0;const u=a=>{r=a;const o=t[a],F=o(n(),u.bind(null,a+1));F&&s.push(F)};if(u(0),r+1===t.length)for(const a of s)a()}}const le=/\s\s+/,tD=D=>D===p?!0:!(D.startsWith(" ")||D.endsWith(" "))&&!le.test(D),nD=(D,e)=>e?`[${D}]`:`<${D}>`,ce="<Root>",U=D=>Array.isArray(D)?D.join(" "):typeof D=="string"?D:ce,rD=()=>process.env.CLERC_LOCALE?process.env.CLERC_LOCALE:Intl.DateTimeFormat().resolvedOptions().locale,{stringify:Y}=JSON;function Au(D,e){const t=[];let n,s;for(const r of D){if(s)throw new Error(e("core.spreadParameterMustBeLast",Y(s)));const u=r[0],a=r[r.length-1];let o;if(u==="<"&&a===">"&&(o=!0,n))throw new Error(e("core.requiredParameterMustBeBeforeOptional",Y(r),Y(n)));if(u==="["&&a==="]"&&(o=!1,n=r),o===void 0)throw new Error(e("core.parameterMustBeWrappedInBrackets",Y(r)));let F=r.slice(1,-1);const i=F.slice(-3)==="...";i&&(s=r,F=F.slice(0,-3)),t.push({name:F,required:o,spread:i})}return t}function xu(D,e,t,n){for(let s=0;s<e.length;s+=1){const{name:r,required:u,spread:a}=e[s],o=ae(r);if(o in D)throw new Error(n("core.parameterIsUsedMoreThanOnce",Y(r)));const F=a?t.slice(s):t[s];if(a&&(s=e.length),u&&(!F||a&&F.length===0))throw new Error(n("core.missingRequiredParameter",Y(r)));D[o]=F}}const Ee={en:{"core.commandExists":'Command "%s" exists.',"core.noSuchCommand":"No such command: %s.","core.noCommandGiven":"No command given.","core.commandNameConflict":"Command name %s conflicts with %s. Maybe caused by alias.","core.nameNotSet":"Name not set.","core.descriptionNotSet":"Description not set.","core.versionNotSet":"Version not set.","core.badNameFormat":"Bad name format: %s.","core.localeMustBeCalledFirst":"locale() or fallbackLocale() must be called at first.","core.cliParseMustBeCalled":"cli.parse() must be called.","core.spreadParameterMustBeLast":"Invalid Parameter: Spread parameter %s must be last.","core.requiredParameterCannotComeAfterOptionalParameter":"Invalid Parameter: Required parameter %s cannot come after optional parameter %s.","core.parameterMustBeWrappedInBrackets":"Invalid Parameter: Parameter %s must be wrapped in <> (required parameter) or [] (optional parameter).","core.parameterIsUsedMoreThanOnce":"Invalid Parameter: Parameter %s is used more than once.","core.missingRequiredParameter":"Missing required parameter %s."},"zh-CN":{"core.commandExists":'\u547D\u4EE4 "%s" \u5DF2\u5B58\u5728\u3002',"core.noSuchCommand":"\u627E\u4E0D\u5230\u547D\u4EE4: %s\u3002","core.noCommandGiven":"\u6CA1\u6709\u8F93\u5165\u547D\u4EE4\u3002","core.commandNameConflict":"\u547D\u4EE4\u540D\u79F0 %s \u548C %s \u51B2\u7A81\u3002 \u53EF\u80FD\u662F\u7531\u4E8E\u522B\u540D\u5BFC\u81F4\u7684\u3002","core.nameNotSet":"\u672A\u8BBE\u7F6ECLI\u540D\u79F0\u3002","core.descriptionNotSet":"\u672A\u8BBE\u7F6ECLI\u63CF\u8FF0\u3002","core.versionNotSet":"\u672A\u8BBE\u7F6ECLI\u7248\u672C\u3002","core.badNameFormat":"\u9519\u8BEF\u7684\u547D\u4EE4\u540D\u5B57\u683C\u5F0F: %s\u3002","core.localeMustBeCalledFirst":"locale() \u6216 fallbackLocale() \u5FC5\u987B\u5728\u6700\u5F00\u59CB\u8C03\u7528\u3002","core.cliParseMustBeCalled":"cli.parse() \u5FC5\u987B\u88AB\u8C03\u7528\u3002","core.spreadParameterMustBeLast":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5C55\u5F00\u53C2\u6570 %s \u5FC5\u987B\u5728\u6700\u540E\u3002","core.requiredParameterCannotComeAfterOptionalParameter":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u5FC5\u586B\u53C2\u6570 %s \u4E0D\u80FD\u5728\u53EF\u9009\u53C2\u6570 %s \u4E4B\u540E\u3002","core.parameterMustBeWrappedInBrackets":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u5FC5\u987B\u88AB <> (\u5FC5\u586B\u53C2\u6570) \u6216 [] (\u53EF\u9009\u53C2\u6570) \u5305\u88F9\u3002","core.parameterIsUsedMoreThanOnce":"\u4E0D\u5408\u6CD5\u7684\u53C2\u6570: \u53C2\u6570 %s \u88AB\u4F7F\u7528\u4E86\u591A\u6B21\u3002","core.missingRequiredParameter":"\u7F3A\u5C11\u5FC5\u586B\u53C2\u6570 %s\u3002"}};var $u=(D,e,t)=>{if(!e.has(D))throw TypeError("Cannot "+t)},m=(D,e,t)=>($u(D,e,"read from private field"),t?t.call(D):e.get(D)),x=(D,e,t)=>{if(e.has(D))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(D):e.set(D,t)},w=(D,e,t,n)=>($u(D,e,"write to private field"),n?n.call(D,t):e.set(D,t),t),$=(D,e,t)=>($u(D,e,"access private method"),t),k,I,R,J,K,Fu,q,Q,X,uu,Du,eu,j,Su,sD,wu,oD,bu,aD,M,T,yu,FD,vu,iD,Ou,CD,iu,Mu,_u,lD;const p=Symbol.for("Clerc.Root"),cD=class{constructor(D,e,t){x(this,Su),x(this,wu),x(this,bu),x(this,M),x(this,yu),x(this,vu),x(this,Ou),x(this,iu),x(this,_u),x(this,k,""),x(this,I,""),x(this,R,""),x(this,J,[]),x(this,K,{}),x(this,Fu,new WD),x(this,q,new Set),x(this,Q,void 0),x(this,X,[]),x(this,uu,!1),x(this,Du,"en"),x(this,eu,"en"),x(this,j,{}),this.i18n={add:n=>{w(this,j,oe(m(this,j),n))},t:(n,...s)=>{const r=m(this,j)[m(this,eu)]||m(this,j)[m(this,Du)],u=m(this,j)[m(this,Du)];return r[n]?Wu(r[n],...s):u[n]?Wu(u[n],...s):void 0}},w(this,k,D||m(this,k)),w(this,I,e||m(this,I)),w(this,R,t||m(this,R)),w(this,eu,rD()),$(this,bu,aD).call(this)}get _name(){return m(this,k)}get _description(){return m(this,I)}get _version(){return m(this,R)}get _inspectors(){return m(this,J)}get _commands(){return m(this,K)}static create(D,e,t){return new cD(D,e,t)}name(D){return $(this,M,T).call(this),w(this,k,D),this}description(D){return $(this,M,T).call(this),w(this,I,D),this}version(D){return $(this,M,T).call(this),w(this,R,D),this}locale(D){if(m(this,uu))throw new du(this.i18n.t);return w(this,eu,D),this}fallbackLocale(D){if(m(this,uu))throw new du(this.i18n.t);return w(this,Du,D),this}errorHandler(D){return m(this,X).push(D),this}command(D,e,t={}){return $(this,iu,Mu).call(this,()=>$(this,yu,FD).call(this,D,e,t)),this}on(D,e){return m(this,Fu).on(D,e),this}use(D){return $(this,M,T).call(this),D.setup(this)}inspector(D){return $(this,M,T).call(this),m(this,J).push(D),this}parse(D=fu()){$(this,M,T).call(this);const{argv:e,run:t}=Array.isArray(D)?{argv:D,run:!0}:{argv:fu(),...D};return w(this,Q,[...e]),$(this,vu,iD).call(this),t&&this.runMatchedCommand(),this}runMatchedCommand(){return $(this,iu,Mu).call(this,()=>$(this,_u,lD).call(this)),process.title=m(this,k),this}};let me=cD;k=new WeakMap,I=new WeakMap,R=new WeakMap,J=new WeakMap,K=new WeakMap,Fu=new WeakMap,q=new WeakMap,Q=new WeakMap,X=new WeakMap,uu=new WeakMap,Du=new WeakMap,eu=new WeakMap,j=new WeakMap,Su=new WeakSet,sD=function(){return m(this,q).has(p)},wu=new WeakSet,oD=function(){return Object.prototype.hasOwnProperty.call(this._commands,p)},bu=new WeakSet,aD=function(){this.i18n.add(Ee)},M=new WeakSet,T=function(){w(this,uu,!0)},yu=new WeakSet,FD=function(D,e,t={}){$(this,M,T).call(this);const{t:n}=this.i18n,s=(i=>!(typeof i=="string"||i===p))(D),r=s?D.name:D;if(!tD(r))throw new Zu(r,n);const{handler:u=void 0,...a}=s?D:{name:r,description:e,...t},o=[a.name],F=a.alias?su(a.alias):[];a.alias&&o.push(...F);for(const i of o)if(m(this,q).has(i))throw new Yu(U(i),n);return m(this,K)[r]=a,m(this,q).add(a.name),F.forEach(i=>m(this,q).add(i)),s&&u&&this.on(D.name,u),this},vu=new WeakSet,iD=function(){const{t:D}=this.i18n;if(!m(this,k))throw new zu(D);if(!m(this,I))throw new Gu(D);if(!m(this,R))throw new Vu(D)},Ou=new WeakSet,CD=function(D){const e=m(this,Q),{t}=this.i18n,[n,s]=D(),r=!!n,u=re((n==null?void 0:n.flags)||{},[...e]),{_:a,flags:o,unknownFlags:F}=u;let i=!r||n.name===p?a:a.slice(n.name.split(" ").length),c=(n==null?void 0:n.parameters)||[];const C=c.indexOf("--"),E=c.slice(C+1)||[],l=Object.create(null);if(C>-1&&E.length>0){c=c.slice(0,C);const h=a["--"];i=i.slice(0,-h.length||void 0),xu(l,Au(c,t),i,t),xu(l,Au(E,t),h,t)}else xu(l,Au(c,t),i,t);const B={...o,...F};return{name:n==null?void 0:n.name,called:Array.isArray(s)?s.join(" "):s,resolved:r,hasRootOrAlias:m(this,Su,sD),hasRoot:m(this,wu,oD),raw:{...u,parameters:i,mergedFlags:B},parameters:l,flags:o,unknownFlags:F,cli:this}},iu=new WeakSet,Mu=function(D){try{D()}catch(e){if(m(this,X).length>0)m(this,X).forEach(t=>t(e));else throw e}},_u=new WeakSet,lD=function(){$(this,M,T).call(this);const{t:D}=this.i18n,e=m(this,Q);if(!e)throw new Error(D("core.cliParseMustBeCalled"));const t=DD(e),n=t.join(" "),s=()=>Qu(m(this,K),t,D),r=()=>$(this,Ou,CD).call(this,s),u={enforce:"post",fn:()=>{const[o]=s(),F=r();if(!o)throw n?new ou(n,D):new au(D);m(this,Fu).emit(o.name,F)}},a=[...m(this,J),u];eD(a)(r)};const W=D=>D,Be=(D,e,t)=>t,he=(D,e)=>e,pe=(D,e)=>({...D,handler:e}),de=D=>`
|
|
2
2
|
${D})
|
|
3
3
|
cmd+="__${D}"
|
|
4
4
|
;;`,ge=D=>{const{cli:e}=D,{_name:t,_commands:n}=e;return`_${t}() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clerc",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc: The full-featured cli framework.",
|
|
6
6
|
"keywords": [
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@clerc/core": "0.32.
|
|
51
|
-
"@clerc/plugin-
|
|
52
|
-
"@clerc/plugin-
|
|
53
|
-
"@clerc/plugin-
|
|
54
|
-
"@clerc/plugin-
|
|
55
|
-
"@clerc/plugin-
|
|
56
|
-
"@clerc/plugin-
|
|
50
|
+
"@clerc/core": "0.32.1",
|
|
51
|
+
"@clerc/plugin-version": "0.32.1",
|
|
52
|
+
"@clerc/plugin-completions": "0.32.1",
|
|
53
|
+
"@clerc/plugin-strict-flags": "0.32.1",
|
|
54
|
+
"@clerc/plugin-friendly-error": "0.32.1",
|
|
55
|
+
"@clerc/plugin-not-found": "0.32.1",
|
|
56
|
+
"@clerc/plugin-help": "0.32.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "puild --minify",
|