cli-kiss 0.2.4 → 0.2.5
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 +150 -164
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +1 -0
- package/docs/guide/01_getting_started.md +12 -13
- package/docs/guide/02_commands.md +12 -29
- package/docs/guide/03_options.md +16 -25
- package/docs/guide/04_positionals.md +45 -55
- package/docs/guide/05_types.md +66 -66
- package/docs/guide/06_run.md +28 -40
- package/docs/public/favicon.ico +0 -0
- package/docs/public/hero.png +0 -0
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/lib/Command.ts +14 -35
- package/src/lib/Operation.ts +13 -4
- package/src/lib/Option.ts +118 -162
- package/src/lib/Positional.ts +37 -62
- package/src/lib/Reader.ts +3 -3
- package/src/lib/Run.ts +74 -46
- package/src/lib/Type.ts +227 -141
- package/src/lib/Typo.ts +36 -24
- package/src/lib/Usage.ts +27 -42
- package/tests/unit.Reader.parsings.ts +50 -0
- package/tests/unit.command.execute.ts +13 -13
- package/tests/unit.command.usage.ts +60 -54
- package/tests/unit.runner.colors.ts +197 -0
- package/tests/unit.runner.cycle.ts +69 -55
- package/tests/unit.runner.errors.ts +12 -20
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var le=e=>{throw TypeError(e)};var Se=(e,t)=>{for(var n in t)X(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of be(t))!Ce.call(e,o)&&o!==n&&X(e,o,{get:()=>t[o],enumerable:!(r=xe(t,o))||r.enumerable});return e};var Ae=e=>Re(X({},"__esModule",{value:!0}),e);var Z=(e,t,n)=>t.has(e)||le("Cannot "+n);var g=(e,t,n)=>(Z(e,t,"read from private field"),n?n.call(e):t.get(e)),b=(e,t,n)=>t.has(e)?le("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),f=(e,t,n,r)=>(Z(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),x=(e,t,n)=>(Z(e,t,"access private method"),n);var ce=(e,t,n,r)=>({set _(o){f(e,t,o,n)},get _(){return g(e,t,r)}});var it={};Se(it,{ReaderArgs:()=>j,TypoError:()=>d,TypoGrid:()=>D,TypoString:()=>s,TypoSupport:()=>$,TypoText:()=>c,command:()=>De,commandChained:()=>ve,commandWithSubcommands:()=>Me,operation:()=>Ee,optionFlag:()=>ze,optionRepeatable:()=>Xe,optionSingleValue:()=>Je,positionalOptional:()=>_e,positionalRequired:()=>Ze,positionalVariadics:()=>et,runAndExit:()=>rt,typeBoolean:()=>H,typeDate:()=>Ge,typeInteger:()=>Ke,typeList:()=>Qe,typeMapped:()=>Ye,typeNumber:()=>Ne,typeOneOf:()=>qe,typeString:()=>je,typeTuple:()=>He,typeUrl:()=>Fe,typoStyleConstants:()=>w,typoStyleFailure:()=>ge,typoStyleLogic:()=>k,typoStyleQuote:()=>y,typoStyleRegularStrong:()=>ee,typoStyleRegularWeaker:()=>te,typoStyleTitle:()=>_,typoStyleUserInput:()=>R,usageToStyledLines:()=>ue});module.exports=Ae(it);var _={fgColor:"darkGreen",bold:!0},k={fgColor:"darkMagenta",bold:!0},y={fgColor:"darkYellow",bold:!0},ge={fgColor:"darkRed",bold:!0},w={fgColor:"darkCyan",bold:!0},R={fgColor:"darkBlue",bold:!0},ee={bold:!0},te={italic:!0,dim:!0},L,F,s=class{constructor(t,n={}){b(this,L);b(this,F);f(this,L,t),f(this,F,n)}computeStyledString(t){return t.computeStyledString(g(this,L),g(this,F))}getRawString(){return g(this,L)}};L=new WeakMap,F=new WeakMap;var S,ne=class ne{constructor(...t){b(this,S);f(this,S,[]);for(let n of t)this.push(n)}push(t){if(typeof t=="string")g(this,S).push(new s(t));else if(t instanceof ne)g(this,S).push(...g(t,S));else if(Array.isArray(t))for(let n of t)g(this,S).push(n);else g(this,S).push(t)}computeStyledString(t){return g(this,S).map(n=>n.computeStyledString(t)).join("")}computeRawString(){return g(this,S).map(t=>t.getRawString()).join("")}computeRawLength(){let t=0;for(let n of g(this,S))t+=n.getRawString().length;return t}};S=new WeakMap;var c=ne,P,D=class{constructor(){b(this,P);f(this,P,[])}pushRow(t){g(this,P).push(t)}computeStyledLines(t){let n=new Array,r=new Array;for(let o of g(this,P))for(let i=0;i<o.length;i++){let a=o[i].computeRawLength();(n[i]===void 0||a>n[i])&&(n[i]=a)}for(let o of g(this,P)){let i=new Array;for(let u=0;u<o.length;u++){let a=o[u];if(i.push(a.computeStyledString(t)),u<o.length-1){let l=a.computeRawLength(),p=" ".repeat(n[u]-l);i.push(p)}}r.push(i.join(""))}return r}};P=new WeakMap;var E,q=class q extends Error{constructor(n,r){let o=new c;o.push(n),r instanceof q?(o.push(new s(": ")),o.push(g(r,E))):r instanceof Error?o.push(new s(`: ${r.message}`)):r!==void 0&&o.push(new s(`: ${String(r)}`));super(o.computeRawString());b(this,E);f(this,E,o)}computeStyledString(n){return g(this,E).computeStyledString(n)}static tryWithContext(n,r){try{return n()}catch(o){throw new q(r(),o)}}};E=new WeakMap;var d=q,V,T=class T{constructor(t){b(this,V);f(this,V,t)}static none(){return new T("none")}static tty(){return new T("tty")}static mock(){return new T("mock")}static inferFromProcess(){if(!process)return T.none();if(process.env){if(process.env.FORCE_COLOR==="0")return T.none();if(process.env.FORCE_COLOR)return T.tty();if("NO_COLOR"in process.env)return T.none()}return process.stdout&&process.stdout.isTTY?T.tty():T.none()}computeStyledString(t,n){if(g(this,V)==="none")return t;if(g(this,V)==="tty"){let r=n.fgColor?Ie[n.fgColor]:"",o=n.bgColor?Pe[n.bgColor]:"",i=n.bold?ke:"",u=n.dim?Oe:"",a=n.italic?Ue:"",l=n.underline?Ve:"",p=n.strikethrough?$e:"";return`${r}${o}${i}${u}${a}${l}${p}${t}${Te}`}if(g(this,V)==="mock"){let r=n.fgColor?`{${t}}@${n.fgColor}`:t,o=n.bgColor?`{${r}}#${n.bgColor}`:r,i=n.bold?`{${o}}+`:o,u=n.dim?`{${i}}-`:i,a=n.italic?`{${u}}*`:u,l=n.underline?`{${a}}_`:a;return n.strikethrough?`{${l}}~`:l}throw new Error(`Unknown TypoSupport kind: ${g(this,V)}`)}computeStyledErrorMessage(t){return[this.computeStyledString("Error:",ge),t instanceof d?t.computeStyledString(this):t instanceof Error?t.message:String(t)].join(" ")}};V=new WeakMap;var $=T,Te="\x1B[0m",ke="\x1B[1m",Oe="\x1B[2m",Ue="\x1B[3m",Ve="\x1B[4m",$e="\x1B[9m",Ie={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"},Pe={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 De(e,t){return{getInformation(){return e},consumeAndMakeDecoder(n){try{let r=t.consumeAndMakeDecoder(n),o=n.consumePositional();if(o!==void 0)throw new d(new c(new s("Unexpected argument: "),new s(`"${o}"`,y)));return{generateUsage:()=>W(e,t),decodeAndMakeInterpreter(){let i=r.decodeAndMakeInterpreter();return{async executeWithContext(u){return await i.executeWithContext(u)}}}}}catch(r){return{generateUsage:()=>W(e,t),decodeAndMakeInterpreter(){throw r}}}}}}function Me(e,t,n){return{getInformation(){return e},consumeAndMakeDecoder(r){try{let o=t.consumeAndMakeDecoder(r),i=r.consumePositional();if(i===void 0)throw new d(new c(new s("<SUBCOMMAND>",R),new s(": Is required, but was not provided")));let u=n[i];if(u===void 0)throw new d(new c(new s("<SUBCOMMAND>",R),new s(": Invalid value: "),new s(`"${i}"`,y)));let a=u.consumeAndMakeDecoder(r);return{generateUsage(){let l=a.generateUsage(),p=W(e,t);return p.segments.push(Le(i)),p.segments.push(...l.segments),p.information=l.information,p.positionals.push(...l.positionals),p.subcommands=l.subcommands,p.options.push(...l.options),p},decodeAndMakeInterpreter(){let l=o.decodeAndMakeInterpreter(),p=a.decodeAndMakeInterpreter();return{async executeWithContext(m){return await p.executeWithContext(await l.executeWithContext(m))}}}}}catch(o){return{generateUsage(){let i=W(e,t);i.segments.push(oe("<SUBCOMMAND>"));for(let[u,a]of Object.entries(n)){let{description:l,hint:p}=a.getInformation();i.subcommands.push({name:u,description:l,hint:p})}return i},decodeAndMakeInterpreter(){throw o}}}}}}function ve(e,t,n){return{getInformation(){return e},consumeAndMakeDecoder(r){try{let o=t.consumeAndMakeDecoder(r),i=n.consumeAndMakeDecoder(r);return{generateUsage(){let u=i.generateUsage(),a=W(e,t);return a.segments.push(...u.segments),a.information=u.information,a.positionals.push(...u.positionals),a.subcommands=u.subcommands,a.options.push(...u.options),a},decodeAndMakeInterpreter(){let u=o.decodeAndMakeInterpreter(),a=i.decodeAndMakeInterpreter();return{async executeWithContext(l){return await a.executeWithContext(await u.executeWithContext(l))}}}}}catch(o){return{generateUsage(){let i=W(e,t);return i.segments.push(oe("[REST]...")),i},decodeAndMakeInterpreter(){throw o}}}}}}function oe(e){return{positional:e}}function Le(e){return{subcommand:e}}function W(e,t){let{positionals:n,options:r}=t.generateUsage();return{segments:n.map(o=>oe(o.label)),information:e,positionals:n,subcommands:[],options:r}}function Ee(e,t){return{generateUsage(){let n=new Array;for(let o in e.options){let i=e.options[o];n.push(i.generateUsage())}let r=new Array;for(let o of e.positionals)r.push(o.generateUsage());return{options:n,positionals:r}},consumeAndMakeDecoder(n){let r={};for(let i in e.options){let u=e.options[i];r[i]=u.registerAndMakeDecoder(n)}let o=[];for(let i of e.positionals)o.push(i.consumeAndMakeDecoder(n));return{decodeAndMakeInterpreter(){let i={};for(let a in r)i[a]=r[a].getAndDecodeValue();let u=[];for(let a of o)u.push(a.decodeValue());return{executeWithContext(a){return t(a,{options:i,positionals:u})}}}}}}}var H={content:"Boolean",decoder(e){let t=e.toLowerCase();if(We.has(t))return!0;if(Be.has(t))return!1;throw new d(new c(new s("Invalid value: "),new s(`"${e}"`,y)))}},We=new Set(["true","yes","on","1","y","t"]),Be=new Set(["false","no","off","0","n","f"]),Ge={content:"Date",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{throw new d(new c(new s("Not a valid ISO_8601: "),new s(`"${e}"`,y)))}}},Ne={content:"Number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{throw new d(new c(new s("Unable to parse: "),new s(`"${e}"`,y)))}}},Ke={content:"Integer",decoder(e){try{return BigInt(e)}catch{throw new d(new c(new s("Unable to parse: "),new s(`"${e}"`,y)))}}},Fe={content:"Url",decoder(e){try{return new URL(e)}catch{throw new d(new c(new s("Unable to parse: "),new s(`"${e}"`,y)))}}},je={content:"String",decoder(e){return e}};function Ye(e,t){return{content:t.content,decoder:n=>t.decoder(d.tryWithContext(()=>e.decoder(n),()=>new c(new s("from: "),new s(e.content,k))))}}function qe(e,t){return{content:e,decoder(n){for(let o of t)if(n===o)return o;let r=[];for(let o of t){if(r.length>=5){r.push(new s("..."));break}r.length>0&&r.push(new s(" | ")),r.push(new s(`"${o}"`,y))}throw new d(new c(new s("Invalid value: "),new s(`"${n}"`,y),new s(" (expected one of: "),...r,new s(")")))}}}function He(e,t=","){return{content:e.map(n=>n.content).join(t),decoder(n){let r=n.split(t,e.length);if(r.length!==e.length)throw new d(new c(new s(`Found ${r.length} splits: `),new s(`Expected ${e.length} splits from: `),new s(`"${n}"`,y)));return r.map((o,i)=>{let u=e[i];return d.tryWithContext(()=>u.decoder(o),()=>new c(new s(`at ${i}: `),new s(u.content,k)))})}}}function Qe(e,t=","){return{content:`${e.content}[${t}${e.content}]...`,decoder(n){return n.split(t).map((o,i)=>d.tryWithContext(()=>e.decoder(o),()=>new c(new s(`at ${i}: `),new s(e.content,k))))}}}function ze(e){let t=`<${H.content.toUpperCase()}>`;return{generateUsage(){return{short:e.short,long:e.long,label:void 0,annotation:"[=no]",description:e.description,hint:e.hint}},registerAndMakeDecoder(n){let r=`no-${e.long}`,o=e.aliases?.longs?.map(a=>`no-${a}`),i=Q(n,{long:r,short:void 0,aliasesShorts:void 0,aliasesLongs:o,parsing:{consumeShortGroup:!1,consumeNextArg:()=>!1}}),u=Q(n,{long:e.long,short:e.short,aliasesLongs:e.aliases?.longs,aliasesShorts:e.aliases?.shorts,parsing:{consumeShortGroup:!1,consumeNextArg:()=>!1}});return{getAndDecodeValue(){let a=n.getOptionValues(i),l=n.getOptionValues(u);if(l.length>1)throw new d(new c(new s(`--${e.long}`,w),new s(": Must not be set multiple times")));if(a.length>1)throw new d(new c(new s(`--${r}`,w),new s(": Must not be set multiple times")));if(a.length>0&&l.length>0)throw new d(new c(new s(`--${e.long}`,w),new s(": Must not be set in combination with: "),new s(`--${r}`,w)));if(a.length>0){if(a[0].inlined)throw new d(new c(new s(`--${r}`,w),new s(": Must not have a value")));return!1}if(l.length>0){let p=l[0];return re({long:e.long,short:e.short,label:t,type:H,input:p.inlined===null?"true":p.inlined})}return e.default??!1}}}}}function Je(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{short:e.short,long:e.long,label:t,annotation:void 0,description:e.description,hint:e.hint}},registerAndMakeDecoder(n){let r=Q(n,{long:e.long,short:e.short,aliasesLongs:e.aliases?.longs,aliasesShorts:e.aliases?.shorts,parsing:{consumeShortGroup:!0,consumeNextArg:(o,i)=>o===null&&i.length===0}});return{getAndDecodeValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new c(new s(`--${e.long}`,w),new s(": Requires a single value, but got multiple")));let i=o[0];if(i===void 0)try{return e.default()}catch(u){throw new d(new c(new s(`--${e.long}`,w),new s(": Failed to get default value")),u)}return re({long:e.long,short:e.short,label:t,type:e.type,input:i.inlined??i.separated[0]})}}}}}function Xe(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{short:e.short,long:e.long,label:t,annotation:" [*]",description:e.description,hint:e.hint}},registerAndMakeDecoder(n){let r=Q(n,{long:e.long,short:e.short,aliasesLongs:e.aliases?.longs,aliasesShorts:e.aliases?.shorts,parsing:{consumeShortGroup:!0,consumeNextArg:(o,i)=>o===null&&i.length===0}});return{getAndDecodeValue(){return n.getOptionValues(r).map(i=>re({long:e.long,short:e.short,label:t,type:e.type,input:i.inlined??i.separated[0]}))}}}}}function re(e){return d.tryWithContext(()=>e.type.decoder(e.input),()=>{let t=new c;return e.short&&(t.push(new s(`-${e.short}`,w)),t.push(new s(", "))),t.push(new s(`--${e.long}`,w)),t.push(new s(": ")),t.push(new s(e.label,R)),t.push(new s(": ")),t.push(new s(e.type.content,k)),t})}function Q(e,t){let{long:n,short:r,aliasesLongs:o,aliasesShorts:i,parsing:u}=t,a=n?[n]:[];o&&a.push(...o);let l=r?[r]:[];return i&&l.push(...i),e.registerOption({longs:a,shorts:l,parsing:u})}function Ze(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumeAndMakeDecoder(n){let r=n.consumePositional();if(r===void 0)throw new d(new c(new s(t,R),new s(": Is required, but was not provided")));return{decodeValue(){return se(t,e.type,r)}}}}}function _e(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumeAndMakeDecoder(n){let r=n.consumePositional();return{decodeValue(){if(r===void 0)try{return e.default()}catch(o){throw new d(new c(new s(t,R),new s(": Failed to get default value")),o)}return se(t,e.type,r)}}}}}function et(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:`${t}...`+(e.endDelimiter?` ["${e.endDelimiter}"]`:"")}},consumeAndMakeDecoder(n){let r=new Array;for(;;){let o=n.consumePositional();if(o===void 0||o===e.endDelimiter)break;r.push(o)}return{decodeValue(){return r.map(o=>se(t,e.type,o))}}}}}function se(e,t,n){return d.tryWithContext(()=>t.decoder(n),()=>new c(new s(e,R),new s(": "),new s(t.content,k)))}var G,M,I,v,O,N,h,z,de,ie,he,B,me,ae,j=class{constructor(t){b(this,h);b(this,G);b(this,M);b(this,I);b(this,v);b(this,O);b(this,N);f(this,G,t),f(this,M,0),f(this,I,!1),f(this,v,new Map),f(this,O,new Map),f(this,N,new Map)}registerOption(t){let n=[...t.longs.map(o=>`--${o}`),...t.shorts.map(o=>`-${o}`)].join(", ");for(let o of t.longs){if(!x(this,h,ae).call(this,o))throw new Error(`Invalid option name: --${o}`);if(g(this,v).has(o))throw new Error(`Option already registered: --${o}`)}for(let o of t.shorts){if(!x(this,h,ae).call(this,o))throw new Error(`Invalid option name: -${o}`);if(g(this,O).has(o))throw new Error(`Option already registered: -${o}`);for(let i=0;i<o.length;i++){let u=o.slice(0,i);if(g(this,O).has(u))throw new Error(`Option -${o} overlap with shorter option: -${u}`)}for(let i of g(this,O).keys())if(i.startsWith(o))throw new Error(`Option -${o} overlap with longer option: -${i}`)}let r={parsing:t.parsing,results:new Array};for(let o of t.longs)g(this,v).set(o,r);for(let o of t.shorts)g(this,O).set(o,r);return g(this,N).set(n,r),n}getOptionValues(t){let n=g(this,N).get(t);if(n===void 0)throw new Error(`Unregistered option: ${t}`);return n.results}consumePositional(){for(;;){let t=x(this,h,z).call(this);if(t===void 0)return;if(!x(this,h,de).call(this,t))return t}}};G=new WeakMap,M=new WeakMap,I=new WeakMap,v=new WeakMap,O=new WeakMap,N=new WeakMap,h=new WeakSet,z=function(){let t=g(this,G)[g(this,M)];if(t!==void 0)return ce(this,M)._++,!g(this,I)&&t==="--"?(f(this,I,!0),x(this,h,z).call(this)):t},de=function(t){if(g(this,I))return!1;if(t.startsWith("--")){let n=t.indexOf("=");return n===-1?x(this,h,ie).call(this,t.slice(2),null):x(this,h,ie).call(this,t.slice(2,n),t.slice(n+1)),!0}if(t.startsWith("-")){let n=1,r=2;for(;r<=t.length;){let o=t.slice(n,r),i=g(this,O).get(o);if(i!==void 0){let u=t.slice(r);if(x(this,h,he).call(this,i,o,u))return!0;n=r}r++}throw new d(new c(new s("Unexpected unknown option(s): "),new s(`-${t.slice(n)}`,y)))}return!1},ie=function(t,n){let r=`--${t}`,o=g(this,v).get(t);if(o!==void 0)return x(this,h,B).call(this,o,r,n);throw new d(new c(new s("Unexpected unknown option: "),new s(r,y)))},he=function(t,n,r){let o=`-${n}`;return r.startsWith("=")?(x(this,h,B).call(this,t,o,r.slice(1)),!0):r.length===0?(x(this,h,B).call(this,t,o,null),!0):t.parsing.consumeShortGroup?(x(this,h,B).call(this,t,o,r),!0):(x(this,h,B).call(this,t,o,null),!1)},B=function(t,n,r){let o=new Array;for(;t.parsing.consumeNextArg(r,o,g(this,G)[g(this,M)]);)o.push(x(this,h,me).call(this,n));t.results.push({inlined:r,separated:o})},me=function(t){let n=x(this,h,z).call(this);if(n===void 0)throw new d(new c(new s(t,w),new s(": Requires a value, but got end of input")));if(g(this,I))throw new d(new c(new s(t,w),new s(": Requires a value before "),new s('"--"',y)));if(n.startsWith("-"))throw new d(new c(new s(t,w),new s(": Requires a value, but got: "),new s(`"${n}"`,y)));return n},ae=function(t){return t.length>0&&!t.includes("=")};function ue(e){let{cliName:t,usage:n,typoSupport:r}=e,o=new Array,i=new c;i.push(tt("Usage:")),i.push(C(" ")),i.push(U(t));for(let a of n.segments)i.push(C(" ")),"positional"in a&&i.push(Y(a.positional)),"subcommand"in a&&i.push(U(a.subcommand));o.push(i.computeStyledString(r)),o.push("");let u=new c;u.push(nt(n.information.description)),n.information.hint&&(u.push(C(" ")),u.push(K(`(${n.information.hint})`))),o.push(u.computeStyledString(r));for(let a of n.information.details??[]){let l=new c;l.push(K(a)),o.push(l.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(J("Positionals:").computeStyledString(r));let a=new D;for(let l of n.positionals){let p=new Array;p.push(new c(C(" "))),p.push(new c(Y(l.label))),p.push(...pe(l)),a.pushRow(p)}o.push(...a.computeStyledLines(r))}if(n.subcommands.length>0){o.push(""),o.push(J("Subcommands:").computeStyledString(r));let a=new D;for(let l of n.subcommands){let p=new Array;p.push(new c(C(" "))),p.push(new c(U(l.name))),p.push(...pe(l)),a.pushRow(p)}o.push(...a.computeStyledLines(r))}if(n.options.length>0){o.push(""),o.push(J("Options:").computeStyledString(r));let a=new D;for(let l of n.options){let p=new Array;p.push(new c(C(" "))),l.short?p.push(new c(U(`-${l.short}`),C(", "))):p.push(new c);let m=new c(U(`--${l.long}`));l.label&&(m.push(C(" ")),m.push(Y(l.label))),l.annotation&&m.push(K(l.annotation)),p.push(m),p.push(...pe(l)),a.pushRow(p)}o.push(...a.computeStyledLines(r))}if(n.information.examples){o.push(""),o.push(J("Examples:").computeStyledString(r));for(let a of n.information.examples){let l=new c;l.push(C(" ")),l.push(K(`# ${a.explanation}`)),o.push(l.computeStyledString(r));let p=new c;p.push(C(" ")),p.push(U(t));for(let m of a.commandArgs)if(p.push(C(" ")),typeof m=="string")p.push(m);else if("positional"in m)p.push(Y(m.positional));else if("subcommand"in m)p.push(U(m.subcommand));else if("option"in m){let A=m.option;"short"in A?p.push(U(`-${A.short}`)):p.push(U(`--${A.long}`)),A.value!==void 0&&(p.push(K("=")),p.push(Y(A.value)))}o.push(p.computeStyledString(r))}}return o.push(""),o}function pe(e){let t=[];return e.description&&(t.push(C(" ")),t.push(ot(e.description))),e.hint&&(t.push(C(" ")),t.push(K(`(${e.hint})`))),t.length>0?[new c(C(" "),...t)]:[]}function tt(e){return new s(e,k)}function nt(e){return new s(e,ee)}function ot(e){return new s(e)}function J(e){return new s(e,_)}function K(e){return new s(e,te)}function U(e){return new s(e,w)}function Y(e){return new s(e,R)}function C(e){return new s(e)}async function rt(e,t,n,r,o){let i=new j(t),u=o?.usageOnHelp??!0;u&&i.registerOption({shorts:[],longs:["help"],parsing:{consumeShortGroup:!1,consumeNextArg:()=>!1}});let a=o?.buildVersion;a&&i.registerOption({shorts:[],longs:["version"],parsing:{consumeShortGroup:!1,consumeNextArg:()=>!1}});let l=r.consumeAndMakeDecoder(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}let p=st(o?.useTtyColors),m=o?.onExit??process.exit;if(u&&i.getOptionValues("--help").length>0)return console.log(we(e,l,p)),m(0);if(a&&i.getOptionValues("--version").length>0)return console.log([e,a].join(" ")),m(0);try{let A=l.decodeAndMakeInterpreter();try{return await A.executeWithContext(n),m(0)}catch(fe){return ye(o?.onError,fe,p),m(1)}}catch(A){return(o?.usageOnError??!0)&&console.error(we(e,l,p)),ye(o?.onError,A,p),m(1)}}function ye(e,t,n){e!==void 0?e(t):console.error(n.computeStyledErrorMessage(t))}function we(e,t,n){return ue({cliName:e,usage:t.generateUsage(),typoSupport:n}).join(`
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var _=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var he=n=>{throw TypeError(n)};var Ue=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},De=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Oe(e))!Ve.call(n,o)&&o!==t&&_(n,o,{get:()=>e[o],enumerable:!(r=ke(e,o))||r.enumerable});return n};var $e=n=>De(_({},"__esModule",{value:!0}),n);var ee=(n,e,t)=>e.has(n)||he("Cannot "+t);var c=(n,e,t)=>(ee(n,e,"read from private field"),t?t.call(n):e.get(n)),b=(n,e,t)=>e.has(n)?he("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),w=(n,e,t,r)=>(ee(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),x=(n,e,t)=>(ee(n,e,"access private method"),t);var me=(n,e,t,r)=>({set _(o){w(n,e,o,t)},get _(){return c(n,e,r)}});var dt={};Ue(dt,{ReaderArgs:()=>Q,TypoError:()=>g,TypoGrid:()=>E,TypoString:()=>i,TypoSupport:()=>O,TypoText:()=>d,command:()=>Ne,commandChained:()=>Ke,commandWithSubcommands:()=>Be,operation:()=>Fe,optionFlag:()=>J,optionRepeatable:()=>nt,optionSingleValue:()=>ae,positionalOptional:()=>rt,positionalRequired:()=>ot,positionalVariadics:()=>st,runAndExit:()=>lt,type:()=>Je,typeBoolean:()=>se,typeChoice:()=>ie,typeConverted:()=>Xe,typeDatetime:()=>qe,typeInteger:()=>He,typeList:()=>tt,typeNumber:()=>Qe,typePath:()=>_e,typeRenamed:()=>Ze,typeTuple:()=>et,typeUrl:()=>ze,typoStyleConstants:()=>R,typoStyleFailure:()=>ye,typoStyleLogic:()=>V,typoStyleQuote:()=>f,typoStyleRegularStrong:()=>ne,typoStyleRegularWeaker:()=>oe,typoStyleTitle:()=>te,typoStyleUserInput:()=>T,usageToStyledLines:()=>ge});module.exports=$e(dt);var te={fgColor:"darkGreen",bold:!0},V={fgColor:"darkMagenta",bold:!0},f={fgColor:"darkYellow",bold:!0},ye={fgColor:"darkRed",bold:!0},R={fgColor:"darkCyan",bold:!0},T={fgColor:"darkBlue",bold:!0},ne={bold:!0},oe={italic:!0,dim:!0},L,q,i=class{constructor(e,t={}){b(this,L);b(this,q);w(this,L,e),w(this,q,t)}computeStyledString(e){return e.computeStyledString(c(this,L),c(this,q))}getRawString(){return c(this,L)}};L=new WeakMap,q=new WeakMap;var A,re=class re{constructor(...e){b(this,A);w(this,A,[]);for(let t of e)this.push(t)}push(e){if(typeof e=="string")c(this,A).push(new i(e));else if(e instanceof re)c(this,A).push(...c(e,A));else if(Array.isArray(e))for(let t of e)c(this,A).push(t);else c(this,A).push(e)}computeStyledString(e){return c(this,A).map(t=>t.computeStyledString(e)).join("")}computeRawString(){return c(this,A).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let t of c(this,A))e+=t.getRawString().length;return e}};A=new WeakMap;var d=re,M,E=class{constructor(){b(this,M);w(this,M,[])}pushRow(e){c(this,M).push(e)}computeStyledLines(e){let t=new Array,r=new Array;for(let o of c(this,M))for(let s=0;s<o.length;s++){let a=o[s].computeRawLength();(t[s]===void 0||a>t[s])&&(t[s]=a)}for(let o of c(this,M)){let s=new Array;for(let u=0;u<o.length;u++){let a=o[u];if(s.push(a.computeStyledString(e)),u<o.length-1){let p=a.computeRawLength(),l=" ".repeat(t[u]-p);s.push(l)}}r.push(s.join(""))}return r}};M=new WeakMap;var G,H=class H extends Error{constructor(t,r){let o=new d;o.push(t),r instanceof H?(o.push(new i(": ")),o.push(c(r,G))):r instanceof Error?o.push(new i(`: ${r.message}`)):r!==void 0&&o.push(new i(`: ${String(r)}`));super(o.computeRawString());b(this,G);w(this,G,o)}computeStyledString(t){return c(this,G).computeStyledString(t)}static tryWithContext(t,r){try{return t()}catch(o){throw new H(r(),o)}}};G=new WeakMap;var g=H,I,k=class k{constructor(e){b(this,I);w(this,I,e)}static none(){return new k("none")}static tty(){return new k("tty")}static mock(){return new k("mock")}static inferFromEnv(){if(!process||!process.env)return k.none();function e(r){if(r in process.env)return process.env[r]}let t=e("FORCE_COLOR");return t==="0"||(t!==void 0&&k.tty(),e("NO_COLOR")!==void 0)?k.none():e("MOCK_COLOR")!==void 0?k.mock():k.tty()}computeStyledString(e,t){let r=e;if(t.case==="upper"&&(r=r.toUpperCase()),t.case==="lower"&&(r=r.toLowerCase()),c(this,I)==="none")return r;if(c(this,I)==="tty"){let o=t.fgColor?Le[t.fgColor]:"",s=t.bgColor?Ge[t.bgColor]:"",u=t.bold?Pe:"",a=t.dim?Me:"",p=t.italic?Ee:"",l=t.underline?ve:"",h=t.strikethrough?We:"";return`${o}${s}${u}${a}${p}${l}${h}${r}${Ie}`}if(c(this,I)==="mock"){let o=t.fgColor?`{${r}}@${t.fgColor}`:r,s=t.bgColor?`{${o}}#${t.bgColor}`:o,u=t.bold?`{${s}}+`:s,a=t.dim?`{${u}}-`:u,p=t.italic?`{${a}}*`:a,l=t.underline?`{${p}}_`:p;return t.strikethrough?`{${l}}~`:l}throw new Error(`Unknown TypoSupport kind: ${c(this,I)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",ye),e instanceof g?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};I=new WeakMap;var O=k,Ie="\x1B[0m",Pe="\x1B[1m",Me="\x1B[2m",Ee="\x1B[3m",ve="\x1B[4m",We="\x1B[9m",Le={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"},Ge={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 Ne(n,e){return{getInformation(){return n},consumeAndMakeDecoder(t){try{let r=e.consumeAndMakeDecoder(t),o=t.consumePositional();if(o!==void 0)throw new g(new d(new i("Unexpected argument: "),new i(`"${o}"`,f)));return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){let s=r.decodeAndMakeInterpreter();return{async executeWithContext(u){return await s.executeWithContext(u)}}}}}catch(r){return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){throw r}}}}}}function Be(n,e,t){return{getInformation(){return n},consumeAndMakeDecoder(r){try{let o=e.consumeAndMakeDecoder(r),s=r.consumePositional();if(s===void 0)throw new g(new d(new i("<subcommand>",T),new i(": Is required, but was not provided")));let u=t[s];if(u===void 0)throw new g(new d(new i("<subcommand>",T),new i(": Invalid value: "),new i(`"${s}"`,f)));let a=u.consumeAndMakeDecoder(r);return{generateUsage(){let p=a.generateUsage(),l=N(n,e);return l.segments.push({subcommand:s}),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=o.decodeAndMakeInterpreter(),l=a.decodeAndMakeInterpreter();return{async executeWithContext(h){return await l.executeWithContext(await p.executeWithContext(h))}}}}}catch(o){return{generateUsage(){let s=N(n,e);s.segments.push({positional:"<subcommand>"});for(let[u,a]of Object.entries(t)){let{description:p,hint:l}=a.getInformation();s.subcommands.push({name:u,description:p,hint:l})}return s},decodeAndMakeInterpreter(){throw o}}}}}}function Ke(n,e,t){return{getInformation(){return n},consumeAndMakeDecoder(r){try{let o=e.consumeAndMakeDecoder(r),s=t.consumeAndMakeDecoder(r);return{generateUsage(){let u=s.generateUsage(),a=N(n,e);return a.segments.push(...u.segments),a.information=u.information,a.positionals.push(...u.positionals),a.subcommands=u.subcommands,a.options.push(...u.options),a},decodeAndMakeInterpreter(){let u=o.decodeAndMakeInterpreter(),a=s.decodeAndMakeInterpreter();return{async executeWithContext(p){return await a.executeWithContext(await u.executeWithContext(p))}}}}}catch(o){return{generateUsage(){let s=N(n,e);return s.segments.push({positional:"[REST]..."}),s},decodeAndMakeInterpreter(){throw o}}}}}}function N(n,e){let{positionals:t,options:r}=e.generateUsage();return{segments:t.map(o=>({positional:o.label})),information:n,positionals:t,subcommands:[],options:r}}function Fe(n,e){return{generateUsage(){let t=new Array;for(let o in n.options){let s=n.options[o];t.push(s.generateUsage())}let r=new Array;for(let o of n.positionals)r.push(o.generateUsage());return{options:t,positionals:r}},consumeAndMakeDecoder(t){let r={};for(let s in n.options){let u=n.options[s];r[s]=u.registerAndMakeDecoder(t)}let o=[];for(let s of n.positionals)o.push(s.consumeAndMakeDecoder(t));return{decodeAndMakeInterpreter(){let s={};for(let a in r)s[a]=r[a].getAndDecodeValue();let u=[];for(let a of o)u.push(a.decodeValue());return{executeWithContext(a){return e(a,{options:s,positionals:u})}}}}}}}var fe=require("fs");function se(n){return{content:n??"boolean",decoder(e){let t=e.toLowerCase();if(je.has(t))return!0;if(Ye.has(t))return!1;throw new g(new d(new i("Not a boolean: "),new i(`"${e}"`,f)))}}}var je=new Set(["true","yes","on","1","y","t"]),Ye=new Set(["false","no","off","0","n","f"]);function qe(n){return{content:n??"datetime",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{throw new g(new d(new i("Not a valid ISO_8601 datetime: "),new i(`"${e}"`,f)))}}}}function Qe(n){return{content:n??"number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{throw new g(new d(new i("Not a number: "),new i(`"${e}"`,f)))}}}}function He(n){return{content:n??"integer",decoder(e){try{return BigInt(e)}catch{throw new g(new d(new i("Not an integer: "),new i(`"${e}"`,f)))}}}}function ze(n){return{content:n??"url",decoder(e){try{return new URL(e)}catch{throw new g(new d(new i("Not an URL: "),new i(`"${e}"`,f)))}}}}function Je(n){return{content:n??"string",decoder:e=>e}}function Xe(n,e,t){return{content:n,decoder:r=>t(g.tryWithContext(()=>e.decoder(r),()=>new d(new i("from: "),new i(e.content,V))))}}function Ze(n,e){return{content:e,decoder:t=>g.tryWithContext(()=>n.decoder(t),()=>new d(new i("from: "),new i(n.content,V)))}}function _e(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=(0,fe.statSync)(t),o=r.isDirectory()?"directory":r.isFile()?"file":"unknown";if(e.checkSyncExistAs==="file"&&!r.isFile())throw new g(new d(new i(`Expected a 'file' but found '${o}': `),new i(`"${t}"`,f)));if(e.checkSyncExistAs==="directory"&&!r.isDirectory())throw new g(new d(new i(`Expected a 'directory' but found '${o}': `),new i(`"${t}"`,f)))}return t}}}function ie(n,e,t=!1){let r=t?s=>s:s=>s.toLowerCase(),o=new Map(e.map(s=>[r(s),s]));return{content:n,decoder(s){let u=r(s),a=o.get(u);if(a!==void 0)return a;let p=[];for(let l of e){if(p.length>=5){p.push(new i("..."));break}p.length>0&&p.push(new i(" | ")),p.push(new i(`"${l}"`,f))}throw new g(new d(new i("Invalid value: "),new i(`"${s}"`,f),new i(" (expected one of: "),...p,new i(")")))}}}function et(n,e=","){return{content:n.map(t=>t.content).join(e),decoder(t){let r=t.split(e,n.length);if(r.length!==n.length)throw new g(new d(new i(`Found ${r.length} splits: `),new i(`Expected ${n.length} splits from: `),new i(`"${t}"`,f)));return r.map((o,s)=>{let u=n[s];return g.tryWithContext(()=>u.decoder(o),()=>new d(new i(`at ${s}: `),new i(u.content,V)))})}}}function tt(n,e=","){return{content:`${n.content}[${e}${n.content}]...`,decoder(t){return t.split(e).map((o,s)=>g.tryWithContext(()=>n.decoder(o),()=>new d(new i(`at ${s}: `),new i(n.content,V))))}}}function J(n){let e=se("value"),{long:t,short:r,description:o,hint:s,aliases:u}=n;return{generateUsage(){return{short:r,long:t,annotation:"[=no]",description:o,hint:s}},registerAndMakeDecoder(a){let p=ue(a,{long:t,short:r,aliasesLongs:u?.longs,aliasesShorts:u?.shorts,parsing:{consumeShortGroup:!1,consumeNextArg:()=>!1}});return{getAndDecodeValue(){let l=a.getOptionValues(p);if(l.length>1&&xe(t),l.length===0)return n.default===void 0?!1:n.default;let h=l[0],m=h.inlined===null?"true":h.inlined;return z({long:t,short:r,type:e,input:m})}}}}}function ae(n){let{long:e,short:t,description:r,hint:o,aliases:s,type:u}=n,a=`<${u.content}>`;return{generateUsage(){return{short:t,long:e,label:a,description:r,hint:o}},registerAndMakeDecoder(p){let l=ue(p,{long:e,short:t,aliasesLongs:s?.longs,aliasesShorts:s?.shorts,parsing:{consumeShortGroup:!0,consumeNextArg(h,m){return n.defaultWhenNotInlined!==void 0?!1:h===null&&m.length===0}}});return{getAndDecodeValue(){let h=p.getOptionValues(l);h.length>1&&xe(e);let m=h[0];if(m===void 0)try{return n.defaultWhenNotDefined()}catch($){we(e,$,"not set")}if(m.inlined){let $=m.inlined;return z({long:e,short:t,label:a,type:u,input:$})}if(n.defaultWhenNotInlined!==void 0)try{return n.defaultWhenNotInlined()}catch($){we(e,$,"not inlined")}let S=m.separated[0];return z({long:e,short:t,label:a,type:u,input:S})}}}}}function nt(n){let{long:e,short:t,description:r,hint:o,aliases:s,type:u}=n,a=`<${u.content}>`;return{generateUsage(){return{short:t,long:e,label:a,annotation:" [*]",description:r,hint:o}},registerAndMakeDecoder(p){let l=ue(p,{long:e,short:t,aliasesLongs:s?.longs,aliasesShorts:s?.shorts,parsing:{consumeShortGroup:!0,consumeNextArg:(h,m)=>h===null&&m.length===0}});return{getAndDecodeValue(){return p.getOptionValues(l).map(m=>{let S=m.inlined??m.separated[0];return z({long:e,short:t,label:a,type:u,input:S})})}}}}}function z(n){return g.tryWithContext(()=>n.type.decoder(n.input),()=>{let e=new d;return n.short&&(e.push(new i(`-${n.short}`,R)),e.push(new i(", "))),e.push(new i(`--${n.long}`,R)),n.label?(e.push(new i(": ")),e.push(new i(n.label,T))):(e.push(new i(": ")),e.push(new i(n.type.content,V))),e})}function ue(n,e){let{long:t,short:r,aliasesLongs:o,aliasesShorts:s,parsing:u}=e,a=t?[t]:[];o&&a.push(...o);let p=r?[r]:[];return s&&p.push(...s),n.registerOption({longs:a,shorts:p,parsing:u})}function xe(n){throw new g(new d(new i(`--${n}`,R),new i(": Must not be set multiple times")))}function we(n,e,t){throw new g(new d(new i(`--${n}`,R),new i(`: Failed to get default value (${t})`)),e)}function ot(n){let{description:e,hint:t,type:r}=n,o=`<${r.content}>`;return{generateUsage(){return{description:e,hint:t,label:o}},consumeAndMakeDecoder(s){let u=s.consumePositional();if(u===void 0)throw new g(new d(new i(o,T),new i(": Is required, but was not provided")));return{decodeValue(){return pe(o,n.type,u)}}}}}function rt(n){let{description:e,hint:t,type:r}=n,o=`[${r.content}]`;return{generateUsage(){return{description:e,hint:t,label:o}},consumeAndMakeDecoder(s){let u=s.consumePositional();return{decodeValue(){if(u===void 0)try{return n.default()}catch{it(o)}return pe(o,n.type,u)}}}}}function st(n){let{description:e,hint:t,type:r}=n,o=`[${r.content}]`,s=`${o}...`+(n.endDelimiter?` ["${n.endDelimiter}"]`:"");return{generateUsage(){return{description:e,hint:t,label:s}},consumeAndMakeDecoder(u){let a=new Array;for(;;){let p=u.consumePositional();if(p===void 0||p===n.endDelimiter)break;a.push(p)}return{decodeValue(){return a.map(p=>pe(o,n.type,p))}}}}}function pe(n,e,t){return g.tryWithContext(()=>e.decoder(t),()=>new d(new i(n,T)))}function it(n){throw new g(new d(new i(n,T),new i(": Failed to get default value")))}var K,v,P,W,U,F,y,X,be,le,Ce,B,Se,de,Q=class{constructor(e){b(this,y);b(this,K);b(this,v);b(this,P);b(this,W);b(this,U);b(this,F);w(this,K,e),w(this,v,0),w(this,P,!1),w(this,W,new Map),w(this,U,new Map),w(this,F,new Map)}registerOption(e){let t=[...e.longs.map(o=>`--${o}`),...e.shorts.map(o=>`-${o}`)].join(", ");for(let o of e.longs){if(!x(this,y,de).call(this,o))throw new Error(`Invalid option name: --${o}`);if(c(this,W).has(o))throw new Error(`Option already registered: --${o}`)}for(let o of e.shorts){if(!x(this,y,de).call(this,o))throw new Error(`Invalid option name: -${o}`);if(c(this,U).has(o))throw new Error(`Option already registered: -${o}`);for(let s=0;s<o.length;s++){let u=o.slice(0,s);if(c(this,U).has(u))throw new Error(`Option -${o} overlap with shorter option: -${u}`)}for(let s of c(this,U).keys())if(s.startsWith(o))throw new Error(`Option -${o} overlap with longer option: -${s}`)}let r={parsing:e.parsing,results:new Array};for(let o of e.longs)c(this,W).set(o,r);for(let o of e.shorts)c(this,U).set(o,r);return c(this,F).set(t,r),t}getOptionValues(e){let t=c(this,F).get(e);if(t===void 0)throw new Error(`Unregistered option: ${e}`);return t.results}consumePositional(){for(;;){let e=x(this,y,X).call(this);if(e===void 0)return;if(!x(this,y,be).call(this,e))return e}}};K=new WeakMap,v=new WeakMap,P=new WeakMap,W=new WeakMap,U=new WeakMap,F=new WeakMap,y=new WeakSet,X=function(){let e=c(this,K)[c(this,v)];if(e!==void 0)return me(this,v)._++,!c(this,P)&&e==="--"?(w(this,P,!0),x(this,y,X).call(this)):e},be=function(e){if(c(this,P))return!1;if(e.startsWith("--")){let t=e.indexOf("=");return t===-1?x(this,y,le).call(this,e.slice(2),null):x(this,y,le).call(this,e.slice(2,t),e.slice(t+1)),!0}if(e.startsWith("-")){let t=1,r=2;for(;r<=e.length;){let o=e.slice(t,r),s=c(this,U).get(o);if(s!==void 0){let u=e.slice(r);if(x(this,y,Ce).call(this,s,o,u))return!0;t=r}r++}throw new g(new d(new i("Unexpected unknown option(s): "),new i(`-${e.slice(t)}`,f)))}return!1},le=function(e,t){let r=`--${e}`,o=c(this,W).get(e);if(o!==void 0)return x(this,y,B).call(this,o,r,t);throw new g(new d(new i("Unexpected unknown option: "),new i(r,f)))},Ce=function(e,t,r){let o=`-${t}`;return r.startsWith("=")?(x(this,y,B).call(this,e,o,r.slice(1)),!0):r.length===0?(x(this,y,B).call(this,e,o,null),!0):e.parsing.consumeShortGroup?(x(this,y,B).call(this,e,o,r),!0):(x(this,y,B).call(this,e,o,null),!1)},B=function(e,t,r){let o=new Array;for(;e.parsing.consumeNextArg(r,o,c(this,K)[c(this,v)]);)o.push(x(this,y,Se).call(this,t));e.results.push({inlined:r,separated:o})},Se=function(e){let t=x(this,y,X).call(this);if(t===void 0)throw new g(new d(new i(e,R),new i(": Requires a value, but got end of input")));if(c(this,P))throw new g(new d(new i(e,R),new i(": Requires a value before "),new i('"--"',f)));if(t.startsWith("-"))throw new g(new d(new i(e,R),new i(": Requires a value, but got: "),new i(`"${t}"`,f)));return t},de=function(e){return e.length>0&&!e.includes("=")&&!e.includes("\0")};function ge(n){let{cliName:e,usage:t,typoSupport:r}=n,o=new Array,s=new d;s.push(at("Usage:")),s.push(C(" ")),s.push(D(e));for(let a of t.segments)s.push(C(" ")),"positional"in a&&s.push(j(a.positional)),"subcommand"in a&&s.push(D(a.subcommand));o.push(s.computeStyledString(r)),o.push("");let u=new d;u.push(ut(t.information.description)),t.information.hint&&(u.push(C(" ")),u.push(Y(`(${t.information.hint})`))),o.push(u.computeStyledString(r));for(let a of t.information.details??[]){let p=new d;p.push(Y(a)),o.push(p.computeStyledString(r))}if(t.positionals.length>0){o.push(""),o.push(Z("Positionals:").computeStyledString(r));let a=new E;for(let p of t.positionals){let l=new Array;l.push(new d(C(" "))),l.push(new d(j(p.label))),l.push(...ce(p)),a.pushRow(l)}o.push(...a.computeStyledLines(r))}if(t.subcommands.length>0){o.push(""),o.push(Z("Subcommands:").computeStyledString(r));let a=new E;for(let p of t.subcommands){let l=new Array;l.push(new d(C(" "))),l.push(new d(D(p.name))),l.push(...ce(p)),a.pushRow(l)}o.push(...a.computeStyledLines(r))}if(t.options.length>0){o.push(""),o.push(Z("Options:").computeStyledString(r));let a=new E;for(let p of t.options){let l=new Array;l.push(new d(C(" "))),p.short?l.push(new d(D(`-${p.short}`),C(", "))):l.push(new d);let h=new d(D(`--${p.long}`));p.label&&(h.push(C(" ")),h.push(j(p.label))),p.annotation&&h.push(Y(p.annotation)),l.push(h),l.push(...ce(p)),a.pushRow(l)}o.push(...a.computeStyledLines(r))}if(t.information.examples){o.push(""),o.push(Z("Examples:").computeStyledString(r));for(let a of t.information.examples){let p=new d;p.push(C(" ")),p.push(Y(`# ${a.explanation}`)),o.push(p.computeStyledString(r));let l=new d;l.push(C(" ")),l.push(D(e));for(let h of a.commandArgs)if(l.push(C(" ")),typeof h=="string")l.push(h);else if("positional"in h)l.push(j(h.positional));else if("subcommand"in h)l.push(D(h.subcommand));else if("option"in h){let m=h.option;if("short"in m?l.push(D(`-${m.short}`)):l.push(D(`--${m.long}`)),m.inlined!==void 0&&(l.push(Y("=")),l.push(j(m.inlined))),m.separated!==void 0)for(let S of m.separated)l.push(C(" ")),l.push(j(S))}o.push(l.computeStyledString(r))}}return o.push(""),o}function ce(n){let e=[];return n.description&&(e.push(C(" ")),e.push(pt(n.description))),n.hint&&(e.push(C(" ")),e.push(Y(`(${n.hint})`))),e.length>0?[new d(C(" "),...e)]:[]}function at(n){return new i(n,V)}function ut(n){return new i(n,ne)}function pt(n){return new i(n)}function Z(n){return new i(n,te)}function Y(n){return new i(n,oe)}function D(n){return new i(n,R)}function j(n){return new i(n,T)}function C(n){return new i(n)}async function lt(n,e,t,r,o){let s=new Q(e),u=new Array,a=O.none(),p=o?.colorSetup??"flag";if(p==="flag"){let m=ae({long:"color",type:ie("color-mode",["auto","always","never","mock"]),defaultWhenNotDefined:()=>"auto",defaultWhenNotInlined:()=>"always"}).registerAndMakeDecoder(s);u.push(()=>{try{a=Te(m.getAndDecodeValue())}catch(S){throw a=O.inferFromEnv(),S}})}else p==="env"?a=O.inferFromEnv():a=Te(p);if(o?.usageOnHelp??!0){let m=J({long:"help"}).registerAndMakeDecoder(s);u.push(S=>{if(m.getAndDecodeValue())return console.log(Re(n,S,a)),0})}if(o?.buildVersion){let m=J({long:"version"}).registerAndMakeDecoder(s);u.push(()=>{if(m.getAndDecodeValue())return console.log([n,o.buildVersion].join(" ")),0})}let l=r.consumeAndMakeDecoder(s);for(;;)try{if(s.consumePositional()===void 0)break}catch{}let h=o?.onExit??process.exit;try{for(let S of u){let $=S(l);if($!==void 0)return h($)}let m=l.decodeAndMakeInterpreter();try{return await m.executeWithContext(t),h(0)}catch(S){return Ae(o?.onError,S,a),h(1)}}catch(m){return(o?.usageOnError??!0)&&console.error(Re(n,l,a)),Ae(o?.onError,m,a),h(1)}}function Ae(n,e,t){n!==void 0?n(e):console.error(t.computeStyledErrorMessage(e))}function Re(n,e,t){return ge({cliName:n,usage:e.generateUsage(),typoSupport:t}).join(`
|
|
2
|
+
`)}function Te(n){switch(n){case"auto":return O.inferFromEnv();case"always":return O.tty();case"never":return O.none();case"mock":return O.mock()}}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,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
|