cli-kiss 0.2.3 → 0.2.4
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/README.md +1 -1
- package/dist/index.d.ts +643 -667
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +1 -3
- package/docs/.vitepress/theme/index.ts +4 -0
- package/docs/.vitepress/theme/style.css +4 -0
- package/docs/guide/02_commands.md +67 -31
- package/docs/guide/03_options.md +11 -10
- package/docs/guide/05_types.md +1 -1
- package/docs/guide/06_run.md +1 -1
- package/docs/index.md +8 -3
- package/docs/public/hero.png +0 -0
- package/package.json +1 -1
- package/src/lib/Command.ts +36 -93
- package/src/lib/Operation.ts +12 -30
- package/src/lib/Option.ts +120 -96
- package/src/lib/Positional.ts +9 -34
- package/src/lib/Reader.ts +122 -98
- package/src/lib/Run.ts +30 -17
- package/src/lib/Type.ts +26 -22
- package/src/lib/Typo.ts +62 -83
- package/src/lib/Usage.ts +174 -78
- package/tests/unit.Reader.aliases.ts +31 -15
- package/tests/unit.Reader.commons.ts +99 -43
- package/tests/unit.Reader.shortBig.ts +75 -31
- package/tests/unit.command.execute.ts +76 -33
- package/tests/unit.command.usage.ts +35 -35
- package/tests/unit.runner.cycle.ts +13 -13
- package/tests/unit.runner.errors.ts +19 -3
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var de=t=>{throw TypeError(t)};var Te=(t,e)=>{for(var n in e)X(t,n,{get:e[n],enumerable:!0})},ke=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Se(e))!Ce.call(t,r)&&r!==n&&X(t,r,{get:()=>e[r],enumerable:!(o=be(e,r))||o.enumerable});return t};var Ae=t=>ke(X({},"__esModule",{value:!0}),t);var Z=(t,e,n)=>e.has(t)||de("Cannot "+n);var d=(t,e,n)=>(Z(t,e,"read from private field"),n?n.call(t):e.get(t)),f=(t,e,n)=>e.has(t)?de("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),w=(t,e,n,o)=>(Z(t,e,"write to private field"),o?o.call(t,n):e.set(t,n),n),m=(t,e,n)=>(Z(t,e,"access private method"),n);var ge=(t,e,n,o)=>({set _(r){w(t,e,r,n)},get _(){return d(t,e,o)}});var rt={};Te(rt,{ReaderArgs:()=>F,TypoError:()=>g,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>$,TypoText:()=>u,command:()=>Pe,commandChained:()=>Ee,commandWithSubcommands:()=>ve,operation:()=>We,optionFlag:()=>Qe,optionRepeatable:()=>ze,optionSingleValue:()=>Je,positionalOptional:()=>Ze,positionalRequired:()=>Xe,positionalVariadics:()=>_e,runAndExit:()=>ot,typeBoolean:()=>Q,typeDate:()=>Be,typeInteger:()=>Ke,typeList:()=>He,typeMapped:()=>Fe,typeNumber:()=>Ge,typeOneOf:()=>Ye,typeString:()=>je,typeTuple:()=>qe,typeUrl:()=>Ne,typoStyleConstants:()=>b,typoStyleFailure:()=>he,typoStyleLogic:()=>R,typoStyleQuote:()=>x,typoStyleRegularStrong:()=>ee,typoStyleRegularWeaker:()=>te,typoStyleTitle:()=>_,typoStyleUserInput:()=>S,usageToStyledLines:()=>ce});module.exports=Ae(rt);var _={fgColor:"darkGreen",bold:!0},R={fgColor:"darkMagenta",bold:!0},x={fgColor:"darkYellow",bold:!0},he={fgColor:"darkRed",bold:!0},b={fgColor:"darkCyan",bold:!0},S={fgColor:"darkBlue",bold:!0},ee={bold:!0},te={italic:!0,dim:!0},L,j,s=class{constructor(e,n={}){f(this,L);f(this,j);w(this,L,e),w(this,j,n)}getRawString(){return d(this,L)}computeStyledString(e){return e.computeStyledString(d(this,L),d(this,j))}};L=new WeakMap,j=new WeakMap;var A,ne=class ne{constructor(...e){f(this,A);w(this,A,[]);for(let n of e)n instanceof ne?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(e){typeof e=="string"?d(this,A).push(new s(e)):d(this,A).push(e)}pushText(e){if(typeof e=="string")this.pushString(e);else for(let n of d(e,A))d(this,A).push(n)}computeStyledString(e){return d(this,A).map(n=>n.computeStyledString(e)).join("")}computeRawString(){return d(this,A).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let n of d(this,A))e+=n.getRawString().length;return e}};A=new WeakMap;var u=ne,M,P=class{constructor(){f(this,M);w(this,M,[])}pushRow(e){d(this,M).push(e)}computeStyledGrid(e){let n=new Array,o=new Array;for(let r of d(this,M))for(let i=0;i<r.length;i++){let a=r[i].computeRawLength();(n[i]===void 0||a>n[i])&&(n[i]=a)}for(let r of d(this,M)){let i=new Array;for(let l=0;l<r.length;l++){let a=r[l],c=a.computeStyledString(e);if(i.push(c),l<r.length-1){let p=a.computeRawLength(),y=" ".repeat(n[l]-p);i.push(y)}}o.push(i)}return o}};M=new WeakMap;var W,H=class H extends Error{constructor(n,o){let r=new u;r.pushText(n),o instanceof H?(r.pushString(new s(": ")),r.pushText(d(o,W))):o instanceof Error?r.pushString(new s(`: ${o.message}`)):o!==void 0&&r.pushString(new s(`: ${String(o)}`));super(r.computeRawString());f(this,W);w(this,W,r)}computeStyledString(n){return d(this,W).computeStyledString(n)}static tryWithContext(n,o){try{return n()}catch(r){throw new H(o(),r)}}};W=new WeakMap;var g=H,V,k=class k{constructor(e){f(this,V);w(this,V,e)}static none(){return new k("none")}static tty(){return new k("tty")}static mock(){return new k("mock")}static inferFromProcess(){if(!process)return k.none();if(process.env){if(process.env.FORCE_COLOR==="0")return k.none();if(process.env.FORCE_COLOR)return k.tty();if("NO_COLOR"in process.env)return k.none()}return process.stdout&&process.stdout.isTTY?k.tty():k.none()}computeStyledString(e,n){if(d(this,V)==="none")return e;if(d(this,V)==="tty"){let o=n.fgColor?De[n.fgColor]:"",r=n.bgColor?Me[n.bgColor]:"",i=n.bold?Ue:"",l=n.dim?Oe:"",a=n.italic?Ve:"",c=n.underline?$e:"",p=n.strikethrough?Ie:"";return`${o}${r}${i}${l}${a}${c}${p}${e}${Re}`}if(d(this,V)==="mock"){let o=n.fgColor?`{${e}}@${n.fgColor}`:e,r=n.bgColor?`{${o}}#${n.bgColor}`:o,i=n.bold?`{${r}}+`:r,l=n.dim?`{${i}}-`:i,a=n.italic?`{${l}}*`:l,c=n.underline?`{${a}}_`:a;return n.strikethrough?`{${c}}~`:c}throw new Error(`Unknown TypoSupport kind: ${d(this,V)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",he),e instanceof g?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};V=new WeakMap;var $=k,Re="\x1B[0m",Ue="\x1B[1m",Oe="\x1B[2m",Ve="\x1B[3m",$e="\x1B[4m",Ie="\x1B[9m",De={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"},Me={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 Pe(t,e){return{getInformation(){return t},consumeAndMakeDecoder(n){try{let o=e.consumeAndMakeDecoder(n),r=n.consumePositional();if(r!==void 0)throw new g(new u(new s("Unexpected argument: "),new s(`"${r}"`,x)));return{generateUsage:()=>B(t,e),decodeAndMakeInterpreter(){let i=o.decodeAndMakeInterpreter();return{async executeWithContext(l){return await i.executeWithContext(l)}}}}}catch(o){return{generateUsage:()=>B(t,e),decodeAndMakeInterpreter(){throw o}}}}}}function ve(t,e,n){return{getInformation(){return t},consumeAndMakeDecoder(o){try{let r=e.consumeAndMakeDecoder(o),i=o.consumePositional();if(i===void 0)throw new g(new u(new s("<SUBCOMMAND>",S),new s(": Is required, but was not provided")));let l=n[i];if(l===void 0)throw new g(new u(new s("<SUBCOMMAND>",S),new s(": Invalid value: "),new s(`"${i}"`,x)));let a=l.consumeAndMakeDecoder(o);return{generateUsage(){let c=a.generateUsage(),p=B(t,e);return p.segments.push(Le(i)),p.segments.push(...c.segments),p.information=c.information,p.positionals.push(...c.positionals),p.subcommands=c.subcommands,p.options.push(...c.options),p},decodeAndMakeInterpreter(){let c=r.decodeAndMakeInterpreter(),p=a.decodeAndMakeInterpreter();return{async executeWithContext(y){return await p.executeWithContext(await c.executeWithContext(y))}}}}}catch(r){return{generateUsage(){let i=B(t,e);i.segments.push(oe("<SUBCOMMAND>"));for(let[l,a]of Object.entries(n)){let{description:c,hint:p}=a.getInformation();i.subcommands.push({name:l,description:c,hint:p})}return i},decodeAndMakeInterpreter(){throw r}}}}}}function Ee(t,e,n){return{getInformation(){return t},consumeAndMakeDecoder(o){try{let r=e.consumeAndMakeDecoder(o),i=n.consumeAndMakeDecoder(o);return{generateUsage(){let l=i.generateUsage(),a=B(t,e);return a.segments.push(...l.segments),a.information=l.information,a.positionals.push(...l.positionals),a.subcommands=l.subcommands,a.options.push(...l.options),a},decodeAndMakeInterpreter(){let l=r.decodeAndMakeInterpreter(),a=i.decodeAndMakeInterpreter();return{async executeWithContext(c){return await a.executeWithContext(await l.executeWithContext(c))}}}}}catch(r){return{generateUsage(){let i=B(t,e);return i.segments.push(oe("[REST]...")),i},decodeAndMakeInterpreter(){throw r}}}}}}function oe(t){return{positional:t}}function Le(t){return{command:t}}function B(t,e){let{positionals:n,options:o}=e.generateUsage();return{segments:n.map(r=>oe(r.label)),information:t,positionals:n,subcommands:[],options:o}}function We(t,e){return{generateUsage(){let n=new Array;for(let r in t.options){let i=t.options[r];i&&n.push(i.generateUsage())}let o=new Array;for(let r of t.positionals)o.push(r.generateUsage());return{options:n,positionals:o}},consumeAndMakeDecoder(n){let o={};for(let i in t.options){let l=t.options[i];o[i]=l.registerAndMakeDecoder(n)}let r=[];for(let i of t.positionals)r.push(i.consumeAndMakeDecoder(n));return{decodeAndMakeInterpreter(){let i={};for(let a in o)i[a]=o[a].getAndDecodeValue();let l=[];for(let a of r)l.push(a.decodeValue());return{executeWithContext(a){return e(a,{options:i,positionals:l})}}}}}}}var Q={content:"Boolean",decoder(t){let e=t.toLowerCase();if(e==="true"||e==="yes")return!0;if(e==="false"||e==="no")return!1;throw new g(new u(new s("Invalid value: "),new s(`"${t}"`,x)))}},Be={content:"Date",decoder(t){try{let e=Date.parse(t);if(isNaN(e))throw new Error;return new Date(e)}catch{throw new g(new u(new s("Not a valid ISO_8601: "),new s(`"${t}"`,x)))}}},Ge={content:"Number",decoder(t){try{let e=Number(t);if(isNaN(e))throw new Error;return e}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${t}"`,x)))}}},Ke={content:"Integer",decoder(t){try{return BigInt(t)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${t}"`,x)))}}},Ne={content:"Url",decoder(t){try{return new URL(t)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${t}"`,x)))}}},je={content:"String",decoder(t){return t}};function Fe(t,e){return{content:e.content,decoder:n=>e.decoder(g.tryWithContext(()=>t.decoder(n),()=>new u(new s("from: "),new s(t.content,R))))}}function Ye(t,e){return{content:t,decoder(n){for(let r of e)if(n===r)return r;let o=[];for(let r of e){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${r}"`,x))}throw new g(new u(new s("Invalid value: "),new s(`"${n}"`,x),new s(" (expected one of: "),...o,new s(")")))}}}function qe(t,e=","){return{content:t.map(n=>n.content).join(e),decoder(n){let o=n.split(e,t.length);if(o.length!==t.length)throw new g(new u(new s(`Found ${o.length} splits: `),new s(`Expected ${t.length} splits from: `),new s(`"${n}"`,x)));return o.map((r,i)=>{let l=t[i];return g.tryWithContext(()=>l.decoder(r),()=>new u(new s(`at ${i}: `),new s(l.content,R)))})}}}function He(t,e=","){return{content:`${t.content}[${e}${t.content}]...`,decoder(n){return n.split(e).map((r,i)=>g.tryWithContext(()=>t.decoder(r),()=>new u(new s(`at ${i}: `),new s(t.content,R))))}}}function Qe(t){let e=`<${Q.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:void 0}},registerAndMakeDecoder(n){let o=se(n,{...t,valued:!1});return{getAndDecodeValue(){let r=n.getOptionValues(o);if(r.length>1)throw new g(new u(new s(`--${t.long}`,b),new s(": Must not be set multiple times")));let i=r[0];if(i===void 0)try{return t.default?t.default():!1}catch(l){throw new g(new u(new s(`--${t.long}`,b),new s(": Failed to get default value")),l)}return re({long:t.long,short:t.short,label:e,type:Q,input:i})}}}}}function Je(t){let e=`<${t.label??t.type.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},registerAndMakeDecoder(n){let o=se(n,{...t,valued:!0});return{getAndDecodeValue(){let r=n.getOptionValues(o);if(r.length>1)throw new g(new u(new s(`--${t.long}`,b),new s(": Requires a single value, but got multiple")));let i=r[0];if(i===void 0)try{return t.default()}catch(l){throw new g(new u(new s(`--${t.long}`,b),new s(": Failed to get default value")),l)}return re({long:t.long,short:t.short,label:e,type:t.type,input:i})}}}}}function ze(t){let e=`<${t.label??t.type.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},registerAndMakeDecoder(n){let o=se(n,{...t,valued:!0});return{getAndDecodeValue(){return n.getOptionValues(o).map(i=>re({long:t.long,short:t.short,label:e,type:t.type,input:i}))}}}}}function re(t){return g.tryWithContext(()=>t.type.decoder(t.input),()=>{let e=new u;return t.short&&(e.pushString(new s(`-${t.short}`,b)),e.pushString(new s(", "))),e.pushString(new s(`--${t.long}`,b)),e.pushString(new s(": ")),e.pushString(new s(t.label,S)),e.pushString(new s(": ")),e.pushString(new s(t.type.content,R)),e})}function se(t,e){let{long:n,short:o,aliases:r,valued:i}=e,l=n?[n]:[];r?.longs&&l.push(...r?.longs);let a=o?[o]:[];return r?.shorts&&a.push(...r?.shorts),t.registerOption({longs:l,shorts:a,valued:i})}function Xe(t){let e=`<${t.label??t.type.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumeAndMakeDecoder(n){let o=n.consumePositional();if(o===void 0)throw new g(new u(new s(e,S),new s(": Is required, but was not provided")));return{decodeValue(){return ie(e,t.type,o)}}}}}function Ze(t){let e=`[${t.label??t.type.content.toUpperCase()}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumeAndMakeDecoder(n){let o=n.consumePositional();return{decodeValue(){if(o===void 0)try{return t.default()}catch(r){throw new g(new u(new s(e,S),new s(": Failed to get default value")),r)}return ie(e,t.type,o)}}}}}function _e(t){let e=`[${t.label??t.type.content.toUpperCase()}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:`${e}...`+(t.endDelimiter?`["${t.endDelimiter}"]`:"")}},consumeAndMakeDecoder(n){let o=new Array;for(;;){let r=n.consumePositional();if(r===void 0||r===t.endDelimiter)break;o.push(r)}return{decodeValue(){return o.map(r=>ie(e,t.type,r))}}}}}function ie(t,e,n){return g.tryWithContext(()=>e.decoder(n),()=>new u(new s(t,S),new s(": "),new s(e.content,R)))}var Y,G,D,v,O,E,K,h,J,me,ae,ye,pe,I,ue,F=class{constructor(e){f(this,h);f(this,Y);f(this,G);f(this,D);f(this,v);f(this,O);f(this,E);f(this,K);w(this,Y,e),w(this,G,0),w(this,D,!1),w(this,v,new Map),w(this,O,new Map),w(this,E,new Map),w(this,K,new Map)}registerOption(e){let n=[...e.longs.map(o=>`--${o}`),...e.shorts.map(o=>`-${o}`)].join(", ");for(let o of e.longs){if(!m(this,h,ue).call(this,o))throw new Error(`Invalid option name: --${o}`);if(d(this,v).has(o))throw new Error(`Option already registered: --${o}`)}for(let o of e.shorts){if(!m(this,h,ue).call(this,o))throw new Error(`Invalid option name: -${o}`);if(d(this,O).has(o))throw new Error(`Option already registered: -${o}`);for(let r=0;r<o.length;r++){let i=o.slice(0,r);if(d(this,O).has(i))throw new Error(`Option -${o} overlap with shorter option: -${i}`)}for(let r of d(this,O).keys())if(r.startsWith(o))throw new Error(`Option -${o} overlap with longer option: -${r}`)}for(let o of e.longs)d(this,v).set(o,n);for(let o of e.shorts)d(this,O).set(o,n);return d(this,E).set(n,e.valued),d(this,K).set(n,new Array),n}getOptionValues(e){let n=d(this,K).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=m(this,h,J).call(this);if(e===null)return;if(m(this,h,me).call(this,e))return e}}};Y=new WeakMap,G=new WeakMap,D=new WeakMap,v=new WeakMap,O=new WeakMap,E=new WeakMap,K=new WeakMap,h=new WeakSet,J=function(){let e=d(this,Y)[d(this,G)];return e===void 0?null:(ge(this,G)._++,!d(this,D)&&e==="--"?(w(this,D,!0),m(this,h,J).call(this)):e)},me=function(e){if(d(this,D))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?m(this,h,ae).call(this,e.slice(2),null):m(this,h,ae).call(this,e.slice(2,n),e.slice(n+1)),!1}if(e.startsWith("-")){let n=1,o=2;for(;o<=e.length;){let r=m(this,h,ye).call(this,e.slice(n,o),e.slice(o));if(r===!0)return!1;r===!1&&(n=o),o++}throw new g(new u(new s(`-${e.slice(n)}`,b),new s(": Unexpected unknown option")))}return!0},ae=function(e,n){let o=`--${e}`,r=d(this,v).get(e);if(r!==void 0)return n!==null?m(this,h,I).call(this,r,n):d(this,E).get(r)?m(this,h,I).call(this,r,m(this,h,pe).call(this,o)):m(this,h,I).call(this,r,"true");throw new g(new u(new s(o,b),new s(": Unexpected unknown option")))},ye=function(e,n){let o=d(this,O).get(e);return o!==void 0?n.startsWith("=")?(m(this,h,I).call(this,o,n.slice(1)),!0):d(this,E).get(o)?(n===""?m(this,h,I).call(this,o,m(this,h,pe).call(this,`-${e}`)):m(this,h,I).call(this,o,n),!0):(m(this,h,I).call(this,o,"true"),n===""):null},pe=function(e){let n=m(this,h,J).call(this);if(n===null)throw new g(new u(new s(e,b),new s(": Requires a value, but got end of input")));if(d(this,D))throw new g(new u(new s(e,b),new s(": Requires a value before "),new s('"--"',x)));if(n.startsWith("-"))throw new g(new u(new s(e,b),new s(": Requires a value, but got: "),new s(`"${n}"`,x)));return n},I=function(e,n){this.getOptionValues(e).push(n)},ue=function(e){return e.length>0&&!e.includes("=")};function ce(t){let{cliName:e,commandUsage:n,typoSupport:o}=t,r=new Array,i=[et("Usage:").computeStyledString(o),U(e).computeStyledString(o)].concat(n.segments.map(a=>{if("positional"in a)return q(a.positional).computeStyledString(o);if("command"in a)return U(a.command).computeStyledString(o);throw new Error(`Unknown segment: ${JSON.stringify(a)}`)}));r.push(i.join(" ")),r.push("");let l=new u;l.pushString(tt(n.information.description)),n.information.hint&&(l.pushString(C(" ")),l.pushString(N(`(${n.information.hint})`))),r.push(l.computeStyledString(o));for(let a of n.information.details??[]){let c=new u;c.pushString(N(a)),r.push(c.computeStyledString(o))}if(n.positionals.length>0){r.push(""),r.push(z("Positionals:").computeStyledString(o));let a=new P;for(let c of n.positionals){let p=new Array;p.push(new u(C(" "))),p.push(new u(q(c.label))),p.push(...le(c)),a.pushRow(p)}r.push(...a.computeStyledGrid(o).map(c=>c.join("")))}if(n.subcommands.length>0){r.push(""),r.push(z("Subcommands:").computeStyledString(o));let a=new P;for(let c of n.subcommands){let p=new Array;p.push(new u(C(" "))),p.push(new u(U(c.name))),p.push(...le(c)),a.pushRow(p)}r.push(...a.computeStyledGrid(o).map(c=>c.join("")))}if(n.options.length>0){r.push(""),r.push(z("Options:").computeStyledString(o));let a=new P;for(let c of n.options){let p=new Array;p.push(new u(C(" "))),c.short?p.push(new u(U(`-${c.short}`),C(", "))):p.push(new u),c.label?p.push(new u(U(`--${c.long}`),C(" "),q(c.label))):p.push(new u(U(`--${c.long}`),N("[=no]"))),p.push(...le(c)),a.pushRow(p)}r.push(...a.computeStyledGrid(o).map(c=>c.join("")))}if(n.information.examples){r.push(""),r.push(z("Examples:").computeStyledString(o));for(let a of n.information.examples){let c=new u;c.pushString(C(" ")),c.pushString(N(`# ${a.explanation}`)),r.push(c.computeStyledString(o));let p=new u;p.pushString(C(" ")),p.pushString(U(e));for(let y of a.commandArgs)if(p.pushString(C(" ")),typeof y=="string")p.pushString(y);else if("positional"in y)p.pushString(q(y.positional));else if("subcommand"in y)p.pushString(U(y.subcommand));else if("option"in y){let T=y.option;"short"in T?p.pushString(U(`-${T.short}`)):p.pushString(U(`--${T.long}`)),T.value!==void 0&&(p.pushString(N("=")),p.pushString(q(T.value)))}r.push(p.computeStyledString(o))}}return r.push(""),r}function le(t){let e=[];return t.description&&(e.push(C(" ")),e.push(nt(t.description))),t.hint&&(e.push(C(" ")),e.push(N(`(${t.hint})`))),e.length>0?[new u(C(" "),...e)]:[]}function et(t){return new s(t,R)}function tt(t){return new s(t,ee)}function nt(t){return new s(t)}function z(t){return new s(t,_)}function N(t){return new s(t,te)}function U(t){return new s(t,b)}function q(t){return new s(t,S)}function C(t){return new s(t)}async function ot(t,e,n,o,r){let i=new F(e),l=r?.usageOnHelp??!0;l&&i.registerOption({shorts:[],longs:["help"],valued:!1});let a=r?.buildVersion;a&&i.registerOption({shorts:[],longs:["version"],valued:!1});let c=o.consumeAndMakeDecoder(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}let p=r?.onExit??process.exit,y=r?.useTtyColors===void 0?$.inferFromProcess():r.useTtyColors==="mock"?$.mock():r.useTtyColors?$.tty():$.none();if(l&&i.getOptionValues("--help").length>0)return console.log(fe(t,c,y)),p(0);if(a&&i.getOptionValues("--version").length>0)return console.log([t,a].join(" ")),p(0);try{let T=c.decodeAndMakeInterpreter();try{return await T.executeWithContext(n),p(0)}catch(xe){return we(r?.onError,xe,y),p(1)}}catch(T){return(r?.usageOnError??!0)&&console.error(fe(t,c,y)),we(r?.onError,T,y),p(1)}}function we(t,e,n){t!==void 0?t(e):console.error(n.computeStyledErrorMessage(e))}function fe(t,e,n){return ce({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
|
|
2
|
-
`)}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,typeBoolean,typeDate,typeInteger,typeList,typeMapped,typeNumber,typeOneOf,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
|
|
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 st(e){return e===void 0?$.inferFromProcess():e==="mock"?$.mock():e?$.tty():$.none()}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,typeBoolean,typeDate,typeInteger,typeList,typeMapped,typeNumber,typeOneOf,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|