cli-kiss 0.2.7 → 0.2.8
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.ts +127 -137
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +1 -1
- package/docs/.vitepress/theme/Layout.vue +16 -0
- package/docs/.vitepress/theme/index.ts +5 -1
- package/docs/.vitepress/theme/style.css +5 -1
- package/docs/guide/02_commands.md +1 -1
- package/docs/guide/03_options.md +11 -11
- package/docs/guide/05_input_types.md +9 -10
- package/docs/guide/06_run_as_cli.md +1 -1
- package/docs/index.md +2 -2
- package/docs/public/favicon.ico +0 -0
- package/docs/public/logo.png +0 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/lib/Command.ts +45 -39
- package/src/lib/Operation.ts +28 -20
- package/src/lib/Option.ts +196 -127
- package/src/lib/Positional.ts +44 -23
- package/src/lib/Reader.ts +194 -226
- package/src/lib/Run.ts +19 -8
- package/src/lib/Suggest.ts +78 -0
- package/src/lib/Type.ts +36 -37
- package/src/lib/Typo.ts +58 -55
- package/src/lib/Usage.ts +12 -12
- package/tests/unit.Reader.commons.ts +92 -116
- package/tests/unit.Reader.parsings.ts +14 -26
- package/tests/unit.Reader.shortBig.ts +81 -96
- package/tests/unit.command.aliases.ts +100 -0
- package/tests/unit.command.execute.ts +1 -1
- package/tests/unit.command.usage.ts +12 -6
- package/tests/unit.fuzzed.alternatives.ts +35 -26
- package/tests/unit.runner.colors.ts +8 -33
- package/tests/unit.runner.cycle.ts +118 -146
- package/tests/unit.runner.errors.ts +25 -22
- package/docs/public/hero.png +0 -0
- package/src/lib/Similarity.ts +0 -41
- package/tests/unit.Reader.aliases.ts +0 -62
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var re=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var xe=o=>{throw TypeError(o)};var Ee=(o,e)=>{for(var t in e)re(o,t,{get:e[t],enumerable:!0})},Le=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Pe(e))!ve.call(o,n)&&n!==t&&re(o,n,{get:()=>e[n],enumerable:!(s=Me(e,n))||s.enumerable});return o};var We=o=>Le(re({},"__esModule",{value:!0}),o);var se=(o,e,t)=>e.has(o)||xe("Cannot "+t);var g=(o,e,t)=>(se(o,e,"read from private field"),t?t.call(o):e.get(o)),b=(o,e,t)=>e.has(o)?xe("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(o):e.set(o,t),w=(o,e,t,s)=>(se(o,e,"write to private field"),s?s.call(o,t):e.set(o,t),t),f=(o,e,t)=>(se(o,e,"access private method"),t);var be=(o,e,t,s)=>({set _(n){w(o,e,n,t)},get _(){return g(o,e,s)}});var ft={};Ee(ft,{ReaderArgs:()=>H,TypoError:()=>m,TypoGrid:()=>L,TypoString:()=>a,TypoSupport:()=>O,TypoText:()=>d,command:()=>rt,commandChained:()=>it,commandWithSubcommands:()=>st,operation:()=>at,optionFlag:()=>te,optionRepeatable:()=>ut,optionSingleValue:()=>de,positionalOptional:()=>lt,positionalRequired:()=>pt,positionalVariadics:()=>dt,runAndExit:()=>yt,similaritySort:()=>v,type:()=>je,typeBoolean:()=>ie,typeBooleanValuesFalse:()=>J,typeBooleanValuesTrue:()=>Se,typeChoice:()=>ae,typeConverted:()=>qe,typeDatetime:()=>Ge,typeInteger:()=>Ke,typeList:()=>He,typeNumber:()=>Ne,typePath:()=>Qe,typeRenamed:()=>Ye,typeTuple:()=>ze,typeUrl:()=>Fe,typoStyleConstants:()=>S,typoStyleFailure:()=>Ae,typoStyleLogic:()=>V,typoStyleQuote:()=>x,typoStyleRegularStrong:()=>pe,typoStyleRegularWeaker:()=>le,typoStyleTitle:()=>ue,typoStyleUserInput:()=>T,usageToStyledLines:()=>we});module.exports=We(ft);function v(o,e){return(Array.isArray(e)?e.map(({key:n,value:r})=>[n,r]):Object.entries(e)).map(([n,r])=>{let i=Be(o,n)/Math.max(o.length,n.length);return{key:n,value:r,score:i}}).sort((n,r)=>n.score-r.score).map(n=>n.value)}function Be(o,e){let t=o.length,s=e.length,n=Array.from({length:t+1},()=>Array(s+1).fill(0));for(let r=0;r<=t;r++)n[r][0]=r;for(let r=0;r<=s;r++)n[0][r]=r;for(let r=1;r<=t;r++)for(let i=1;i<=s;i++){let u=o[r-1]===e[i-1]?0:1;n[r][i]=Math.min(n[r-1][i]+1,n[r][i-1]+1,n[r-1][i-1]+u),r>1&&i>1&&o[r-1]===e[i-2]&&o[r-2]===e[i-1]&&(n[r][i]=Math.min(n[r][i],n[r-2][i-2]+u))}return n[t][s]}var Ce=require("fs");function ie(o){return{content:o??"boolean",decoder(e){let t=e.toLowerCase();if(Se.has(t))return!0;if(J.has(t))return!1;Q("a boolean",e)}}}var Se=new Set(["true","yes","on","y"]),J=new Set(["false","no","off","n"]);function Ge(o){return{content:o??"datetime",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{Q("a valid ISO_8601 datetime",e)}}}}function Ne(o){return{content:o??"number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{Q("a number",e)}}}}function Ke(o){return{content:o??"integer",decoder(e){try{return BigInt(e)}catch{Q("an integer",e)}}}}function Fe(o){return{content:o??"url",decoder(e){try{return new URL(e)}catch{Q("an URL",e)}}}}function je(o){return{content:o??"string",decoder:e=>e}}function qe(o,e,t){return{content:o,decoder:s=>t(m.tryWithContext(()=>e.decoder(s),()=>new d(new a("from: "),new a(e.content,V))))}}function Ye(o,e){return{content:e,decoder:t=>m.tryWithContext(()=>o.decoder(t),()=>new d(new a("from: "),new a(o.content,V)))}}function Qe(o,e){return{content:o??"path",decoder(t){if(t.length===0)throw new Error("Path cannot be empty");if(t.includes("\0"))throw new Error("Path cannot contain null characters");if(e?.checkSyncExistAs!==void 0){let n=function(u){try{return(0,Ce.statSync)(u)}catch(l){throw new m(new d(new a("Path does not exist: "),new a(`"${u}"`,x)),l)}};var s=n;let r=n(t),i=r.isDirectory()?"directory":r.isFile()?"file":"unknown";if(e.checkSyncExistAs==="file"&&!r.isFile())throw new m(new d(new a(`Expected a file but found: ${i}: `),new a(`"${t}"`,x)));if(e.checkSyncExistAs==="directory"&&!r.isDirectory())throw new m(new d(new a(`Expected a directory but found: ${i}: `),new a(`"${t}"`,x)))}return t}}}function ae(o,e,t=!1){if(e.length===0)throw new Error("At least one value is required");let s=t?r=>r:r=>r.toLowerCase(),n=new Map(e.map(r=>[s(r),r]));return{content:o,decoder(r){let i=s(r),u=n.get(i);if(u!==void 0)return u;let l=new d;l.push(new a("Unknown value: ")),l.push(new a(`"${r}"`,x));let p=v(i,[...n.entries()].map(([c,h])=>({key:c,value:new a(`"${h}"`,x)}))).slice(0,3);throw l.push(new a(": did you mean: ")),l.push(d.join(p,new a(", "))),l.push(new a(" ?")),new m(l)}}}function ze(o,e=","){return{content:o.map(t=>t.content).join(e),decoder(t){let s=t.split(e,o.length);if(s.length!==o.length)throw new m(new d(new a(`Found ${s.length} splits: `),new a(`Expected ${o.length} splits from: `),new a(`"${t}"`,x)));return s.map((n,r)=>{let i=o[r];return m.tryWithContext(()=>i.decoder(n),()=>new d(new a(`at ${r}: `),new a(i.content,V)))})}}}function He(o,e=","){return{content:`${o.content}[${e}${o.content}]...`,decoder(t){return t.split(e).map((n,r)=>m.tryWithContext(()=>o.decoder(n),()=>new d(new a(`at ${r}: `),new a(o.content,V))))}}}function Q(o,e){throw new m(new d(new a(`Not ${o}: `),new a(`"${e}"`,x)))}var ue={fgColor:"darkGreen",bold:!0},V={fgColor:"darkMagenta",bold:!0},x={fgColor:"darkYellow",bold:!0},Ae={fgColor:"darkRed",bold:!0},S={fgColor:"darkCyan",bold:!0},T={fgColor:"darkBlue",bold:!0},pe={bold:!0},le={italic:!0,dim:!0},B,z,a=class{constructor(e,t){b(this,B);b(this,z);w(this,B,e),w(this,z,t)}computeStyledString(e){return e.computeStyledString(g(this,B),g(this,z))}getRawString(){return g(this,B)}};B=new WeakMap,z=new WeakMap;var k,Z=class Z{constructor(...e){b(this,k);w(this,k,[]);for(let t of e)this.push(t)}push(e){if(typeof e=="string")g(this,k).push(new a(e));else if(e instanceof Z)g(this,k).push(...g(e,k));else if(Array.isArray(e))for(let t of e)this.push(t);else g(this,k).push(e)}computeStyledString(e){return g(this,k).map(t=>t.computeStyledString(e)).join("")}computeRawString(){return g(this,k).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let t of g(this,k))e+=t.getRawString().length;return e}static join(e,t){let s=new Z;for(let n=0;n<e.length;n++)n>0&&s.push(t),s.push(e[n]);return s}};k=new WeakMap;var d=Z,E,L=class{constructor(){b(this,E);w(this,E,[])}pushRow(e){g(this,E).push(e)}computeStyledLines(e){let t=new Array,s=new Array;for(let n of g(this,E))for(let r=0;r<n.length;r++){let u=n[r].computeRawLength();(t[r]===void 0||u>t[r])&&(t[r]=u)}for(let n of g(this,E)){let r=new Array;for(let i=0;i<n.length;i++){let u=n[i];if(r.push(u.computeStyledString(e)),i<n.length-1){let l=u.computeRawLength(),p=" ".repeat(t[i]-l);r.push(p)}}s.push(r.join(""))}return s}};E=new WeakMap;var G,_=class _ extends Error{constructor(t,s){let n=new d;n.push(t),s instanceof _?(n.push(new a(": ")),n.push(g(s,G))):s instanceof Error?n.push(new a(`: ${s.message}`)):s!==void 0&&n.push(new a(`: ${String(s)}`));super(n.computeRawString());b(this,G);w(this,G,n)}computeStyledString(t){return g(this,G).computeStyledString(t)}static tryWithContext(t,s){try{return t()}catch(n){throw new _(s(),n)}}};G=new WeakMap;var m=_,D,R=class R{constructor(e){b(this,D);w(this,D,e)}static none(){return new R("none")}static tty(){return new R("tty")}static mock(){return new R("mock")}static inferFromEnv(){if(!process||!process.env||!process.stdout||X("NO_COLOR"))return R.none();let e=X("FORCE_COLOR");return e==="0"?R.none():e!==void 0&&!J.has(e.toLowerCase())?R.tty():X("MOCK_COLOR")?R.mock():!process.stdout.isTTY||X("TERM")?.toLowerCase()==="dumb"?R.none():R.tty()}computeStyledString(e,t){if(t===void 0)return e;let s=e;if(t.case==="upper"&&(s=s.toUpperCase()),t.case==="lower"&&(s=s.toLowerCase()),g(this,D)==="none")return s;if(g(this,D)==="tty"){let n=t.fgColor?nt[t.fgColor]:"",r=t.bgColor?ot[t.bgColor]:"",i=t.bold?Xe:"",u=t.dim?Ze:"",l=t.italic?_e:"",p=t.underline?et:"",c=t.strikethrough?tt:"";return`${n}${r}${i}${u}${l}${p}${c}${s}${Je}`}if(g(this,D)==="mock"){let n=t.fgColor?`{${s}}@${t.fgColor}`:s,r=t.bgColor?`{${n}}#${t.bgColor}`:n,i=t.bold?`{${r}}+`:r,u=t.dim?`{${i}}-`:i,l=t.italic?`{${u}}*`:u,p=t.underline?`{${l}}_`:l;return t.strikethrough?`{${p}}~`:p}throw new Error(`Unknown TypoSupport kind: ${g(this,D)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",Ae),e instanceof m?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};D=new WeakMap;var O=R,Je="\x1B[0m",Xe="\x1B[1m",Ze="\x1B[2m",_e="\x1B[3m",et="\x1B[4m",tt="\x1B[9m",nt={darkBlack:"\x1B[30m",darkRed:"\x1B[31m",darkGreen:"\x1B[32m",darkYellow:"\x1B[33m",darkBlue:"\x1B[34m",darkMagenta:"\x1B[35m",darkCyan:"\x1B[36m",darkWhite:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"},ot={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function X(o){if(o in process.env)return process.env[o]}function rt(o,e){return{getInformation(){return o},consumeAndMakeDecoder(t){try{let s=e.consumeAndMakeDecoder(t),n=t.consumePositional();if(n!==void 0)throw new m(new d(new a("Unexpected argument: "),new a(`"${n}"`,x)));return{generateUsage:()=>N(o,e),decodeAndMakeInterpreter(){let r=s.decodeAndMakeInterpreter();return{async executeWithContext(i){return await r.executeWithContext(i)}}}}}catch(s){return{generateUsage:()=>N(o,e),decodeAndMakeInterpreter(){throw s}}}}}}function st(o,e,t){let s=Object.keys(t);if(s.length===0)throw new Error("At least one subcommand is required");return{getInformation(){return o},consumeAndMakeDecoder(n){try{let r=e.consumeAndMakeDecoder(n),i=n.consumePositional();if(i===void 0)throw new m(new d(new a("<subcommand>",T),new a(": Is required, but was not provided")));let u=t[i];if(u===void 0){let p=new d;p.push(new a("<subcommand>",T)),p.push(new a(": Unknown name: ")),p.push(new a(`"${i}"`,x));let c=v(i,s.map(h=>({key:h,value:new a(h,S)}))).slice(0,3);throw p.push(new a(": did you mean: ")),p.push(d.join(c,new a(", "))),p.push(new a(" ?")),new m(p)}let l=u.consumeAndMakeDecoder(n);return{generateUsage(){let p=l.generateUsage(),c=N(o,e);return c.segments.push({subcommand:i}),c.segments.push(...p.segments),c.information=p.information,c.positionals.push(...p.positionals),c.subcommands=p.subcommands,c.options.push(...p.options),c},decodeAndMakeInterpreter(){let p=r.decodeAndMakeInterpreter(),c=l.decodeAndMakeInterpreter();return{async executeWithContext(h){return await c.executeWithContext(await p.executeWithContext(h))}}}}}catch(r){return{generateUsage(){let i=N(o,e);i.segments.push({positional:"<subcommand>"});for(let[u,l]of Object.entries(t)){let{description:p,hint:c}=l.getInformation();i.subcommands.push({name:u,description:p,hint:c})}return i},decodeAndMakeInterpreter(){throw r}}}}}}function it(o,e,t){return{getInformation(){return o},consumeAndMakeDecoder(s){try{let n=e.consumeAndMakeDecoder(s),r=t.consumeAndMakeDecoder(s);return{generateUsage(){let i=r.generateUsage(),u=N(o,e);return u.segments.push(...i.segments),u.information=i.information,u.positionals.push(...i.positionals),u.subcommands=i.subcommands,u.options.push(...i.options),u},decodeAndMakeInterpreter(){let i=n.decodeAndMakeInterpreter(),u=r.decodeAndMakeInterpreter();return{async executeWithContext(l){return await u.executeWithContext(await i.executeWithContext(l))}}}}}catch(n){return{generateUsage(){let r=N(o,e);return r.segments.push({positional:"[REST]..."}),r},decodeAndMakeInterpreter(){throw n}}}}}}function N(o,e){let{positionals:t,options:s}=e.generateUsage();return{segments:t.map(n=>({positional:n.label})),information:o,positionals:t,subcommands:[],options:s}}function at(o,e){return{generateUsage(){let t=new Array;for(let n in o.options){let r=o.options[n];t.push(r.generateUsage())}let s=new Array;for(let n of o.positionals)s.push(n.generateUsage());return{options:t,positionals:s}},consumeAndMakeDecoder(t){let s={};for(let r in o.options){let i=o.options[r];s[r]=i.registerAndMakeDecoder(t)}let n=[];for(let r of o.positionals)n.push(r.consumeAndMakeDecoder(t));return{decodeAndMakeInterpreter(){let r={};for(let u in s)r[u]=s[u].getAndDecodeValue();let i=[];for(let u of n)i.push(u.decodeValue());return{executeWithContext(u){return e(u,{options:r,positionals:i})}}}}}}}function te(o){let e=ie("value"),{long:t,short:s,description:n,hint:r,aliases:i}=o;return{generateUsage(){return{short:s,long:t,annotation:"[=no]",description:n,hint:r}},registerAndMakeDecoder(u){let l=ce(u,{long:t,short:s,aliasesLongs:i?.longs,aliasesShorts:i?.shorts,parsing:{consumeShortGroup:!1,consumeNextArg:()=>!1}});return{getAndDecodeValue(){let p=u.getOptionValues(l);if(p.length>1&&Te(t),p.length===0)return o.default===void 0?!1:o.default;let c=p[0],h=c.inlined===null?"true":c.inlined;return ee({long:t,type:e,input:h})}}}}}function de(o){let{long:e,short:t,description:s,hint:n,aliases:r,type:i}=o,u=`<${i.content}>`;return{generateUsage(){return{short:t,long:e,label:u,description:s,hint:n}},registerAndMakeDecoder(l){let p=ce(l,{long:e,short:t,aliasesLongs:r?.longs,aliasesShorts:r?.shorts,parsing:{consumeShortGroup:!0,consumeNextArg(c,h){return o.valueIfNothingInlined!==void 0?!1:c===null&&h.length===0}}});return{getAndDecodeValue(){let c=l.getOptionValues(p);c.length>1&&Te(e);let h=c[0];if(h===void 0)try{return o.defaultIfNotSpecified()}catch($){Re({long:e,error:$,context:"Not specified"})}if(h.inlined){let $=h.inlined;return ee({long:e,label:u,type:i,input:$})}if(o.valueIfNothingInlined!==void 0)try{return o.valueIfNothingInlined()}catch($){Re({long:e,error:$,context:"Nothing inlined"})}let A=h.separated[0];return ee({long:e,label:u,type:i,input:A})}}}}}function ut(o){let{long:e,short:t,description:s,hint:n,aliases:r,type:i}=o,u=`<${i.content}>`;return{generateUsage(){return{short:t,long:e,label:u,annotation:" [*]",description:s,hint:n}},registerAndMakeDecoder(l){let p=ce(l,{long:e,short:t,aliasesLongs:r?.longs,aliasesShorts:r?.shorts,parsing:{consumeShortGroup:!0,consumeNextArg:(c,h)=>c===null&&h.length===0}});return{getAndDecodeValue(){return l.getOptionValues(p).map(h=>{let A=h.inlined??h.separated[0];return ee({long:e,label:u,type:i,input:A})})}}}}}function ee(o){return m.tryWithContext(()=>o.type.decoder(o.input),()=>{let e=new d;return e.push(new a(`--${o.long}`,S)),o.label?(e.push(new a(": ")),e.push(new a(o.label,T))):(e.push(new a(": ")),e.push(new a(o.type.content,V))),e})}function ce(o,e){let{long:t,short:s,aliasesLongs:n,aliasesShorts:r,parsing:i}=e,u=t?[t]:[];n&&u.push(...n);let l=s?[s]:[];return r&&l.push(...r),o.registerOption({longs:u,shorts:l,parsing:i})}function Te(o){throw new m(new d(new a(`--${o}`,S),new a(": Must not be set multiple times")))}function Re(o){let e=new d;throw e.push(new a(`--${o.long}`,S)),e.push(new a(`: ${o.context}: Failed to generate default value`)),new m(e,o.error)}function pt(o){let{description:e,hint:t,type:s}=o,n=`<${s.content}>`;return{generateUsage(){return{description:e,hint:t,label:n}},consumeAndMakeDecoder(r){let i=r.consumePositional();if(i===void 0)throw new m(new d(new a(n,T),new a(": Is required, but was not provided")));return{decodeValue(){return ge(n,o.type,i)}}}}}function lt(o){let{description:e,hint:t,type:s}=o,n=`[${s.content}]`;return{generateUsage(){return{description:e,hint:t,label:n}},consumeAndMakeDecoder(r){let i=r.consumePositional();return{decodeValue(){if(i===void 0)try{return o.default()}catch{ct(n)}return ge(n,o.type,i)}}}}}function dt(o){let{description:e,hint:t,type:s}=o,n=`[${s.content}]`,r=`${n}...`+(o.endDelimiter?` ["${o.endDelimiter}"]`:"");return{generateUsage(){return{description:e,hint:t,label:r}},consumeAndMakeDecoder(i){let u=new Array;for(;;){let l=i.consumePositional();if(l===void 0||l===o.endDelimiter)break;u.push(l)}return{decodeValue(){return u.map(l=>ge(n,o.type,l))}}}}}function ge(o,e,t){return m.tryWithContext(()=>e.decoder(t),()=>new d(new a(o,T)))}function ct(o){throw new m(new d(new a(o,T),new a(": Failed to get default value")))}var F,W,M,P,I,j,y,ne,ke,he,Oe,K,Ve,me,ye,H=class{constructor(e){b(this,y);b(this,F);b(this,W);b(this,M);b(this,P);b(this,I);b(this,j);w(this,F,e),w(this,W,0),w(this,M,!1),w(this,P,new Map),w(this,I,new Map),w(this,j,new Map)}registerOption(e){let t=[...e.longs.map(n=>`--${n}`),...e.shorts.map(n=>`-${n}`)].join(", ");for(let n of e.longs){if(!f(this,y,me).call(this,n))throw new Error(`Invalid option name: --${n}`);if(g(this,P).has(n))throw new Error(`Option already registered: --${n}`)}for(let n of e.shorts){if(!f(this,y,me).call(this,n))throw new Error(`Invalid option name: -${n}`);if(g(this,I).has(n))throw new Error(`Option already registered: -${n}`);for(let r=0;r<n.length;r++){let i=n.slice(0,r);if(g(this,I).has(i))throw new Error(`Option -${n} overlap with shorter option: -${i}`)}for(let r of g(this,I).keys())if(r.startsWith(n))throw new Error(`Option -${n} overlap with longer option: -${r}`)}let s={parsing:e.parsing,results:new Array};for(let n of e.longs)g(this,P).set(n,s);for(let n of e.shorts)g(this,I).set(n,s);return g(this,j).set(t,s),t}getOptionValues(e){let t=g(this,j).get(e);if(t===void 0)throw new Error(`Unregistered option: ${e}`);return t.results}consumePositional(){for(;;){let e=f(this,y,ne).call(this);if(e===void 0)return;if(!f(this,y,ke).call(this,e))return e}}};F=new WeakMap,W=new WeakMap,M=new WeakMap,P=new WeakMap,I=new WeakMap,j=new WeakMap,y=new WeakSet,ne=function(){let e=g(this,F)[g(this,W)];if(e!==void 0)return be(this,W)._++,!g(this,M)&&e==="--"?(w(this,M,!0),f(this,y,ne).call(this)):e},ke=function(e){if(g(this,M))return!1;if(e.startsWith("--")){let t=e.indexOf("=");return t===-1?f(this,y,he).call(this,e.slice(2),null):f(this,y,he).call(this,e.slice(2,t),e.slice(t+1)),!0}if(e.startsWith("-")){let t=1,s=2;for(;s<=e.length;){let n=e.slice(t,s),r=g(this,I).get(n);if(r!==void 0){let i=e.slice(s);if(f(this,y,Oe).call(this,r,n,i))return!0;t=s}s++}f(this,y,ye).call(this,`-${e.slice(t)}`)}return!1},he=function(e,t){let s=`--${e}`,n=g(this,P).get(e);if(n!==void 0)return f(this,y,K).call(this,n,s,t);f(this,y,ye).call(this,s)},Oe=function(e,t,s){let n=`-${t}`;return s.startsWith("=")?(f(this,y,K).call(this,e,n,s.slice(1)),!0):s.length===0?(f(this,y,K).call(this,e,n,null),!0):e.parsing.consumeShortGroup?(f(this,y,K).call(this,e,n,s),!0):(f(this,y,K).call(this,e,n,null),!1)},K=function(e,t,s){let n=new Array;for(;e.parsing.consumeNextArg(s,n,g(this,F)[g(this,W)]);)n.push(f(this,y,Ve).call(this,t));e.results.push({inlined:s,separated:n})},Ve=function(e){let t=f(this,y,ne).call(this);if(t===void 0)throw new m(new d(new a(e,S),new a(": Requires a value, but got end of input")));if(g(this,M))throw new m(new d(new a(e,S),new a(": Requires a value before "),new a('"--"',x)));if(t.startsWith("-"))throw new m(new d(new a(e,S),new a(": Requires a value, but got: "),new a(`"${t}"`,x)));return t},me=function(e){return e.length>0&&!e.includes("=")&&!e.includes("\0")},ye=function(e){let t=[];for(let n of g(this,P).keys())t.push(`--${n}`);for(let n of g(this,I).keys())t.push(`-${n}`);let s=new d;if(s.push(new a("Unknown option: ")),s.push(new a(`"${e}"`,x)),t.length>0){let n=v(e,t.map(r=>({key:r,value:new a(r,S)}))).slice(0,3);s.push(new a(": did you mean: ")),s.push(d.join(n,new a(", "))),s.push(new a(" ?"))}else s.push(new a(", no options are registered"));throw new m(s)};function we(o){let{cliName:e,usage:t,typoSupport:s}=o,n=new Array,r=new d;r.push(gt("Usage:")),r.push(C(" ")),r.push(U(e));for(let u of t.segments)r.push(C(" ")),"positional"in u&&r.push(q(u.positional)),"subcommand"in u&&r.push(U(u.subcommand));n.push(r.computeStyledString(s)),n.push("");let i=new d;i.push(ht(t.information.description)),t.information.hint&&(i.push(C(" ")),i.push(Y(`(${t.information.hint})`))),n.push(i.computeStyledString(s));for(let u of t.information.details??[]){let l=new d;l.push(Y(u)),n.push(l.computeStyledString(s))}if(t.positionals.length>0){n.push(""),n.push(oe("Positionals:").computeStyledString(s));let u=new L;for(let l of t.positionals){let p=new Array;p.push(new d(C(" "))),p.push(new d(q(l.label))),p.push(...fe(l)),u.pushRow(p)}n.push(...u.computeStyledLines(s))}if(t.subcommands.length>0){n.push(""),n.push(oe("Subcommands:").computeStyledString(s));let u=new L;for(let l of t.subcommands){let p=new Array;p.push(new d(C(" "))),p.push(new d(U(l.name))),p.push(...fe(l)),u.pushRow(p)}n.push(...u.computeStyledLines(s))}if(t.options.length>0){n.push(""),n.push(oe("Options:").computeStyledString(s));let u=new L;for(let l of t.options){let p=new Array;p.push(new d(C(" "))),l.short?p.push(new d(U(`-${l.short}`),C(", "))):p.push(new d);let c=new d(U(`--${l.long}`));l.label&&(c.push(C(" ")),c.push(q(l.label))),l.annotation&&c.push(Y(l.annotation)),p.push(c),p.push(...fe(l)),u.pushRow(p)}n.push(...u.computeStyledLines(s))}if(t.information.examples){n.push(""),n.push(oe("Examples:").computeStyledString(s));for(let u of t.information.examples){let l=new d;l.push(C(" ")),l.push(Y(`# ${u.explanation}`)),n.push(l.computeStyledString(s));let p=new d;p.push(C(" ")),p.push(U(e));for(let c of u.commandArgs)if(p.push(C(" ")),typeof c=="string")p.push(new a(c));else if("positional"in c)p.push(q(c.positional));else if("subcommand"in c)p.push(U(c.subcommand));else if("option"in c){let h=c.option;if("short"in h?p.push(U(`-${h.short}`)):p.push(U(`--${h.long}`)),h.inlined!==void 0&&(p.push(Y("=")),p.push(q(h.inlined))),h.separated!==void 0)for(let A of h.separated)p.push(C(" ")),p.push(q(A))}n.push(p.computeStyledString(s))}}return n.push(""),n}function fe(o){let e=[];return o.description&&(e.push(C(" ")),e.push(mt(o.description))),o.hint&&(e.push(C(" ")),e.push(Y(`(${o.hint})`))),e.length>0?[new d(C(" "),...e)]:[]}function gt(o){return new a(o,V)}function ht(o){return new a(o,pe)}function mt(o){return new a(o)}function oe(o){return new a(o,ue)}function Y(o){return new a(o,le)}function U(o){return new a(o,S)}function q(o){return new a(o,T)}function C(o){return new a(o)}async function yt(o,e,t,s,n){let r=new H(e),i=new Array,u=O.none(),l=n?.colorSetup??"flag";if(l==="flag"){let h=de({long:"color",type:ae("color-mode",["auto","always","never","mock"]),defaultIfNotSpecified:()=>"auto",valueIfNothingInlined:()=>"always"}).registerAndMakeDecoder(r);i.push(()=>{try{u=$e(h.getAndDecodeValue())}catch(A){throw u=O.inferFromEnv(),A}})}else u=$e(l);if(n?.usageOnHelp??!0){let h=te({long:"help"}).registerAndMakeDecoder(r);i.push(A=>{if(h.getAndDecodeValue())return console.log(Ue(o,A,u)),0})}if(n?.buildVersion){let h=te({long:"version"}).registerAndMakeDecoder(r);i.push(()=>{if(h.getAndDecodeValue())return console.log([o,n.buildVersion].join(" ")),0})}let p=s.consumeAndMakeDecoder(r);for(;;)try{if(r.consumePositional()===void 0)break}catch{}let c=n?.onExit??process.exit;try{for(let A of i){let $=A(p);if($!==void 0)return c($)}let h=p.decodeAndMakeInterpreter();try{return await h.executeWithContext(t),c(0)}catch(A){return Ie(n?.onError,A,u),c(1)}}catch(h){return(n?.usageOnError??!0)&&console.error(Ue(o,p,u)),Ie(n?.onError,h,u),c(1)}}function Ie(o,e,t){o!==void 0?o(e):console.error(t.computeStyledErrorMessage(e))}function Ue(o,e,t){return we({cliName:o,usage:e.generateUsage(),typoSupport:t}).join(`
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var se=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var be=n=>{throw TypeError(n)};var Ee=(n,e)=>{for(var t in e)se(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of $e(e))!Ge.call(n,r)&&r!==t&&se(n,r,{get:()=>e[r],enumerable:!(o=Me(e,r))||o.enumerable});return n};var Le=n=>Ke(se({},"__esModule",{value:!0}),n);var ie=(n,e,t)=>e.has(n)||be("Cannot "+t);var g=(n,e,t)=>(ie(n,e,"read from private field"),t?t.call(n):e.get(n)),C=(n,e,t)=>e.has(n)?be("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),w=(n,e,t,o)=>(ie(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t),b=(n,e,t)=>(ie(n,e,"access private method"),t);var Se=(n,e,t,o)=>({set _(r){w(n,e,r,t)},get _(){return g(n,e,o)}});var Ct={};Ee(Ct,{ReaderArgs:()=>X,TypoError:()=>h,TypoGrid:()=>G,TypoString:()=>u,TypoSupport:()=>k,TypoText:()=>c,command:()=>Xe,commandChained:()=>_e,commandWithSubcommands:()=>Ze,operation:()=>et,optionFlag:()=>ne,optionRepeatable:()=>gt,optionSingleValue:()=>ge,positionalOptional:()=>yt,positionalRequired:()=>ht,positionalVariadics:()=>mt,runAndExit:()=>Tt,suggestTextPushMessage:()=>E,type:()=>at,typeBoolean:()=>le,typeChoice:()=>ce,typeConverted:()=>ut,typeDatetime:()=>rt,typeInteger:()=>st,typeList:()=>ct,typeNumber:()=>ot,typePath:()=>dt,typeRenamed:()=>pt,typeTuple:()=>lt,typeUrl:()=>it,typoStyleConstants:()=>R,typoStyleFailure:()=>Te,typoStyleLogic:()=>V,typoStyleQuote:()=>m,typoStyleRegularStrong:()=>pe,typoStyleRegularWeaker:()=>B,typoStyleTitle:()=>ue,typoStyleUserInput:()=>O,usageToStyledLines:()=>we});module.exports=Le(Ct);var ue={fgColor:"darkGreen",bold:!0},V={fgColor:"darkMagenta",bold:!0},m={fgColor:"darkYellow",bold:!0},Te={fgColor:"darkRed",bold:!0},R={fgColor:"darkCyan",bold:!0},O={fgColor:"darkBlue",bold:!0},pe={bold:!0},B={italic:!0,dim:!0},L,Q,Z=class Z{constructor(e,t){C(this,L);C(this,Q);w(this,L,e),w(this,Q,t)}computeStyledString(e){return e.computeStyledString(g(this,L),g(this,Q))}getRawString(){return g(this,L)}};L=new WeakMap,Q=new WeakMap,Z.elipsis=new Z("...",B);var u=Z,A,de=class de{constructor(...e){C(this,A);w(this,A,[]);for(let t of e)this.push(t)}push(...e){for(let t of e)if(typeof t=="string")g(this,A).push(new u(t));else if(t instanceof u)g(this,A).push(t);else if(t instanceof de)g(this,A).push(...g(t,A));else if(Array.isArray(t))for(let o of t)this.push(o)}pushJoined(e,t,o){for(let r=0;r<e.length;r++){if(r>0&&this.push(t),o!==void 0&&r>=o){this.push(u.elipsis);break}this.push(e[r])}}computeStyledString(e){return g(this,A).map(t=>t.computeStyledString(e)).join("")}computeRawString(){return g(this,A).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let t of g(this,A))e+=t.getRawString().length;return e}};A=new WeakMap;var c=de,$,G=class{constructor(){C(this,$);w(this,$,[])}pushRow(e){g(this,$).push(e)}computeStyledLines(e){let t=new Array,o=new Array;for(let r of g(this,$))for(let s=0;s<r.length;s++){let a=r[s].computeRawLength();(t[s]===void 0||a>t[s])&&(t[s]=a)}for(let r of g(this,$)){let s=new Array;for(let i=0;i<r.length;i++){let a=r[i];if(s.push(a.computeStyledString(e)),i<r.length-1){let d=a.computeRawLength(),p=" ".repeat(t[i]-d);s.push(p)}}o.push(s.join(""))}return o}};$=new WeakMap;var W,_=class _ extends Error{constructor(t,o){let r=new c;r.push(t),o instanceof _?(r.push(new u(": ")),r.push(g(o,W))):o instanceof Error?r.push(new u(`: ${o.message}`)):o!==void 0&&r.push(new u(`: ${String(o)}`));super(r.computeRawString());C(this,W);w(this,W,r)}computeStyledString(t){return g(this,W).computeStyledString(t)}static tryWithContext(t,o){try{return t()}catch(r){throw new _(o(),r)}}};W=new WeakMap;var h=_,D,S=class S{constructor(e){C(this,D);w(this,D,e)}static none(){return new S("none")}static tty(){return new S("tty")}static mock(){return new S("mock")}static inferFromEnv(){if(!process||!process.env||!process.stdout||ae("NO_COLOR"))return S.none();let e=ae("FORCE_COLOR");return e==="0"?S.none():e==="1"||e==="2"||e==="3"||e?S.tty():!process.stdout.isTTY||ae("TERM")?.toLowerCase()==="dumb"?S.none():S.tty()}computeStyledString(e,t){if(t===void 0)return e;let o=e;if(t.case==="upper"&&(o=o.toUpperCase()),t.case==="lower"&&(o=o.toLowerCase()),g(this,D)==="none")return o;if(g(this,D)==="tty"){let r=t.fgColor?Ye[t.fgColor]:"",s=t.bgColor?ze[t.bgColor]:"",i=t.bold?Be:"",a=t.dim?Ne:"",d=t.italic?Fe:"",p=t.underline?je:"",l=t.strikethrough?qe:"";return`${r}${s}${i}${a}${d}${p}${l}${o}${We}`}if(g(this,D)==="mock"){let r=t.fgColor?`{${o}}@${t.fgColor}`:o,s=t.bgColor?`{${r}}#${t.bgColor}`:r,i=t.bold?`{${s}}+`:s,a=t.dim?`{${i}}-`:i,d=t.italic?`{${a}}*`:a,p=t.underline?`{${d}}_`:d;return t.strikethrough?`{${p}}~`:p}throw new Error(`Unknown TypoSupport kind: ${g(this,D)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",Te),e instanceof h?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};D=new WeakMap;var k=S,We="\x1B[0m",Be="\x1B[1m",Ne="\x1B[2m",Fe="\x1B[3m",je="\x1B[4m",qe="\x1B[9m",Ye={darkBlack:"\x1B[30m",darkRed:"\x1B[31m",darkGreen:"\x1B[32m",darkYellow:"\x1B[33m",darkBlue:"\x1B[34m",darkMagenta:"\x1B[35m",darkCyan:"\x1B[36m",darkWhite:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"},ze={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function ae(n){if(n in process.env)return process.env[n]}function E(n,e,t){let o=He(e,t.map(({reference:r,hint:s})=>({reference:r,payload:s})));o.length!==0&&(n.push(new u(" Did you mean: ")),n.pushJoined(o,new u(", "),3),n.push(new u(" ?")))}function He(n,e){if(e.length===0)return[];let t=Qe(n,e),o=t[0].divergence+.25,r=new Array;for(let{divergence:s,payload:i}of t){if(s>o)break;r.push(i)}return r}function Qe(n,e){let t=n.toLowerCase().slice(0,100);return e.map(({reference:r,payload:s})=>{let i=r.toLowerCase().slice(0,100);return{divergence:Je(t,i)/Math.max(t.length,i.length),reference:r,payload:s}}).sort((r,s)=>r.divergence-s.divergence)}function Je(n,e){let t=n.length,o=e.length,r=Array.from({length:t+1},()=>Array(o+1).fill(0));for(let s=0;s<=t;s++)r[s][0]=s;for(let s=0;s<=o;s++)r[0][s]=s;for(let s=1;s<=t;s++)for(let i=1;i<=o;i++){let a=n[s-1]===e[i-1]?0:1;r[s][i]=Math.min(r[s-1][i]+1,r[s][i-1]+1,r[s-1][i-1]+a),s>1&&i>1&&n[s-1]===e[i-2]&&n[s-2]===e[i-1]&&(r[s][i]=Math.min(r[s][i],r[s-2][i-2]+a))}return r[t][o]}function Xe(n,e){return{getInformation(){return n},consumeAndMakeDecoder(t){try{let o=e.consumeAndMakeDecoder(t),r=t.consumePositional();if(r!==void 0){let s=new c;throw s.push(new u("Unexpected argument: ")),s.push(new u(`"${r}"`,m)),s.push(new u(".")),new h(s)}return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){let s=o.decodeAndMakeInterpreter();return{async executeWithContext(i){return await s.executeWithContext(i)}}}}}catch(o){return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){throw o}}}}}}function Ze(n,e,t){let o=Object.keys(t);if(o.length===0)throw new Error("At least one subcommand is required");return{getInformation(){return n},consumeAndMakeDecoder(r){try{let s=e.consumeAndMakeDecoder(r),i=r.consumePositional();if(i===void 0){let p=new c;throw p.push(new u("<subcommand>",O)),p.push(new u(": Missing argument.")),Ce(p,"",o),new h(p)}let a=t[i];if(a===void 0){let p=new c;throw p.push(new u("<subcommand>",O)),p.push(new u(": Unknown name: ")),p.push(new u(`"${i}"`,m)),p.push(new u(".")),Ce(p,i,o),new h(p)}let d=a.consumeAndMakeDecoder(r);return{generateUsage(){let p=d.generateUsage(),l=N(n,e);return l.segments.push({subcommand:i}),l.segments.push(...p.segments),l.information=p.information,l.positionals.push(...p.positionals),l.subcommands=p.subcommands,l.options.push(...p.options),l},decodeAndMakeInterpreter(){let p=s.decodeAndMakeInterpreter(),l=d.decodeAndMakeInterpreter();return{async executeWithContext(f){return await l.executeWithContext(await p.executeWithContext(f))}}}}}catch(s){return{generateUsage(){let i=N(n,e);i.segments.push({positional:"<subcommand>"});for(let[a,d]of Object.entries(t)){let{description:p,hint:l}=d.getInformation();i.subcommands.push({name:a,description:p,hint:l})}return i},decodeAndMakeInterpreter(){throw s}}}}}}function _e(n,e,t){return{getInformation(){return n},consumeAndMakeDecoder(o){try{let r=e.consumeAndMakeDecoder(o),s=t.consumeAndMakeDecoder(o);return{generateUsage(){let i=s.generateUsage(),a=N(n,e);return a.segments.push(...i.segments),a.information=i.information,a.positionals.push(...i.positionals),a.subcommands=i.subcommands,a.options.push(...i.options),a},decodeAndMakeInterpreter(){let i=r.decodeAndMakeInterpreter(),a=s.decodeAndMakeInterpreter();return{async executeWithContext(d){return await a.executeWithContext(await i.executeWithContext(d))}}}}}catch(r){return{generateUsage(){let s=N(n,e);return s.segments.push({positional:"[REST]..."}),s},decodeAndMakeInterpreter(){throw r}}}}}}function N(n,e){let{positionals:t,options:o}=e.generateUsage();return{segments:t.map(r=>({positional:r.label})),information:n,positionals:t,subcommands:[],options:o}}function Ce(n,e,t=[]){E(n,e,t.map(o=>({reference:o,hint:new u(o,R)})))}function et(n,e){return{generateUsage(){let t=new Array;if(n.options!==void 0)for(let r in n.options){let s=n.options[r];t.push(s.generateUsage())}let o=new Array;if(n.positionals!==void 0)for(let r of n.positionals)o.push(r.generateUsage());return{options:t,positionals:o}},consumeAndMakeDecoder(t){let o={};if(n.options!==void 0)for(let s in n.options){let i=n.options[s];o[s]=i.registerAndMakeDecoder(t)}let r=[];if(n.positionals!==void 0)for(let s of n.positionals)r.push(s.consumeAndMakeDecoder(t));return{decodeAndMakeInterpreter(){let s={};for(let a in o)s[a]=o[a].getAndDecodeValue();let i=[];for(let a of r)i.push(a.decodeValue());return{executeWithContext(a){return e(a,{options:s,positionals:i})}}}}}}}var Re=require("fs");function le(n){return{content:n??"boolean",decoder(e){let t=e.toLowerCase();if(tt.has(t))return!0;if(nt.has(t))return!1;J("a boolean",e)}}}var tt=new Set(["true","yes","on","y"]),nt=new Set(["false","no","off","n"]);function rt(n){return{content:n??"datetime",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{J("a valid ISO_8601 datetime",e)}}}}function ot(n){return{content:n??"number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{J("a number",e)}}}}function st(n){return{content:n??"integer",decoder(e){try{return BigInt(e)}catch{J("an integer",e)}}}}function it(n){return{content:n??"url",decoder(e){try{return new URL(e)}catch{J("an URL",e)}}}}function at(n){return{content:n??"string",decoder:e=>e}}function ut(n,e,t){return{content:n,decoder:o=>t(h.tryWithContext(()=>e.decoder(o),()=>new c(new u("from: "),new u(e.content,V))))}}function pt(n,e){return{content:e,decoder:t=>h.tryWithContext(()=>n.decoder(t),()=>new c(new u("from: "),new u(n.content,V)))}}function dt(n,e){return{content:n??"path",decoder(t){if(t.length===0)throw new Error("Path cannot be empty");if(t.includes("\0"))throw new Error("Path cannot contain null characters");if(e?.checkSyncExistAs!==void 0){let r=function(a){try{return(0,Re.statSync)(a)}catch(d){throw new h(new c(new u("Path does not exist: "),new u(`"${a}"`,m)),d)}};var o=r;let s=r(t),i=s.isDirectory()?"directory":s.isFile()?"file":"unknown";if(e.checkSyncExistAs==="file"&&!s.isFile())throw new h(new c(new u(`Expected a file but found: ${i}: `),new u(`"${t}"`,m)));if(e.checkSyncExistAs==="directory"&&!s.isDirectory())throw new h(new c(new u(`Expected a directory but found: ${i}: `),new u(`"${t}"`,m)))}return t}}}function ce(n,e,t=!0){if(e.length===0)throw new Error("At least one value is required");let o=t?s=>s:s=>s.toLowerCase(),r=new Map(e.map(s=>[o(s),s]));return{content:n,decoder(s){let i=r.get(o(s));if(i!==void 0)return i;let a=new c;throw a.push(new u("Unknown value: ")),a.push(new u(`"${s}"`,m)),a.push(new u(".")),E(a,s,e.map(d=>({reference:d,hint:new u(`"${d}"`,m)}))),new h(a)}}}function lt(n,e=","){return{content:n.map(t=>t.content).join(e),decoder(t){let o=t.split(e,n.length);if(o.length!==n.length)throw new h(new c(new u(`Found ${o.length} splits: `),new u(`Expected ${n.length} splits from: `),new u(`"${t}"`,m),new u(".")));return o.map((r,s)=>{let i=n[s];return h.tryWithContext(()=>i.decoder(r),()=>new c(new u(`at ${s}: `),new u(i.content,V)))})}}}function ct(n,e=","){return{content:`${n.content}[${e}${n.content}]...`,decoder(t){return t.split(e).map((r,s)=>h.tryWithContext(()=>n.decoder(r),()=>new c(new u(`at ${s}: `),new u(n.content,V))))}}}function J(n,e){throw new h(new c(new u(`Not ${n}: `),new u(`"${e}"`,m),new u(".")))}function ne(n){let e=le("value"),{long:t,short:o,description:r,hint:s,aliases:i}=n;return{generateUsage(){return{short:o,long:t,annotation:"[=no]",description:r,hint:s}},registerAndMakeDecoder(a){let d=fe(a,{longKey:t,shortKey:o,aliasLongKeys:i?.longs,aliasShortKeys:i?.shorts,restGuard:()=>!1,nextGuard:()=>!1});return{getAndDecodeValue(){let p=d();if(p.length>1&&Ae(p.map(f=>f.identifier)),p.length===0)return n.default===void 0?!1:n.default;let l=p[0].value.inlined;return l===null?!0:te({long:t,label:void 0,type:e,input:l})}}}}}function ge(n){let{long:e,short:t,description:o,hint:r,aliases:s,type:i}=n,a=n.impliedValueIfNotInlined?void 0:`<${i.content}>`,d=n.impliedValueIfNotInlined?`[=${i.content}]`:void 0;return{generateUsage(){return{short:t,long:e,label:a,annotation:d,description:o,hint:r}},registerAndMakeDecoder(p){let l=fe(p,{longKey:e,shortKey:t,aliasLongKeys:s?.longs,aliasShortKeys:s?.shorts,restGuard:()=>n.impliedValueIfNotInlined===void 0,nextGuard:f=>!(n.impliedValueIfNotInlined!==void 0||f.inlined!==null||f.separated.length!==0)});return{getAndDecodeValue(){let f=l();f.length>1&&Ae(f.map(v=>v.identifier));let x=f[0];if(x===void 0){if(n.fallbackValueIfAbsent===void 0){let v=ee({long:e,label:a,type:i});throw v.push(new u(": Is required, but was not set.")),new h(v)}try{return n.fallbackValueIfAbsent()}catch(v){let H=ee({long:e,label:a,type:i});throw H.push(new u(": Failed to get fallback value.")),new h(H,v)}}let z=x.value.inlined;if(z!==null)return te({long:e,label:a,type:i,input:z});if(n.impliedValueIfNotInlined!==void 0)try{return n.impliedValueIfNotInlined()}catch(v){let H=ee({long:e,label:a,type:i});throw H.push(new u(": Failed to get implied value.")),new h(H,v)}let Pe=x.value.separated[0];return te({long:e,label:a,type:i,input:Pe})}}}}}function gt(n){let{long:e,short:t,description:o,hint:r,aliases:s,type:i}=n,a=`<${i.content}>`;return{generateUsage(){return{short:t,long:e,label:a,annotation:" [*]",description:o,hint:r}},registerAndMakeDecoder(d){let p=fe(d,{longKey:e,shortKey:t,aliasLongKeys:s?.longs,aliasShortKeys:s?.shorts,restGuard:()=>!0,nextGuard:l=>!(l.inlined!==null||l.separated.length!==0)});return{getAndDecodeValue(){return p().map(l=>{let f=l.value,x=f.inlined??f.separated[0];return te({long:e,label:a,type:i,input:x})})}}}}}function te(n){let{long:e,label:t,type:o,input:r}=n;return h.tryWithContext(()=>o.decoder(r),()=>ee({long:e,label:t,type:o}))}function ee(n){let e=new c;return e.push(new u(`--${n.long}`,R)),n.label!==void 0?(e.push(new u(": ")),e.push(new u(n.label,O))):(e.push(new u(": ")),e.push(new u(n.type.content,V))),e}function fe(n,e){let{longKey:t,shortKey:o,aliasLongKeys:r,aliasShortKeys:s}=e,i=[t];r!==void 0&&i.push(...r);let a=o?[o]:[];return s!==void 0&&a.push(...s),ft(n,{longKeys:i,shortKeys:a,restGuard:e.restGuard,nextGuard:e.nextGuard})}function ft(n,e){let{longKeys:t,shortKeys:o,restGuard:r,nextGuard:s}=e,i=new Array;for(let a of t)i.push(n.registerOptionLong({key:a,nextGuard:s}));for(let a of o)i.push(n.registerOptionShort({key:a,restGuard:r,nextGuard:s}));return()=>{let a=new Array;for(let d of i){let{identifier:p,values:l}=d();for(let f of l)a.push({identifier:p,value:f})}return a}}function Ae(n){let e=Array.from(new Set(n)).map(o=>new u(o,R)),t=new c;throw t.pushJoined(e,new u(", "),3),t.push(new u(": Must not be set multiple times.")),new h(t)}function ht(n){let{description:e,hint:t,type:o}=n,r=`<${o.content}>`;return{generateUsage(){return{description:e,hint:t,label:r}},consumeAndMakeDecoder(s){let i=s.consumePositional();if(i===void 0){let a=ke(r);throw a.push(new u(": Is required, but was not provided.")),e!==void 0&&a.push(new u(` (${e})`,B)),new h(a)}return{decodeValue(){return he(r,n.type,i)}}}}}function yt(n){let{description:e,hint:t,type:o}=n,r=`[${o.content}]`;return{generateUsage(){return{description:e,hint:t,label:r}},consumeAndMakeDecoder(s){let i=s.consumePositional();return{decodeValue(){if(i===void 0)try{return n.default()}catch{xt(r)}return he(r,n.type,i)}}}}}function mt(n){let{description:e,hint:t,type:o}=n,r=`[${o.content}]`,s=`${r}...`+(n.endDelimiter?` ["${n.endDelimiter}"]`:"");return{generateUsage(){return{description:e,hint:t,label:s}},consumeAndMakeDecoder(i){let a=new Array;for(;;){let d=i.consumePositional();if(d===void 0||d===n.endDelimiter)break;a.push(d)}return{decodeValue(){return a.map(d=>he(r,n.type,d))}}}}}function he(n,e,t){return h.tryWithContext(()=>e.decoder(t),()=>new c(new u(n,O)))}function ke(n){let e=new c;return e.push(new u(n,O)),e}function xt(n){let e=ke(n);throw e.push(new u(": Failed to get default value.")),new h(e)}var j,K,P,M,I,y,re,Ve,ye,Ie,F,me,X=class{constructor(e){C(this,y);C(this,j);C(this,K);C(this,P);C(this,M);C(this,I);w(this,j,e),w(this,K,0),w(this,P,!1),w(this,M,new Map),w(this,I,new Map)}registerOptionLong(e){let t=`--${e.key}`;if(!Oe(e.key))throw new Error(`Option identifier is invalid: ${t}.`);if(g(this,M).has(t))throw new Error(`Option already registered: ${t}.`);let o=new Array;return g(this,M).set(t,{identifier:t,spec:e,values:o}),()=>({identifier:t,values:o})}registerOptionShort(e){let t=`-${e.key}`;if(!Oe(e.key))throw new Error(`Option identifier is invalid: ${t}.`);if(g(this,I).has(t))throw new Error(`Option already registered: ${t}.`);for(let r=0;r<t.length;r++){let s=t.slice(0,1+r);if(g(this,I).has(s))throw new Error(`Option ${t} overlap with shorter option: ${s}.`)}for(let r of g(this,I).keys())if(r.startsWith(t))throw new Error(`Option ${t} overlap with longer option: ${r}.`);let o=new Array;return g(this,I).set(t,{identifier:t,spec:e,values:o}),()=>({identifier:t,values:o})}consumePositional(){for(;;){let e=b(this,y,re).call(this);if(e===void 0)return;if(!b(this,y,Ve).call(this,e))return e}}};j=new WeakMap,K=new WeakMap,P=new WeakMap,M=new WeakMap,I=new WeakMap,y=new WeakSet,re=function(){let e=g(this,j)[g(this,K)];if(e!==void 0)return Se(this,K)._++,!g(this,P)&&e==="--"?(w(this,P,!0),b(this,y,re).call(this)):e},Ve=function(e){if(g(this,P))return!1;if(e.startsWith("--")){let t=e.indexOf("=");return t===-1?b(this,y,ye).call(this,e,null):b(this,y,ye).call(this,e.slice(0,t),e.slice(t+1)),!0}if(e.startsWith("-")){let t=1,o=2;for(;o<=e.length;){let r=`-${e.slice(t,o)}`,s=g(this,I).get(r);if(s!==void 0){let i=e.slice(o);if(b(this,y,Ie).call(this,s,i))return!0;t=o}o++}b(this,y,me).call(this,`-${e.slice(t)}`)}return!1},ye=function(e,t){let o=g(this,M).get(e);if(o!==void 0)return b(this,y,F).call(this,o,t);b(this,y,me).call(this,e)},Ie=function(e,t){return t.startsWith("=")?(b(this,y,F).call(this,e,t.slice(1)),!0):t.length===0?(b(this,y,F).call(this,e,null),!0):e.spec.restGuard(t)?(b(this,y,F).call(this,e,t),!0):(b(this,y,F).call(this,e,null),!1)},F=function(e,t){let o={inlined:t,separated:new Array},{identifier:r,values:s,spec:i}=e;for(s.push(o);;){let a=g(this,j)[g(this,K)];if(!i.nextGuard(o,a))return;let d=b(this,y,re).call(this);if(g(this,P))throw new h(new c(new u(r,R),new u(": Requires a value but got: "),new u('"--"',m),new u(".")));if(d===void 0)throw new h(new c(new u(r,R),new u(": Requires a value, but got end of input.")));if(d.startsWith("-"))throw new h(new c(new u(r,R),new u(": Requires a value, but got: "),new u(`"${d}"`,m),new u(".")));o.separated.push(d)}},me=function(e){let t=[];for(let r of g(this,M).keys())t.push(r);for(let r of g(this,I).keys())t.push(r);let o=new c;throw o.push(new u("Unknown option: ")),o.push(new u(`"${e}"`,m)),t.length===0?o.push(new u(", no options are registered.")):(o.push(new u(".")),E(o,e,t.map(r=>({reference:r,hint:new u(r,R)})))),new h(o)};function Oe(n){return n.length>0&&!n.includes("=")&&!n.includes("\0")}function we(n){let{cliName:e,usage:t,typoSupport:o}=n,r=new Array,s=new c;s.push(wt("Usage:")),s.push(T(" ")),s.push(U(e));for(let a of t.segments)s.push(T(" ")),"positional"in a&&s.push(q(a.positional)),"subcommand"in a&&s.push(U(a.subcommand));r.push(s.computeStyledString(o)),r.push("");let i=new c;i.push(bt(t.information.description)),t.information.hint!==void 0&&(i.push(T(" ")),i.push(Y(`(${t.information.hint})`))),r.push(i.computeStyledString(o));for(let a of t.information.details??[]){let d=new c;d.push(Y(a)),r.push(d.computeStyledString(o))}if(t.positionals.length>0){r.push(""),r.push(oe("Positionals:").computeStyledString(o));let a=new G;for(let d of t.positionals){let p=new Array;p.push(new c(T(" "))),p.push(new c(q(d.label))),p.push(...xe(d)),a.pushRow(p)}r.push(...a.computeStyledLines(o))}if(t.subcommands.length>0){r.push(""),r.push(oe("Subcommands:").computeStyledString(o));let a=new G;for(let d of t.subcommands){let p=new Array;p.push(new c(T(" "))),p.push(new c(U(d.name))),p.push(...xe(d)),a.pushRow(p)}r.push(...a.computeStyledLines(o))}if(t.options.length>0){r.push(""),r.push(oe("Options:").computeStyledString(o));let a=new G;for(let d of t.options){let p=new Array;p.push(new c(T(" "))),d.short!==void 0?p.push(new c(U(`-${d.short}`),T(", "))):p.push(new c);let l=new c(U(`--${d.long}`));d.label!==void 0&&(l.push(T(" ")),l.push(q(d.label))),d.annotation!==void 0&&l.push(Y(d.annotation)),p.push(l),p.push(...xe(d)),a.pushRow(p)}r.push(...a.computeStyledLines(o))}if(t.information.examples!==void 0){r.push(""),r.push(oe("Examples:").computeStyledString(o));for(let a of t.information.examples){let d=new c;d.push(T(" ")),d.push(Y(`# ${a.explanation}`)),r.push(d.computeStyledString(o));let p=new c;p.push(T(" ")),p.push(U(e));for(let l of a.commandArgs)if(p.push(T(" ")),typeof l=="string")p.push(new u(l));else if("positional"in l)p.push(q(l.positional));else if("subcommand"in l)p.push(U(l.subcommand));else if("option"in l){let f=l.option;if("short"in f?p.push(U(`-${f.short}`)):p.push(U(`--${f.long}`)),f.inlined!==void 0&&(p.push(Y("=")),p.push(q(f.inlined))),f.separated!==void 0)for(let x of f.separated)p.push(T(" ")),p.push(q(x))}r.push(p.computeStyledString(o))}}return r.push(""),r}function xe(n){let e=[];return n.description!==void 0&&(e.push(T(" ")),e.push(St(n.description))),n.hint!==void 0&&(e.push(T(" ")),e.push(Y(`(${n.hint})`))),e.length>0?[new c(T(" "),...e)]:[]}function wt(n){return new u(n,V)}function bt(n){return new u(n,pe)}function St(n){return new u(n)}function oe(n){return new u(n,ue)}function Y(n){return new u(n,B)}function U(n){return new u(n,R)}function q(n){return new u(n,O)}function T(n){return new u(n)}async function Tt(n,e,t,o,r){let s=new X(e),i=new Array,a=k.none(),d=r?.colorSetup??"flag";if(d==="flag"){let f=ge({long:"color",type:ce("color-mode",["auto","always","never"]),fallbackValueIfAbsent:()=>"auto",impliedValueIfNotInlined:()=>"always"}).registerAndMakeDecoder(s);i.push(()=>{try{a=De(f.getAndDecodeValue())}catch(x){throw a=k.inferFromEnv(),x}})}else a=De(d);if(r?.usageOnHelp??!0){let f=ne({long:"help"}).registerAndMakeDecoder(s);i.push(x=>{if(f.getAndDecodeValue())return console.log(ve(n,x,a)),0})}if(r?.buildVersion!==void 0){let f=ne({long:"version"}).registerAndMakeDecoder(s);i.push(()=>{if(f.getAndDecodeValue())return console.log([n,r.buildVersion].join(" ")),0})}let p=o.consumeAndMakeDecoder(s);for(;;)try{if(s.consumePositional()===void 0)break}catch{}let l=r?.onExit??process.exit;try{for(let x of i){let z=x(p);if(z!==void 0)return l(z)}let f=p.decodeAndMakeInterpreter();try{return await f.executeWithContext(t),l(0)}catch(x){return Ue(n,r?.onError,x,a),l(1)}}catch(f){return(r?.usageOnError??!0)&&console.error(ve(n,p,a)),Ue(n,r?.onError,f,a),l(1)}}function Ue(n,e,t,o){let r=t;e!==void 0?e(r):console.error(o.computeStyledErrorMessage(r))}function ve(n,e,t){return we({cliName:n,usage:e.generateUsage(),typoSupport:t}).join(`
|
|
2
|
+
`)}function De(n){switch(n){case"auto":return k.inferFromEnv();case"env":return k.inferFromEnv();case"always":return k.tty();case"never":return k.none();case"mock":return k.mock()}}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,suggestTextPushMessage,type,typeBoolean,typeChoice,typeConverted,typeDatetime,typeInteger,typeList,typeNumber,typePath,typeRenamed,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|