clerc 0.35.0 → 0.36.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.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/dist/index.js +1 -1
  3. package/package.json +9 -9
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Ray <https://github.com/so1ve>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ray <https://github.com/so1ve>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{format as Pu}from"node:util";import du from"tty";class PD{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,r;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):(r=this.listenerMap[e])==null||r.clear(),this)}}const HD="known-flag",UD="unknown-flag",GD="argument",{stringify:q}=JSON,zD=/\B([A-Z])/g,YD=u=>u.replace(zD,"-$1").toLowerCase(),{hasOwnProperty:qD}=Object.prototype,Z=(u,e)=>qD.call(u,e),ZD=u=>Array.isArray(u),Hu=u=>typeof u=="function"?[u,!1]:ZD(u)?[u[0],!0]:Hu(u.type),VD=(u,e)=>u===Boolean?e!=="false":e,JD=(u,e)=>typeof e=="boolean"?e:u===Number&&e===""?Number.NaN:u(e),KD=/[\s.:=]/,QD=u=>{const e=`Flag name ${q(u)}`;if(u.length===0)throw new Error(`${e} cannot be empty`);if(u.length===1)throw new Error(`${e} must be longer than a character`);const t=u.match(KD);if(t)throw new Error(`${e} cannot contain ${q(t==null?void 0:t[0])}`)},XD=u=>{const e={},t=(n,r)=>{if(Z(e,n))throw new Error(`Duplicate flags named ${q(n)}`);e[n]=r};for(const n in u){if(!Z(u,n))continue;QD(n);const r=u[n],s=[[],...Hu(r),r];t(n,s);const D=YD(n);if(n!==D&&t(D,s),"alias"in r&&typeof r.alias=="string"){const{alias:i}=r,o=`Flag alias ${q(i)} for flag ${q(n)}`;if(i.length===0)throw new Error(`${o} cannot be empty`);if(i.length>1)throw new Error(`${o} must be a single character`);t(i,s)}}return e},ue=(u,e)=>{const t={};for(const n in u){if(!Z(u,n))continue;const[r,,s,D]=e[n];if(r.length===0&&"default"in D){let{default:i}=D;typeof i=="function"&&(i=i()),t[n]=i}else t[n]=s?r:r.pop()}return t},ou="--",De=/[.:=]/,ee=/^-{1,2}\w/,te=u=>{if(!ee.test(u))return;const e=!u.startsWith(ou);let t=u.slice(e?1:2),n;const r=t.match(De);if(r){const{index:s}=r;n=t.slice(s+1),t=t.slice(0,s)}return[t,n,e]},ne=(u,{onFlag:e,onArgument:t})=>{let n;const r=(s,D)=>{if(typeof n!="function")return!0;n(s,D),n=void 0};for(let s=0;s<u.length;s+=1){const D=u[s];if(D===ou){r();const o=u.slice(s+1);t==null||t(o,[s],!0);break}const i=te(D);if(i){if(r(),!e)continue;const[o,a,F]=i;if(F)for(let l=0;l<o.length;l+=1){r();const C=l===o.length-1;n=e(o[l],C?a:void 0,[s,l+1,C])}else n=e(o,a,[s])}else r(D,[s])&&(t==null||t([D],[s]))}r()},re=(u,e)=>{for(const[t,n,r]of e.reverse()){if(n){const s=u[t];let D=s.slice(0,n);if(r||(D+=s.slice(n+1)),D!=="-"){u[t]=D;continue}}u.splice(t,1)}},Uu=(u,e=process.argv.slice(2),{ignore:t}={})=>{const n=[],r=XD(u),s={},D=[];return D[ou]=[],ne(e,{onFlag(i,o,a){const F=Z(r,i);if(!(t!=null&&t(F?HD:UD,i,o))){if(F){const[l,C]=r[i],E=VD(C,o),c=(h,p)=>{n.push(a),p&&n.push(p),l.push(JD(C,h||""))};return E===void 0?c:c(E)}Z(s,i)||(s[i]=[]),s[i].push(o===void 0?!0:o),n.push(a)}},onArgument(i,o,a){t!=null&&t(GD,e[o[0]])||(D.push(...i),a?(D[ou]=i,e.splice(o[0])):n.push(o))}}),re(e,n),{flags:ue(u,r),unknownFlags:s,_:D}};function gu(u){return u!==null&&typeof u=="object"}function fu(u,e,t=".",n){if(!gu(e))return fu(u,{},t,n);const r=Object.assign({},e);for(const s in u){if(s==="__proto__"||s==="constructor")continue;const D=u[s];D!=null&&(n&&n(r,s,D,t)||(Array.isArray(D)&&Array.isArray(r[s])?r[s]=[...D,...r[s]]:gu(D)&&gu(r[s])?r[s]=fu(D,r[s],(t?`${t}.`:"")+s.toString(),n):r[s]=D))}return r}function se(u){return(...e)=>e.reduce((t,n)=>fu(t,n,"",u),{})}const oe=se(),Gu=u=>Array.isArray(u)?u:[u],ie=u=>u.replace(/[\W_]([a-z\d])?/gi,(e,t)=>t?t.toUpperCase():""),ae=(u,e)=>e.length!==u.length?!1:u.every((t,n)=>t===e[n]),Fe=(u,e)=>e.length>u.length?!1:ae(u.slice(0,e.length),e),V=JSON.stringify;class zu extends Error{constructor(e,t){super(t("core.commandExists",V(e))),this.commandName=e}}class iu extends Error{constructor(e,t){super(t("core.noSuchCommand",V(e))),this.commandName=e}}class au extends Error{constructor(e){super(e("core.noCommandGiven"))}}class Yu extends Error{constructor(e,t,n){super(n("core.commandNameConflict",V(e),V(t))),this.n1=e,this.n2=t}}class qu extends Error{constructor(e){super(e("core.nameNotSet"))}}class Zu extends Error{constructor(e){super(e("core.descriptionNotSet"))}}class Vu extends Error{constructor(e){super(e("core.versionNotSet"))}}class Ju extends Error{constructor(e,t){super(t("core.badNameFormat",V(e))),this.commandName=e}}class Au extends Error{constructor(e){super(e("core.localeMustBeCalledFirst"))}}const Ku=typeof Deno!="undefined",Ce=typeof process!="undefined"&&!Ku,le=process.versions.electron&&!process.defaultApp;function Qu(u,e,t,n){if(t.alias){const r=Gu(t.alias);for(const s of r){if(s in e)throw new Yu(e[s].name,t.name,n);u.set(typeof s=="symbol"?s:s.split(" "),{...t,__isAlias:!0})}}}function xu(u,e){const t=new Map;u[d]&&(t.set(d,u[d]),Qu(t,u,u[d],e));for(const n of Object.values(u))Qu(t,u,n,e),t.set(n.name.split(" "),n);return t}function Xu(u,e,t){const n=xu(u,t);for(const[r,s]of n.entries()){const D=Uu((s==null?void 0:s.flags)||{},[...e]),{_:i}=D;if(r!==d&&Fe(i,r))return[s,r]}return n.has(d)?[n.get(d),d]:[void 0,void 0]}const $u=()=>Ce?process.argv.slice(le?1:2):Ku?Deno.args:[];function uD(u){const e={pre:[],normal:[],post:[]};for(const n of u){const r=typeof n=="object"?n:{fn:n},{enforce:s,fn:D}=r;s==="post"||s==="pre"?e[s].push(D):e.normal.push(D)}const t=[...e.pre,...e.normal,...e.post];return n=>{const r=[];let s=0;const D=i=>{s=i;const o=t[i],a=o(n,D.bind(null,i+1));a&&r.push(a)};if(D(0),s+1===t.length)for(const i of r)i()}}const ce=/\s\s+/,DD=u=>u===d?!0:!(u.startsWith(" ")||u.endsWith(" "))&&!ce.test(u),eD=(u,e)=>e?`[${u}]`:`<${u}>`,Ee="<Root>",U=u=>Array.isArray(u)?u.join(" "):typeof u=="string"?u:Ee,tD=()=>process.env.CLERC_LOCALE?process.env.CLERC_LOCALE:Intl.DateTimeFormat().resolvedOptions().locale,nD=u=>u.filter(e=>!e.startsWith("-")),{stringify:G}=JSON;function Su(u,e){const t=[];let n,r;for(const s of u){if(r)throw new Error(e("core.spreadParameterMustBeLast",G(r)));const D=s[0],i=s[s.length-1];let o;if(D==="<"&&i===">"&&(o=!0,n))throw new Error(e("core.requiredParameterMustBeBeforeOptional",G(s),G(n)));if(D==="["&&i==="]"&&(o=!1,n=s),o===void 0)throw new Error(e("core.parameterMustBeWrappedInBrackets",G(s)));let a=s.slice(1,-1);const F=a.slice(-3)==="...";F&&(r=s,a=a.slice(0,-3)),t.push({name:a,required:o,spread:F})}return t}function wu(u,e,t,n){for(let r=0;r<e.length;r+=1){const{name:s,required:D,spread:i}=e[r],o=ie(s);if(o in u)throw new Error(n("core.parameterIsUsedMoreThanOnce",G(s)));const a=i?t.slice(r):t[r];if(i&&(r=e.length),D&&(!a||i&&a.length===0))throw new Error(n("core.missingRequiredParameter",G(s)));u[o]=a}}const me={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 bu=(u,e,t)=>{if(!e.has(u))throw TypeError("Cannot "+t)},m=(u,e,t)=>(bu(u,e,"read from private field"),t?t.call(u):e.get(u)),x=(u,e,t)=>{if(e.has(u))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(u):e.set(u,t)},O=(u,e,t,n)=>(bu(u,e,"write to private field"),n?n.call(u,t):e.set(u,t),t),$=(u,e,t)=>(bu(u,e,"access private method"),t),I,R,j,J,K,Fu,Q,z,X,uu,Du,eu,tu,W,yu,rD,vu,sD,Ou,oD,M,N,_u,iD,Mu,aD,Tu,FD,Cu,Nu,Lu,CD;const d=Symbol.for("Clerc.Root"),lD=class{constructor(u,e,t){x(this,yu),x(this,vu),x(this,Ou),x(this,M),x(this,_u),x(this,Mu),x(this,Tu),x(this,Cu),x(this,Lu),x(this,I,""),x(this,R,""),x(this,j,""),x(this,J,[]),x(this,K,{}),x(this,Fu,new PD),x(this,Q,{}),x(this,z,new Set),x(this,X,void 0),x(this,uu,[]),x(this,Du,!1),x(this,eu,"en"),x(this,tu,"en"),x(this,W,{}),this.i18n={add:n=>{O(this,W,oe(m(this,W),n))},t:(n,...r)=>{const s=m(this,W)[m(this,tu)]||m(this,W)[m(this,eu)],D=m(this,W)[m(this,eu)];return s[n]?Pu(s[n],...r):D[n]?Pu(D[n],...r):void 0}},O(this,I,u||m(this,I)),O(this,R,e||m(this,R)),O(this,j,t||m(this,j)),O(this,tu,tD()),$(this,Ou,oD).call(this)}get _name(){return m(this,I)}get _description(){return m(this,R)}get _version(){return m(this,j)}get _inspectors(){return m(this,J)}get _commands(){return m(this,K)}get _flags(){return m(this,Q)}static create(u,e,t){return new lD(u,e,t)}name(u){return $(this,M,N).call(this),O(this,I,u),this}description(u){return $(this,M,N).call(this),O(this,R,u),this}version(u){return $(this,M,N).call(this),O(this,j,u),this}locale(u){if(m(this,Du))throw new Au(this.i18n.t);return O(this,tu,u),this}fallbackLocale(u){if(m(this,Du))throw new Au(this.i18n.t);return O(this,eu,u),this}errorHandler(u){return m(this,uu).push(u),this}command(u,e,t={}){return $(this,Cu,Nu).call(this,()=>$(this,_u,iD).call(this,u,e,t)),this}flag(u,e,t){return m(this,Q)[u]={description:e,...t},this}on(u,e){return m(this,Fu).on(u,e),this}use(u){return $(this,M,N).call(this),u.setup(this)}inspector(u){return $(this,M,N).call(this),m(this,J).push(u),this}parse(u=$u()){$(this,M,N).call(this);const{argv:e,run:t}=Array.isArray(u)?{argv:u,run:!0}:{argv:$u(),...u};return O(this,X,[...e]),$(this,Mu,aD).call(this),t&&this.runMatchedCommand(),this}runMatchedCommand(){return $(this,Cu,Nu).call(this,()=>$(this,Lu,CD).call(this)),process.title=m(this,I),this}};let he=lD;I=new WeakMap,R=new WeakMap,j=new WeakMap,J=new WeakMap,K=new WeakMap,Fu=new WeakMap,Q=new WeakMap,z=new WeakMap,X=new WeakMap,uu=new WeakMap,Du=new WeakMap,eu=new WeakMap,tu=new WeakMap,W=new WeakMap,yu=new WeakSet,rD=function(){return m(this,z).has(d)},vu=new WeakSet,sD=function(){return Object.prototype.hasOwnProperty.call(this._commands,d)},Ou=new WeakSet,oD=function(){this.i18n.add(me)},M=new WeakSet,N=function(){O(this,Du,!0)},_u=new WeakSet,iD=function(u,e,t={}){$(this,M,N).call(this);const{t:n}=this.i18n,r=(F=>!(typeof F=="string"||F===d))(u),s=r?u.name:u;if(!DD(s))throw new Ju(s,n);const{handler:D=void 0,...i}=r?u:{name:s,description:e,...t},o=[i.name],a=i.alias?Gu(i.alias):[];i.alias&&o.push(...a);for(const F of o)if(m(this,z).has(F))throw new zu(U(F),n);return m(this,K)[s]=i,m(this,z).add(i.name),a.forEach(F=>m(this,z).add(F)),r&&D&&this.on(u.name,D),this},Mu=new WeakSet,aD=function(){const{t:u}=this.i18n;if(!m(this,I))throw new qu(u);if(!m(this,R))throw new Zu(u);if(!m(this,j))throw new Vu(u)},Tu=new WeakSet,FD=function(u){const e=m(this,X),{t}=this.i18n,[n,r]=u(),s=!!n,D={...m(this,Q),...n==null?void 0:n.flags},i=Uu(D,[...e]),{_:o,flags:a,unknownFlags:F}=i;let l=!s||n.name===d?o:o.slice(n.name.split(" ").length),C=(n==null?void 0:n.parameters)||[];const E=C.indexOf("--"),c=C.slice(E+1)||[],h=Object.create(null);if(E>-1&&c.length>0){C=C.slice(0,E);const v=o["--"];l=l.slice(0,-v.length||void 0),wu(h,Su(C,t),l,t),wu(h,Su(c,t),v,t)}else wu(h,Su(C,t),l,t);const p={...a,...F};return{name:n==null?void 0:n.name,called:Array.isArray(r)?r.join(" "):r,resolved:s,hasRootOrAlias:m(this,yu,rD),hasRoot:m(this,vu,sD),raw:{...i,parameters:l,mergedFlags:p},parameters:h,flags:a,unknownFlags:F,cli:this}},Cu=new WeakSet,Nu=function(u){try{u()}catch(e){if(m(this,uu).length>0)m(this,uu).forEach(t=>t(e));else throw e}},Lu=new WeakSet,CD=function(){$(this,M,N).call(this);const{t:u}=this.i18n,e=m(this,X);if(!e)throw new Error(u("core.cliParseMustBeCalled"));const t=()=>Xu(m(this,K),e,u),n=()=>$(this,Tu,FD).call(this,t),r={enforce:"post",fn:D=>{const[i]=t(),o=nD(e).join(" ");if(!i)throw o?new iu(o,u):new au(u);m(this,Fu).emit(i.name,D)}},s=[...m(this,J),r];uD(s)(n())};const P=u=>u,Be=(u,e,t)=>t,pe=(u,e)=>e,de=(u,e)=>({...u,handler:e}),ge=u=>`
1
+ import{format as Pu}from"node:util";import du from"tty";class PD{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.apply(null,[e,...t])),this.listenerMap[e].forEach(n=>n(...t))),this}off(e,t){var n,r;return e===void 0?(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):(r=this.listenerMap[e])==null||r.clear(),this)}}const HD="known-flag",UD="unknown-flag",GD="argument",{stringify:q}=JSON,zD=/\B([A-Z])/g,YD=u=>u.replace(zD,"-$1").toLowerCase(),{hasOwnProperty:qD}=Object.prototype,Z=(u,e)=>qD.call(u,e),ZD=u=>Array.isArray(u),Hu=u=>typeof u=="function"?[u,!1]:ZD(u)?[u[0],!0]:Hu(u.type),VD=(u,e)=>u===Boolean?e!=="false":e,JD=(u,e)=>typeof e=="boolean"?e:u===Number&&e===""?Number.NaN:u(e),KD=/[\s.:=]/,QD=u=>{const e=`Flag name ${q(u)}`;if(u.length===0)throw new Error(`${e} cannot be empty`);if(u.length===1)throw new Error(`${e} must be longer than a character`);const t=u.match(KD);if(t)throw new Error(`${e} cannot contain ${q(t==null?void 0:t[0])}`)},XD=u=>{const e={},t=(n,r)=>{if(Z(e,n))throw new Error(`Duplicate flags named ${q(n)}`);e[n]=r};for(const n in u){if(!Z(u,n))continue;QD(n);const r=u[n],s=[[],...Hu(r),r];t(n,s);const D=YD(n);if(n!==D&&t(D,s),"alias"in r&&typeof r.alias=="string"){const{alias:i}=r,o=`Flag alias ${q(i)} for flag ${q(n)}`;if(i.length===0)throw new Error(`${o} cannot be empty`);if(i.length>1)throw new Error(`${o} must be a single character`);t(i,s)}}return e},ue=(u,e)=>{const t={};for(const n in u){if(!Z(u,n))continue;const[r,,s,D]=e[n];if(r.length===0&&"default"in D){let{default:i}=D;typeof i=="function"&&(i=i()),t[n]=i}else t[n]=s?r:r.pop()}return t},ou="--",De=/[.:=]/,ee=/^-{1,2}\w/,te=u=>{if(!ee.test(u))return;const e=!u.startsWith(ou);let t=u.slice(e?1:2),n;const r=t.match(De);if(r){const{index:s}=r;n=t.slice(s+1),t=t.slice(0,s)}return[t,n,e]},ne=(u,{onFlag:e,onArgument:t})=>{let n;const r=(s,D)=>{if(typeof n!="function")return!0;n(s,D),n=void 0};for(let s=0;s<u.length;s+=1){const D=u[s];if(D===ou){r();const o=u.slice(s+1);t==null||t(o,[s],!0);break}const i=te(D);if(i){if(r(),!e)continue;const[o,a,F]=i;if(F)for(let l=0;l<o.length;l+=1){r();const C=l===o.length-1;n=e(o[l],C?a:void 0,[s,l+1,C])}else n=e(o,a,[s])}else r(D,[s])&&(t==null||t([D],[s]))}r()},re=(u,e)=>{for(const[t,n,r]of e.reverse()){if(n){const s=u[t];let D=s.slice(0,n);if(r||(D+=s.slice(n+1)),D!=="-"){u[t]=D;continue}}u.splice(t,1)}},Uu=(u,e=process.argv.slice(2),{ignore:t}={})=>{const n=[],r=XD(u),s={},D=[];return D[ou]=[],ne(e,{onFlag(i,o,a){const F=Z(r,i);if(!(t!=null&&t(F?HD:UD,i,o))){if(F){const[l,C]=r[i],E=VD(C,o),c=(h,p)=>{n.push(a),p&&n.push(p),l.push(JD(C,h||""))};return E===void 0?c:c(E)}Z(s,i)||(s[i]=[]),s[i].push(o===void 0?!0:o),n.push(a)}},onArgument(i,o,a){t!=null&&t(GD,e[o[0]])||(D.push(...i),a?(D[ou]=i,e.splice(o[0])):n.push(o))}}),re(e,n),{flags:ue(u,r),unknownFlags:s,_:D}};function gu(u){return u!==null&&typeof u=="object"}function fu(u,e,t=".",n){if(!gu(e))return fu(u,{},t,n);const r=Object.assign({},e);for(const s in u){if(s==="__proto__"||s==="constructor")continue;const D=u[s];D!=null&&(n&&n(r,s,D,t)||(Array.isArray(D)&&Array.isArray(r[s])?r[s]=[...D,...r[s]]:gu(D)&&gu(r[s])?r[s]=fu(D,r[s],(t?`${t}.`:"")+s.toString(),n):r[s]=D))}return r}function se(u){return(...e)=>e.reduce((t,n)=>fu(t,n,"",u),{})}const oe=se(),Gu=u=>Array.isArray(u)?u:[u],ie=u=>u.replace(/[\W_]([a-z\d])?/gi,(e,t)=>t?t.toUpperCase():""),ae=(u,e)=>e.length!==u.length?!1:u.every((t,n)=>t===e[n]),Fe=(u,e)=>e.length>u.length?!1:ae(u.slice(0,e.length),e),V=JSON.stringify;class zu extends Error{constructor(e,t){super(t("core.commandExists",V(e))),this.commandName=e}}class iu extends Error{constructor(e,t){super(t("core.noSuchCommand",V(e))),this.commandName=e}}class au extends Error{constructor(e){super(e("core.noCommandGiven"))}}class Yu extends Error{constructor(e,t,n){super(n("core.commandNameConflict",V(e),V(t))),this.n1=e,this.n2=t}}class qu extends Error{constructor(e){super(e("core.nameNotSet"))}}class Zu extends Error{constructor(e){super(e("core.descriptionNotSet"))}}class Vu extends Error{constructor(e){super(e("core.versionNotSet"))}}class Ju extends Error{constructor(e,t){super(t("core.badNameFormat",V(e))),this.commandName=e}}class Au extends Error{constructor(e){super(e("core.localeMustBeCalledFirst"))}}const Ku=typeof Deno!="undefined",Ce=typeof process!="undefined"&&!Ku,le=process.versions.electron&&!process.defaultApp;function Qu(u,e,t,n){if(t.alias){const r=Gu(t.alias);for(const s of r){if(s in e)throw new Yu(e[s].name,t.name,n);u.set(typeof s=="symbol"?s:s.split(" "),{...t,__isAlias:!0})}}}function xu(u,e){const t=new Map;u[d]&&(t.set(d,u[d]),Qu(t,u,u[d],e));for(const n of Object.values(u))Qu(t,u,n,e),t.set(n.name.split(" "),n);return t}function Xu(u,e,t){const n=xu(u,t);for(const[r,s]of n.entries()){const D=Uu((s==null?void 0:s.flags)||{},[...e]),{_:i}=D;if(r!==d&&Fe(i,r))return[s,r]}return n.has(d)?[n.get(d),d]:[void 0,void 0]}const $u=()=>Ce?process.argv.slice(le?1:2):Ku?Deno.args:[];function uD(u){const e={pre:[],normal:[],post:[]};for(const n of u){const r=typeof n=="object"?n:{fn:n},{enforce:s,fn:D}=r;s==="post"||s==="pre"?e[s].push(D):e.normal.push(D)}const t=[...e.pre,...e.normal,...e.post];return n=>{const r=[];let s=0;const D=i=>{s=i;const o=t[i],a=o(n,D.bind(null,i+1));a&&r.push(a)};if(D(0),s+1===t.length)for(const i of r)i()}}const ce=/\s\s+/,DD=u=>u===d?!0:!(u.startsWith(" ")||u.endsWith(" "))&&!ce.test(u),eD=(u,e)=>e?`[${u}]`:`<${u}>`,Ee="<Root>",U=u=>Array.isArray(u)?u.join(" "):typeof u=="string"?u:Ee,tD=()=>process.env.CLERC_LOCALE?process.env.CLERC_LOCALE:Intl.DateTimeFormat().resolvedOptions().locale,nD=u=>u.filter(e=>!e.startsWith("-")),{stringify:G}=JSON;function Su(u,e){const t=[];let n,r;for(const s of u){if(r)throw new Error(e("core.spreadParameterMustBeLast",G(r)));const D=s[0],i=s[s.length-1];let o;if(D==="<"&&i===">"&&(o=!0,n))throw new Error(e("core.requiredParameterMustBeBeforeOptional",G(s),G(n)));if(D==="["&&i==="]"&&(o=!1,n=s),o===void 0)throw new Error(e("core.parameterMustBeWrappedInBrackets",G(s)));let a=s.slice(1,-1);const F=a.slice(-3)==="...";F&&(r=s,a=a.slice(0,-3)),t.push({name:a,required:o,spread:F})}return t}function wu(u,e,t,n){for(let r=0;r<e.length;r+=1){const{name:s,required:D,spread:i}=e[r],o=ie(s);if(o in u)throw new Error(n("core.parameterIsUsedMoreThanOnce",G(s)));const a=i?t.slice(r):t[r];if(i&&(r=e.length),D&&(!a||i&&a.length===0))throw new Error(n("core.missingRequiredParameter",G(s)));u[o]=a}}const me={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 bu=(u,e,t)=>{if(!e.has(u))throw TypeError("Cannot "+t)},m=(u,e,t)=>(bu(u,e,"read from private field"),t?t.call(u):e.get(u)),x=(u,e,t)=>{if(e.has(u))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(u):e.set(u,t)},O=(u,e,t,n)=>(bu(u,e,"write to private field"),n?n.call(u,t):e.set(u,t),t),$=(u,e,t)=>(bu(u,e,"access private method"),t),I,R,j,J,K,Fu,Q,z,X,uu,Du,eu,tu,W,yu,rD,vu,sD,Ou,oD,M,N,_u,iD,Mu,aD,Tu,FD,Cu,Nu,Lu,CD;const d=Symbol.for("Clerc.Root"),lD=class{constructor(u,e,t){x(this,yu),x(this,vu),x(this,Ou),x(this,M),x(this,_u),x(this,Mu),x(this,Tu),x(this,Cu),x(this,Lu),x(this,I,""),x(this,R,""),x(this,j,""),x(this,J,[]),x(this,K,{}),x(this,Fu,new PD),x(this,Q,{}),x(this,z,new Set),x(this,X,void 0),x(this,uu,[]),x(this,Du,!1),x(this,eu,"en"),x(this,tu,"en"),x(this,W,{}),this.i18n={add:n=>{O(this,W,oe(m(this,W),n))},t:(n,...r)=>{const s=m(this,W)[m(this,tu)]||m(this,W)[m(this,eu)],D=m(this,W)[m(this,eu)];return s[n]?Pu(s[n],...r):D[n]?Pu(D[n],...r):void 0}},O(this,I,u||m(this,I)),O(this,R,e||m(this,R)),O(this,j,t||m(this,j)),O(this,tu,tD()),$(this,Ou,oD).call(this)}get _name(){return m(this,I)}get _description(){return m(this,R)}get _version(){return m(this,j)}get _inspectors(){return m(this,J)}get _commands(){return m(this,K)}get _flags(){return m(this,Q)}static create(u,e,t){return new lD(u,e,t)}name(u){return $(this,M,N).call(this),O(this,I,u),this}description(u){return $(this,M,N).call(this),O(this,R,u),this}version(u){return $(this,M,N).call(this),O(this,j,u),this}locale(u){if(m(this,Du))throw new Au(this.i18n.t);return O(this,tu,u),this}fallbackLocale(u){if(m(this,Du))throw new Au(this.i18n.t);return O(this,eu,u),this}errorHandler(u){return m(this,uu).push(u),this}command(u,e,t={}){return $(this,Cu,Nu).call(this,()=>$(this,_u,iD).call(this,u,e,t)),this}flag(u,e,t){return m(this,Q)[u]={description:e,...t},this}on(u,e){return m(this,Fu).on(u,e),this}use(u){return $(this,M,N).call(this),u.setup(this)}inspector(u){return $(this,M,N).call(this),m(this,J).push(u),this}parse(u=$u()){$(this,M,N).call(this);const{argv:e,run:t}=Array.isArray(u)?{argv:u,run:!0}:{argv:$u(),...u};return O(this,X,[...e]),$(this,Mu,aD).call(this),t&&this.runMatchedCommand(),this}runMatchedCommand(){return $(this,Cu,Nu).call(this,()=>$(this,Lu,CD).call(this)),process.title=m(this,I),this}};let he=lD;I=new WeakMap,R=new WeakMap,j=new WeakMap,J=new WeakMap,K=new WeakMap,Fu=new WeakMap,Q=new WeakMap,z=new WeakMap,X=new WeakMap,uu=new WeakMap,Du=new WeakMap,eu=new WeakMap,tu=new WeakMap,W=new WeakMap,yu=new WeakSet,rD=function(){return m(this,z).has(d)},vu=new WeakSet,sD=function(){return Object.prototype.hasOwnProperty.call(this._commands,d)},Ou=new WeakSet,oD=function(){this.i18n.add(me)},M=new WeakSet,N=function(){O(this,Du,!0)},_u=new WeakSet,iD=function(u,e,t={}){$(this,M,N).call(this);const{t:n}=this.i18n,r=(F=>!(typeof F=="string"||F===d))(u),s=r?u.name:u;if(!DD(s))throw new Ju(s,n);const{handler:D=void 0,...i}=r?u:{name:s,description:e,...t},o=[i.name],a=i.alias?Gu(i.alias):[];i.alias&&o.push(...a);for(const F of o)if(m(this,z).has(F))throw new zu(U(F),n);return m(this,K)[s]=i,m(this,z).add(i.name),a.forEach(F=>m(this,z).add(F)),r&&D&&this.on(u.name,D),this},Mu=new WeakSet,aD=function(){const{t:u}=this.i18n;if(!m(this,I))throw new qu(u);if(!m(this,R))throw new Zu(u);if(!m(this,j))throw new Vu(u)},Tu=new WeakSet,FD=function(u){const e=m(this,X),{t}=this.i18n,[n,r]=u(),s=!!n,D={...m(this,Q),...n==null?void 0:n.flags},i=Uu(D,[...e]),{_:o,flags:a,unknownFlags:F}=i;let l=!s||n.name===d?o:o.slice(n.name.split(" ").length),C=(n==null?void 0:n.parameters)||[];const E=C.indexOf("--"),c=C.slice(E+1)||[],h=Object.create(null);if(E>-1&&c.length>0){C=C.slice(0,E);const v=o["--"];l=l.slice(0,-v.length||void 0),wu(h,Su(C,t),l,t),wu(h,Su(c,t),v,t)}else wu(h,Su(C,t),l,t);const p={...a,...F};return{name:n==null?void 0:n.name,called:Array.isArray(r)?r.join(" "):r,resolved:s,hasRootOrAlias:m(this,yu,rD),hasRoot:m(this,vu,sD),raw:{...i,parameters:l,mergedFlags:p},parameters:h,flags:a,unknownFlags:F,cli:this}},Cu=new WeakSet,Nu=function(u){try{u()}catch(e){if(m(this,uu).length>0)m(this,uu).forEach(t=>t(e));else throw e}},Lu=new WeakSet,CD=function(){$(this,M,N).call(this);const{t:u}=this.i18n,e=m(this,X);if(!e)throw new Error(u("core.cliParseMustBeCalled"));const t=()=>Xu(m(this,K),e,u),n=()=>$(this,Tu,FD).call(this,t),r={enforce:"post",fn:D=>{const[i]=t(),o=nD(e).join(" ");if(!i)throw o?new iu(o,u):new au(u);m(this,Fu).emit(i.name,D)}},s=[...m(this,J),r];uD(s)(n())};const P=u=>u,Be=(u,e,t)=>t,pe=(u,e)=>e,de=(u,e)=>({...u,handler:e}),ge=u=>`
2
2
  ${u})
3
3
  cmd+="__${u}"
4
4
  ;;`,fe=u=>{const{cli:e}=u,{_name:t,_commands:n}=e;return`_${t}() {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "clerc",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
- "description": "Clerc: The full-featured cli framework.",
5
+ "description": "Clerc: The full-featured cli library.",
6
6
  "keywords": [
7
7
  "cli",
8
8
  "clerc",
@@ -47,13 +47,13 @@
47
47
  "access": "public"
48
48
  },
49
49
  "devDependencies": {
50
- "@clerc/core": "0.35.0",
51
- "@clerc/plugin-completions": "0.35.0",
52
- "@clerc/plugin-friendly-error": "0.35.0",
53
- "@clerc/plugin-help": "0.35.0",
54
- "@clerc/plugin-not-found": "0.35.0",
55
- "@clerc/plugin-strict-flags": "0.35.0",
56
- "@clerc/plugin-version": "0.35.0"
50
+ "@clerc/plugin-friendly-error": "0.36.0",
51
+ "@clerc/core": "0.36.0",
52
+ "@clerc/plugin-help": "0.36.0",
53
+ "@clerc/plugin-strict-flags": "0.36.0",
54
+ "@clerc/plugin-version": "0.36.0",
55
+ "@clerc/plugin-not-found": "0.36.0",
56
+ "@clerc/plugin-completions": "0.36.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "puild --minify",