@politty/valibot 0.7.2 → 0.7.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/dist/docs.js CHANGED
@@ -1,10 +1,10 @@
1
- import{h as e,l as t}from"./unflatten-DVeO9OZ_.js";import"./register-ZdhcM-o7.js";import{c as n,n as r,o as i,r as a,s as o,t as s}from"./schema-extractor-Cwg_WAC-.js";import{r as c}from"./subcommand-router-40vA6Mka.js";import{t as l}from"./log-collector-uhRWYT-z.js";import*as u from"node:fs";import d,*as f from"node:path";import{isDeepStrictEqual as p}from"node:util";const m=[`option`,`alias`,`description`,`required`,`default`];function h(e){return`(↔ \`--${e.cliName}\`)`}function g(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function _(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${g(e)}>`}function v(e){let t=_(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:h(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function y(e){return e.map(v)}function b(e){return e.replace(/\r?\n/g,`<br>`)}function x(e){return b(e.replace(/\|/g,`\\|`))}function S(e){return`\`${e}\``}function C(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function ee(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function E(e,t){switch(t){case`option`:{let t=S(e.longFlag);return e.inlineNegation?`${t} / ${S(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(S).join(`, `):`-`;case`description`:return x(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return C(e);case`env`:return ee(e.env)}}function D(e,t){switch(t){case`option`:return S(e.flag);case`description`:return`${x(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function O(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...m,`env`]:m),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>E(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>D(t.negationRow,e)).join(` | `)} |`);return r.join(`
1
+ import"./register-ZdhcM-o7.js";import{c as e,n as t,o as n,r,s as i,t as a}from"./schema-extractor-Cwg_WAC-.js";import{t as o}from"./log-collector-uhRWYT-z.js";import{h as s,l as c}from"./unflatten-DVeO9OZ_.js";import{r as l}from"./subcommand-router-CfCW9eG4.js";import*as u from"node:fs";import d,*as f from"node:path";import{isDeepStrictEqual as p}from"node:util";const m=[`option`,`alias`,`description`,`required`,`default`];function h(e){return`(↔ \`--${e.cliName}\`)`}function g(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function _(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${g(e)}>`}function v(e){let t=_(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:h(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function y(e){return e.map(v)}function b(e){return e.replace(/\r?\n/g,`<br>`)}function x(e){return b(e.replace(/\|/g,`\\|`))}function S(e){return`\`${e}\``}function C(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function ee(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function E(e,t){switch(t){case`option`:{let t=S(e.longFlag);return e.inlineNegation?`${t} / ${S(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(S).join(`, `):`-`;case`description`:return x(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return C(e);case`env`:return ee(e.env)}}function D(e,t){switch(t){case`option`:return S(e.flag);case`description`:return`${x(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function O(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...m,`env`]:m),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>E(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>D(t.negationRow,e)).join(` | `)} |`);return r.join(`
2
2
  `)}function k(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.aliases.filter(e=>!e.startsWith(`--`)),r=n.aliases.filter(e=>e.startsWith(`--`)),i=[...e,n.longFlag,...r].map(S).join(`, `);n.inlineNegation&&(i+=` / ${S(n.inlineNegation)}`);let a=n.description?` - ${b(n.description)}`:``,o=n.required?` (required)`:``,s=n.hasDefault?` (default: ${JSON.stringify(n.defaultValue)})`:``,c=w(n.env);t.push(`- ${i}${a}${o}${s}${c}`),n.negationRow&&t.push(`- ${S(n.negationRow.flag)} - ${b(n.negationRow.description)} ${n.negationRow.relationMarker}`)}return t.join(`
3
- `)}const A=`POLITTY_DOCS_UPDATE`,j=`POLITTY_DOCS_DOCTOR`,M=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],N=`politty:command`;function P(e,t){return`<!-- ${N}:${t}:${e}:start -->`}function F(e,t){return`<!-- ${N}:${t}:${e}:end -->`}const I=`politty:global-options`;function L(){return`<!-- ${I}:start -->`}function te(){return`<!-- ${I}:end -->`}const R=`politty:root-header`;function ne(){return`<!-- ${R}:start -->`}function re(){return`<!-- ${R}:end -->`}const z=`politty:root-footer`;function ie(){return`<!-- ${z}:start -->`}function ae(){return`<!-- ${z}:end -->`}const B=`politty:index`;function V(e){return`<!-- ${B}:${e}:start -->`}function oe(e){return`<!-- ${B}:${e}:end -->`}function se(e){return b(e.replace(/\|/g,`\\|`))}function ce(e){let t=[e.fullCommandPath];e.options.length>0&&t.push(`[options]`),e.subCommands.length>0&&(e.command.run||e.command.defaultSubCommand?t.push(`[command]`):t.push(`<command>`));for(let n of e.positionalArgs)n.required?t.push(`<${n.name}>`):t.push(`[${n.name}]`);return t.join(` `)}function le(e){return fe(e,Ce)}function ue(e){return e.named?`\`${e.name}\`, \`${_(e)}\``:`\`${e.name}\``}function de(e){return fe(e,we)}function fe(e,t,n=e.positionalArgs){let r=pe(e.extracted),i=r.length>0?s(r):void 0,a=new Set(n.map(e=>e.name)),o=[],c=n.filter(e=>i===void 0||i.has(e.name));c.length>0&&o.push(t(c));for(let e of r){let n=e.fields.filter(e=>e.positional&&!i?.has(e.name)&&a.has(e.name));n.length>0&&o.push(`${e.label}\n\n${t(n)}`)}return o.join(`
3
+ `)}const A=`POLITTY_DOCS_UPDATE`,j=`POLITTY_DOCS_DOCTOR`,M=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],N=`politty:command`;function P(e,t){return`<!-- ${N}:${t}:${e}:start -->`}function F(e,t){return`<!-- ${N}:${t}:${e}:end -->`}const I=`politty:global-options`;function L(){return`<!-- ${I}:start -->`}function te(){return`<!-- ${I}:end -->`}const R=`politty:root-header`;function ne(){return`<!-- ${R}:start -->`}function re(){return`<!-- ${R}:end -->`}const z=`politty:root-footer`;function ie(){return`<!-- ${z}:start -->`}function ae(){return`<!-- ${z}:end -->`}const B=`politty:index`;function V(e){return`<!-- ${B}:${e}:start -->`}function oe(e){return`<!-- ${B}:${e}:end -->`}function se(e){return b(e.replace(/\|/g,`\\|`))}function ce(e){let t=[e.fullCommandPath];e.options.length>0&&t.push(`[options]`),e.subCommands.length>0&&(e.command.run||e.command.defaultSubCommand?t.push(`[command]`):t.push(`<command>`));for(let n of e.positionalArgs)n.required?t.push(`<${n.name}>`):t.push(`[${n.name}]`);return t.join(` `)}function le(e){return fe(e,Ce)}function ue(e){return e.named?`\`${e.name}\`, \`${_(e)}\``:`\`${e.name}\``}function de(e){return fe(e,we)}function fe(e,t,n=e.positionalArgs){let r=pe(e.extracted),i=r.length>0?a(r):void 0,o=new Set(n.map(e=>e.name)),s=[],c=n.filter(e=>i===void 0||i.has(e.name));c.length>0&&s.push(t(c));for(let e of r){let n=e.fields.filter(e=>e.positional&&!i?.has(e.name)&&o.has(e.name));n.length>0&&s.push(`${e.label}\n\n${t(n)}`)}return s.join(`
4
4
 
5
- `)}function pe(e){if(e?.schemaType===`discriminatedUnion`&&e.discriminator){let t=e.discriminator;return(e.variants??[]).map(e=>({label:me(t,e),fields:e.fields}))}return(e?.schemaType===`union`||e?.schemaType===`xor`)&&e.unionOptions?e.unionOptions.map((e,t)=>({label:he(e,t),fields:e.fields})):[]}function me(e,t){let n=t.description?` ${t.description}`:``;return`**When \`${e}\` = \`${t.discriminatorValue}\`:**${n}`}function he(e,t){return`**${e.description??`Variant ${t+1}`}:**`}function ge(e){return O(y(e.options))}function _e(e){return k(y(e.options))}function ve(e){return e.join(`-`).toLowerCase()}function ye(e,t){let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`);return d.posix.relative(d.posix.dirname(n),r)}function be(e,t=!0){return Te(e.subCommands,e,t)}function H(e){return O(y(e))}function xe(e,t=`table`){let n=e.unionOptions??[];if(n.length===0)return``;let r=[],i=s(n),a=e.fields.filter(e=>i.has(e.name)&&!e.positional);a.length>0&&r.push(t===`table`?H(a):U(a)),r.push(`> One of the following option groups is required:`);for(let e=0;e<n.length;e++){let a=n[e];if(!a)continue;let o=a.fields.filter(e=>!i.has(e.name)&&!e.positional),s=he(a,e);if(o.length===0){r.push(`${s}\n\n_no options_`);continue}let c=t===`table`?H(o):U(o);r.push(`${s}\n\n${c}`)}return r.join(`
5
+ `)}function pe(e){if(e?.schemaType===`discriminatedUnion`&&e.discriminator){let t=e.discriminator;return(e.variants??[]).map(e=>({label:me(t,e),fields:e.fields}))}return(e?.schemaType===`union`||e?.schemaType===`xor`)&&e.unionOptions?e.unionOptions.map((e,t)=>({label:he(e,t),fields:e.fields})):[]}function me(e,t){let n=t.description?` ${t.description}`:``;return`**When \`${e}\` = \`${t.discriminatorValue}\`:**${n}`}function he(e,t){return`**${e.description??`Variant ${t+1}`}:**`}function ge(e){return O(y(e.options))}function _e(e){return k(y(e.options))}function ve(e){return e.join(`-`).toLowerCase()}function ye(e,t){let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`);return d.posix.relative(d.posix.dirname(n),r)}function be(e,t=!0){return Te(e.subCommands,e,t)}function H(e){return O(y(e))}function xe(e,t=`table`){let n=e.unionOptions??[];if(n.length===0)return``;let r=[],i=a(n),o=e.fields.filter(e=>i.has(e.name)&&!e.positional);o.length>0&&r.push(t===`table`?H(o):U(o)),r.push(`> One of the following option groups is required:`);for(let e=0;e<n.length;e++){let a=n[e];if(!a)continue;let o=a.fields.filter(e=>!i.has(e.name)&&!e.positional),s=he(a,e);if(o.length===0){r.push(`${s}\n\n_no options_`);continue}let c=t===`table`?H(o):U(o);r.push(`${s}\n\n${c}`)}return r.join(`
6
6
 
7
- `)}function Se(e,t=`table`){let n=e.discriminator,r=e.variants??[];if(!n||r.length===0)return``;let a=[],o=s(r,n),c=i(e,n),l=r.map(e=>e.discriminatorValue).join(`\\|`),u=[];c&&u.push({...c,placeholder:l});for(let t of o){let n=e.fields.find(e=>e.name===t);n&&!n.positional&&u.push(n)}u.length>0&&a.push(t===`table`?H(u):U(u));for(let e of r){let r=e.fields.filter(e=>e.name!==n&&!o.has(e.name)&&!e.positional);if(r.length===0)continue;let i=me(n,e),s=t===`table`?H(r):U(r);a.push(`${i}\n\n${s}`)}return a.join(`
7
+ `)}function Se(e,t=`table`){let r=e.discriminator,i=e.variants??[];if(!r||i.length===0)return``;let o=[],s=a(i,r),c=n(e,r),l=i.map(e=>e.discriminatorValue).join(`\\|`),u=[];c&&u.push({...c,placeholder:l});for(let t of s){let n=e.fields.find(e=>e.name===t);n&&!n.positional&&u.push(n)}u.length>0&&o.push(t===`table`?H(u):U(u));for(let e of i){let n=e.fields.filter(e=>e.name!==r&&!s.has(e.name)&&!e.positional);if(n.length===0)continue;let i=me(r,e),a=t===`table`?H(n):U(n);o.push(`${i}\n\n${a}`)}return o.join(`
8
8
 
9
9
  `)}function U(e){return k(y(e))}function Ce(e){if(e.length===0)return``;let t=[];t.push(`| Argument | Description | Required |`),t.push(`|----------|-------------|----------|`);for(let n of e){let e=se(n.description??``),r=n.required?`Yes`:`No`;t.push(`| ${ue(n)} | ${e} | ${r} |`)}return t.join(`
10
10
  `)}function we(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.required?`(required)`:`(optional)`,r=n.description?` - ${b(n.description)}`:``;t.push(`- ${ue(n)}${r} ${e}`)}return t.join(`
@@ -18,9 +18,9 @@ import{h as e,l as t}from"./unflatten-DVeO9OZ_.js";import"./register-ZdhcM-o7.js
18
18
  `}}const ke={command:e=>W(e),tableStyle:W({optionStyle:`table`}),listStyle:W({optionStyle:`list`})};function Ae(e,t){let n=f.resolve(t);if(!u.existsSync(n))return{match:!1,fileExists:!1};let r=u.readFileSync(n,`utf-8`);return e===r?{match:!0,fileExists:!0}:{match:!1,diff:G(r,e),fileExists:!0}}function G(e,t){let n=e.split(`
19
19
  `),r=t.split(`
20
20
  `),i=[];i.push(`--- existing`),i.push(`+++ generated`),i.push(``);let a=Math.max(n.length,r.length),o=!1,s=0,c=[],l=()=>{c.length>0&&(i.push(`@@ -${s+1},${c.length} @@`),i.push(...c),c.length=0),o=!1};for(let e=0;e<a;e++){let t=n[e],i=r[e];if(t===i){if(o){c.push(` ${t??``}`);let e=c.findIndex((e,t)=>(e.startsWith(`-`)||e.startsWith(`+`))&&c.slice(t+1).every(e=>e.startsWith(` `)));e!==-1&&c.length-e>3&&l()}}else{if(!o){o=!0,s=e;let t=Math.max(0,e-3);for(let r=t;r<e;r++)c.push(` ${n[r]??``}`)}t!==void 0&&(i===void 0||t!==i)&&c.push(`-${t}`),i!==void 0&&(t===void 0||t!==i)&&c.push(`+${i}`)}}return l(),i.join(`
21
- `)}function K(e,t){let n=f.resolve(e),r=f.dirname(n);u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(n,t,`utf-8`)}function je(e){let t=f.resolve(e);return u.existsSync(t)?u.readFileSync(t,`utf-8`):null}function Me(e,t=u){let n=f.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,t,n=[]){return Pe(e,t,n,!1)}async function Pe(e,t,r,i){let s=a(e),l=s?n(s):[],u=s?o(s):[],d=[];if(e.subCommands)for(let[t,n]of Object.entries(e.subCommands)){let a=await c(n,t=>i||!!e.requiredPackages?.length||!!t.requiredPackages?.length),o=[...r,t];d.push({name:t,description:a.description,aliases:a.aliases,fullPath:o})}return{name:e.name??``,description:e.description,aliases:e.aliases,fullCommandPath:r.length>0?`${t} ${r.join(` `)}`:t,commandPath:r.join(` `),depth:r.length+1,positionalArgs:l,options:u,subCommands:d,extracted:s,command:e,notes:e.notes,examples:e.examples}}async function Fe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t,a){a||=!!e.requiredPackages?.length;let o=await Pe(e,n,t,a),s=t.join(` `);if(r.set(s,o),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await c(r,e=>a||!!e.requiredPackages?.length),[...t,n],a)}return await i(e,[],!1),r}async function Ie(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Le(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Le(e,t,n){let r=Re(e.cmd),i=[...n,...r],a=l({passthrough:!1});a.start();let o=!0;try{let{runCommand:e}=await import(`./runner-yzfeOFoF.js`),n=await e(t,i);o=n.success,!n.success&&n.error&&console.error(n.error.message)}catch(e){o=!1,console.error(e instanceof Error?e.message:String(e))}finally{a.stop()}let s=a.getLogs(),c=s.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
22
- `),u=s.entries.filter(e=>e.stream===`stderr`).map(e=>e.message).join(`
23
- `);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:c,stderr:u,success:o}}function Re(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function ze(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t))}function Be(e,t){let n=ze(e).filter(e=>!e.positional);return n.length===0?``:O(y(n),t?.columns)}function Ve(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function He(e){return e.replace(/\s+/g,`-`).toLowerCase()}function Ue(e){return e.subCommands.length===0}function We(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function Ge(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(Ue(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(Ue(a)||!n)&&r.push(e)}}return r}function Ke(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:Ge(e.commands,t,r),s=o,c=/* @__PURE__ */ new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>We(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!Ue(i))continue;let o=n||i.name,s=He(o),l=Ve(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
21
+ `)}function K(e,t){let n=f.resolve(e),r=f.dirname(n);u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(n,t,`utf-8`)}function je(e){let t=f.resolve(e);return u.existsSync(t)?u.readFileSync(t,`utf-8`):null}function Me(e,t=u){let n=f.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,t,n=[]){return Pe(e,t,n,!1)}async function Pe(t,n,a,o){let s=r(t),c=s?e(s):[],u=s?i(s):[],d=[];if(t.subCommands)for(let[e,n]of Object.entries(t.subCommands)){let r=await l(n,e=>o||!!t.requiredPackages?.length||!!e.requiredPackages?.length),i=[...a,e];d.push({name:e,description:r.description,aliases:r.aliases,fullPath:i})}return{name:t.name??``,description:t.description,aliases:t.aliases,fullCommandPath:a.length>0?`${n} ${a.join(` `)}`:n,commandPath:a.join(` `),depth:a.length+1,positionalArgs:c,options:u,subCommands:d,extracted:s,command:t,notes:t.notes,examples:t.examples}}async function Fe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t,a){a||=!!e.requiredPackages?.length;let o=await Pe(e,n,t,a),s=t.join(` `);if(r.set(s,o),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await l(r,e=>a||!!e.requiredPackages?.length),[...t,n],a)}return await i(e,[],!1),r}async function Ie(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Le(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Le(e,t,n){let r=Re(e.cmd),i=[...n,...r],a=o({passthrough:!1});a.start();let s=!0;try{let{runCommand:e}=await import(`./runner-OAeVJgFF.js`),n=await e(t,i);s=n.success,!n.success&&n.error&&console.error(n.error.message)}catch(e){s=!1,console.error(e instanceof Error?e.message:String(e))}finally{a.stop()}let c=a.getLogs(),l=c.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
22
+ `),u=c.entries.filter(e=>e.stream===`stderr`).map(e=>e.message).join(`
23
+ `);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:l,stderr:u,success:s}}function Re(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function ze(e){let t=s();return Object.entries(e).map(([e,n])=>t.resolveFieldMeta(e,n))}function Be(e,t){let n=ze(e).filter(e=>!e.positional);return n.length===0?``:O(y(n),t?.columns)}function Ve(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function He(e){return e.replace(/\s+/g,`-`).toLowerCase()}function Ue(e){return e.subCommands.length===0}function We(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function Ge(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(Ue(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(Ue(a)||!n)&&r.push(e)}}return r}function Ke(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:Ge(e.commands,t,r),s=o,c=/* @__PURE__ */ new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>We(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!Ue(i))continue;let o=n||i.name,s=He(o),l=Ve(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
24
24
  `)}async function qe(e,t,n){let r=n?.headingLevel??3,i=n?.leafOnly??!0,a=await Fe(e),o=[];for(let e of t){let t=Ke(e,a,r,i);o.push(t)}return o.join(`
25
25
 
26
26
  `)}async function q(e,t){if(!t)return e;let n=await t(e);return!e.endsWith(`
@@ -67,7 +67,7 @@ import{h as e,l as t}from"./unflatten-DVeO9OZ_.js";import"./register-ZdhcM-o7.js
67
67
  `:`
68
68
  `}function Dt(e){return(e.match(/\n/g)??[]).length}function Ot(e){return M.some(t=>t===e)}function kt(e){switch(Math.min(6,Math.max(1,Math.trunc(e)))){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 5:return 5;default:return 6}}function At(e,t){if(e.length===0)return t===void 0||t.has(``)?``:null;let n=e.join(`:`);if(t?.has(n))return n;let r=e.join(` `);return t?.has(r)||t===void 0?r:null}function jt(e){return e.join(` `)}function Mt(e,t){let n=e.slice(2,-2).split(`:`),r=n[1];if(r===`command`){let r=n.slice(2);if(r.length===1&&r[0]===``)return{kind:`invalid`,reason:`Trailing colon in "${e}"; use {{politty:command}} for the root command.`};let i=At(r,t);if(i!==null)return{kind:`command`,scope:i,type:void 0};if(r.length>=2){let e=r[r.length-1],n=r.slice(0,-1),i=At(n,t);if(e!==void 0&&Ot(e))return{kind:`command`,scope:i??jt(n),type:e};if(e!==void 0&&i!==null)return{kind:`invalid`,reason:`Unknown section type "${e}" for command scope "${Z(i)}". Valid section types: ${M.join(`, `)}`}}return{kind:`command`,scope:jt(r),type:void 0}}return r===`global-options`?n.length===2?{kind:`global-options`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:global-options}}.`}:r===`index`?n.length===2?{kind:`index`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:index}}.`}:{kind:`invalid`,reason:`Unknown politty directive "${r??``}" in "${e}". Valid directives: command, global-options, index`}}function Nt(e,t){let n=it(e);for(let r of e){let e=Mt(`{{politty:${r}}}`,t);if(e.kind===`command`){if(e.type===void 0)n.commandScopes.add(e.scope);else{let t=n.commandSections.get(e.scope);t||(t=/* @__PURE__ */ new Set,n.commandSections.set(e.scope,t)),t.add(e.type)}}else e.kind===`global-options`?n.globalOptions=!0:e.kind===`index`&&(n.index=!0)}return n}function Pt(e,t){for(let n of t)if(J(e,n))return!0;return!1}function Ft(e,t,n){return Pt(e,n.commandScopes)?!0:n.commandSections.get(e)?.has(t)??!1}function It(e,t,n,r){return mt(ut(lt([e],t),n).filter(e=>!Pt(e,r.commandScopes)),[e])}function Lt(e,t,n){return n.rawKeys.has($e(e))?!0:t.kind===`command`?Pt(t.scope,n.commandScopes)?!0:t.type!==void 0&&(n.commandSections.get(t.scope)?.has(t.type)??!1):t.kind===`global-options`?n.globalOptions:t.kind===`index`&&n.index}function Rt(e,t){if(!e.startsWith(`command:`))return!1;let n=e.slice(8).split(`:`);for(let e of t.commandScopes){if(e===``)return!0;let t=e.split(` `);if(n.slice(0,t.length).join(` `)===e)return!0;let r=e.split(`:`);if(n.slice(0,r.length).join(`:`)===e)return!0}return!1}const zt=/\{\{politty:[^{}]*\}\}/g;function Bt(e,t){let n=/* @__PURE__ */ new Set;for(let r of e.matchAll(zt)){let i=r.index,a=i+r[0].length;if(e[i-1]===`{`||e[a]===`}`){let n=e.slice(Math.max(0,i-1),Math.min(e.length,a+1)).split(`
69
69
  `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}n.add(i)}let r=0;for(;;){let i=e.indexOf(`{{politty:`,r);if(i===-1)return;if(!n.has(i)){let n=e.slice(i,i+80).split(`
70
- `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Vt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${Z(r)}". Valid section types: ${M.join(`, `)}`}function Ht(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ut(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Wt(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Gt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Wt(e.args)}function Kt(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t)).filter(e=>!e.positional)}function qt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return p(r,a)}function Jt(e){if(e)return Gt(e)?e:{args:e}}function Yt(e){if(!e)return;let t=r(e).fields.filter(e=>!e.positional);if(t.length!==0)return Object.fromEntries(t.map(e=>[e.name,e.schema]))}function Xt(e){let t=/* @__PURE__ */ new Map;if(!e?.globalOptions)return t;let n=Jt(e.globalOptions);if(!n)return t;for(let e of Kt(n.args))t.set(e.name,e);return t}function Zt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=X(o,n,r);if(e.length===0)continue;let c=`./`+f.relative(f.dirname(t),a).replace(/\\/g,`/`),l=e[0],u=l===void 0?void 0:n.get(l),d=Array.isArray(o)?void 0:o;i.push({title:d?.title??u?.name??f.basename(a,f.extname(a)),description:d?.description??u?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Qt(e,t,n,r){let i=$(t),a=[];for(let[t,o]of e.entries()){if($(t)===i)continue;let e=o.headingScopes;if(e.length===0)continue;let s=`./`+f.relative(f.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??f.basename(t,f.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function $t(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of Object.values(e)){let{commandPaths:e}=X(i,t,n);for(let t of e)r.add(t)}return r}function en(e,t,n,r){let i=/* @__PURE__ */ new Set;for(let a of Object.keys(t)){let o=pn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function tn(e,t){return t.some(t=>J(e,t))}function nn(e,t){return e.referencedScopes.some(e=>tn(e,t))}function rn(e,t){return e.emitsIndex||e.emitsGlobalOptions||nn(e,t)}function an(e,t,n){if(n.size===0)return;let r=[];for(let i of e){let e=t.get(i);if(e)for(let t of e.options){let e=n.get(t.name);e&&(qt(e,t)||r.push(`Command "${Z(i)}" option "--${t.cliName}" does not match globalOptions definition for "${t.name}".`))}}if(r.length>0)throw Error(`Invalid globalOptions configuration:\n - ${r.join(`
70
+ `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Vt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${Z(r)}". Valid section types: ${M.join(`, `)}`}function Ht(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ut(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Wt(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Gt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Wt(e.args)}function Kt(e){let t=s();return Object.entries(e).map(([e,n])=>t.resolveFieldMeta(e,n)).filter(e=>!e.positional)}function qt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return p(r,a)}function Jt(e){if(e)return Gt(e)?e:{args:e}}function Yt(e){if(!e)return;let n=t(e).fields.filter(e=>!e.positional);if(n.length!==0)return Object.fromEntries(n.map(e=>[e.name,e.schema]))}function Xt(e){let t=/* @__PURE__ */ new Map;if(!e?.globalOptions)return t;let n=Jt(e.globalOptions);if(!n)return t;for(let e of Kt(n.args))t.set(e.name,e);return t}function Zt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=X(o,n,r);if(e.length===0)continue;let c=`./`+f.relative(f.dirname(t),a).replace(/\\/g,`/`),l=e[0],u=l===void 0?void 0:n.get(l),d=Array.isArray(o)?void 0:o;i.push({title:d?.title??u?.name??f.basename(a,f.extname(a)),description:d?.description??u?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Qt(e,t,n,r){let i=$(t),a=[];for(let[t,o]of e.entries()){if($(t)===i)continue;let e=o.headingScopes;if(e.length===0)continue;let s=`./`+f.relative(f.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??f.basename(t,f.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function $t(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of Object.values(e)){let{commandPaths:e}=X(i,t,n);for(let t of e)r.add(t)}return r}function en(e,t,n,r){let i=/* @__PURE__ */ new Set;for(let a of Object.keys(t)){let o=pn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function tn(e,t){return t.some(t=>J(e,t))}function nn(e,t){return e.referencedScopes.some(e=>tn(e,t))}function rn(e,t){return e.emitsIndex||e.emitsGlobalOptions||nn(e,t)}function an(e,t,n){if(n.size===0)return;let r=[];for(let i of e){let e=t.get(i);if(e)for(let t of e.options){let e=n.get(t.name);e&&(qt(e,t)||r.push(`Command "${Z(i)}" option "--${t.cliName}" does not match globalOptions definition for "${t.name}".`))}}if(r.length>0)throw Error(`Invalid globalOptions configuration:\n - ${r.join(`
71
71
  - `)}`)}function on(e){return[`<a id="global-options"></a>`,Be(e.args,e.options)].join(`
72
72
  `)}function sn(e){return[L(),on(e),te()].join(`
73
73
  `)}async function cn(e,t,n,r){let i=V(n),a=oe(n);return[i,await qe(t,e,r),a].join(`
@@ -80,15 +80,15 @@ import{h as e,l as t}from"./unflatten-DVeO9OZ_.js";import"./register-ZdhcM-o7.js
80
80
  `+f+`
81
81
  `,d=!0,{content:c,diffs:l,hasError:u,wasUpdated:d}):(u=!0,l.push(`${t} marker not found in file. Expected markers:\n${n}\n...\n${r}`),{content:c,diffs:l,hasError:u,wasUpdated:d});if(p!==f){if(a){let e=Ut(c,n,r,f);e?(c=e,d=!0):(u=!0,l.push(`Failed to replace ${t} section`))}else u=!0,l.push(G(p,f))}return{content:c,diffs:l,hasError:u,wasUpdated:d}}async function dn(e,t,n,r,i,a,o){let s=e,c=[],l=!1,u=!1,d=V(r),f=oe(r),p=s.includes(d),m=s.includes(f);if(!p&&!m)return{content:s,diffs:c,hasError:l,wasUpdated:u};if(!p||!m)return l=!0,c.push(`Index marker section is malformed: both start and end markers are required.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let h=Ht(s,d,f);if(!h)return l=!0,c.push(`Index marker section is malformed: start marker must appear before end marker.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let g=await q(await cn(t,n,r,o),a);if(h!==g){if(i){let e=Ut(s,d,f,g);e?(s=e,u=!0):(l=!0,c.push(`Failed to replace index section`))}else l=!0,c.push(G(h,g))}return{content:s,diffs:c,hasError:l,wasUpdated:u}}function fn(e,t,n,r){for(let[i,a]of Object.entries(t)){let{commandPaths:t}=X(a,n,r);if(t.includes(e))return i}return null}function pn(e,t,n,r,i){let a=n[t];if(!a)return[];let{specifiedCommands:o,commandPaths:s}=X(a,r,i),c=/* @__PURE__ */ new Set;for(let t of e)if(s.includes(t)){c.add(t);for(let e of s)J(e,t)&&!o.includes(e)&&c.add(e)}return Array.from(c)}function mn(e,t,n,r,i,a,o,s=[],c,l){let u=t.get(e);if(!u||l&&Pt(u.commandPath,l.commandScopes))return null;let d={...u,filePath:r,fileMap:i,rootDocPath:a};(s.length>0||l&&l.commandScopes.size>0)&&(d.subCommands=u.subCommands.filter(e=>{let t=e.fullPath.join(` `);return!s.some(e=>ct(t,e))&&!(l&&Pt(t,l.commandScopes))})),o!==void 0&&(d.hasGlobalOptions=o),c&&c.size>0&&(d.options=u.options.filter(e=>!c.has(e.name)),u.extracted&&(d.extracted=gn(u.extracted,c)));let f=n(d);if(l){for(let[e,t]of l.commandSections)if(e===u.commandPath){for(let n of t){let t=Q(f,n,e);t!==null&&(f=f.replace(t,``))}f=Tt(f)}}return f}function hn(e,t,n,r,i,a,o,s,c,l){let u=It(e,t,r,l),d=[];for(let e of u){let u=mn(e,t,n,i,a,o,s,r,c,l);u!==null&&d.push(u)}return d.length===0?null:d.join(`
82
82
  `)}function gn(e,t){let n={...e,fields:e.fields.filter(e=>!t.has(e.name))};return e.unionOptions&&(n.unionOptions=e.unionOptions.map(e=>gn(e,t))),e.variants&&(n.variants=e.variants.map(e=>({...e,fields:e.fields.filter(e=>!t.has(e.name))}))),n}function _n(e,t,n,r,i,a,o,s,c,l=[]){let u=[],d=o?ht(o):null;d&&u.push(d);let f=mt(e,a??[]);for(let e of f){let a=mn(e,t,n,r,i,s,c,l);a&&u.push(a)}return`${u.join(`
83
- `)}\n`}function vn(e,n,r){let i={};for(let[a,o]of Object.entries(e)){let{commandPaths:e}=X(o,n,r);for(let n of e)t(i,n,a)}return i}async function yn(e,t,n){for(let[r,i]of Object.entries(t)){let t=e.get(r);if(!t?.examples?.length)continue;let a=i===!0?{}:i,o=r?r.split(` `):[];t.exampleResults=await Ie(t.examples,a,n,o)}}function bn(e,t){if(typeof e==`string`)return{files:{[e]:Array.from(t.keys())},rootDocPath:e};let{root:n,commands:r={}}=e,i={},a=/* @__PURE__ */ new Set,o=Object.entries(r).sort(([e],[t])=>t.split(` `).length-e.split(` `).length);for(let[e,n]of o){i[n]||(i[n]={commands:[],noExpand:!0});let r=i[n];for(let n of t.keys())(n===e||n.startsWith(e+` `))&&!a.has(n)&&(r.commands.push(n),a.add(n))}return i[n]={commands:Array.from(t.keys()).filter(e=>!a.has(e)),noExpand:!0},{files:i,rootDocPath:n}}async function xn(e){let{command:n,ignores:i=[],format:a={},formatter:o,examples:s,targetCommands:c,globalArgs:l,customizable:u=!1}=e,d=await Fe(n),p,m=!1,h;if(e.path!==void 0){if(e.files!==void 0)throw Error(`Cannot specify both "path" and "files". Use one or the other.`);let t=bn(e.path,d);p=t.files,h=t.rootDocPath,m=!0}else if(e.files!==void 0)p=e.files;else if(e.templates!==void 0)p={};else throw Error(`Either "path", "files", or "templates" must be specified.`);let g=e.rootDoc;if(!g&&m&&(l||e.rootInfo)&&(g={path:h}),l&&g&&!g.globalOptions){let e=r(l).fields.filter(e=>!e.positional);if(e.length>0){let t=Object.fromEntries(e.map(e=>[e.name,e.schema]));g={...g,globalOptions:t}}}let _=Je(A),v=Je(j),y=!1;if(g&&!m){let e=$(g.path);if(Object.keys(p).some(t=>$(t)===e))throw Error(`rootDoc.path "${g.path}" must not also appear as a key in files.`)}s&&await yn(d,s,n);let b=c!==void 0&&c.length>0,x=Xt(g),S=/* @__PURE__ */ new Map;if(e.templates){if(x.size>0)for(let[e,t]of x)S.set(e,t);else{let e=Yt(l);if(e)for(let t of Kt(e))S.set(t.name,t)}}let C=b?en(c,p,d,i):$t(p,d,i),ee=[];for(let e of Object.values(p)){let t=at(e);ee.push(...t.commands)}pt(i,d),ft(ee,i,d);let w=vn(p,d,i),T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map;if(e.templates)for(let[t,n]of Object.entries(e.templates)){let e=je(n);T.set(t,e),e!==null&&E.set(t,Nt(nt(e),d))}let D=Object.entries(e.templates??{}),O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map;if(D.length>0){let e=g?$(g.path):null,t=new Set(Object.keys(p).map($)),n=/* @__PURE__ */ new Set,r=new Set(D.map(([e])=>$(e)));for(let[i,a]of D){let o=$(i),s=$(a);if(t.has(o))throw Error(`Template output path "${i}" conflicts with an existing files key.`);if(e&&o===e)throw Error(`Template output path "${i}" conflicts with rootDoc.path "${g.path}".`);if(n.has(o))throw Error(`Duplicate template output path: "${i}".`);if(n.add(o),s===o)throw Error(`Template output path "${i}" must not be the same as its source template path.`);if(t.has(s))throw Error(`Template source path "${a}" conflicts with a files output key.`);if(e&&s===e)throw Error(`Template source path "${a}" conflicts with rootDoc.path "${g.path}".`);if(r.has(s))throw Error(`Template source path "${a}" conflicts with a template output path.`)}let a=Array.from(d.keys()).join(`, `);for(let[e,t]of D){let n=T.get(e)??null,r=[];if(n===null){O.set(e,{referencedScopes:[],headingScopes:[],commandTreeRoots:[],emitsGlobalOptions:!1,emitsIndex:!1}),k.set(e,r);continue}try{Bt(n,t)}catch(e){r.push(e instanceof Error?e.message:String(e))}let o=Array.from(new Set(n.match(zt)??[])),s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,f=!1,p=!1,m=E.get(e)??it(/* @__PURE__ */ new Set),h=rt(n);for(let e of o){let n=$e(e);if(m.rawKeys.has(n)||Rt(n,m))continue;let o=Mt(e,d);if(!Lt(e,o,m)){if(o.kind===`invalid`)r.push(`${o.reason} (in template "${t}")`);else if(o.kind===`command`){let{scope:e,type:n}=o;if(!d.has(e)){let n=Vt(e,d);if(n){r.push(`${n} (in template "${t}")`);continue}r.push(`Unknown command scope "${e}" in template "${t}". Available: ${a}`);continue}if(i.some(t=>ct(e,t))){r.push(`Command scope "${e}" in template "${t}" conflicts with ignores configuration.`);continue}if(n===void 0){let t=It(e,d,i,m);Ft(e,`heading`,m)||u.add(e);for(let e of t)s.add(e),Ft(e,`heading`,m)||c.add(e)}else s.add(e),n===`heading`&&!Ft(e,`heading`,m)&&(c.add(e),u.add(e))}else o.kind===`global-options`?f=!0:o.kind===`index`&&(p=!0)}}f&&(g?.globalOptions||Yt(l)!==void 0||r.push(`Template "${t}" uses {{politty:global-options}} but no global options are configured (neither rootDoc.globalOptions nor globalArgs with non-positional options).`)),O.set(e,{referencedScopes:Array.from(s),headingScopes:Array.from(c),commandTreeRoots:Array.from(u),emitsGlobalOptions:f,emitsIndex:p,...h.title===void 0?{}:{indexTitle:h.title},...h.description===void 0?{}:{indexDescription:h.description}}),k.set(e,r)}for(let e of O.values())if(!b||rn(e,c))for(let t of e.referencedScopes)C.add(t)}if(b)for(let e of c){let t=fn(e,p,d,i),n=Array.from(O.values()).some(t=>nn(t,[e]));if(!t&&!n)throw Error(`Target command "${e}" not found in any file or template configuration`)}let M=b&&e.templates?new Map(Array.from(O.entries()).filter(([,e])=>rn(e,c))):O;for(let[e,t]of k.entries())if(t.length>0&&M.has(e))throw Error(t.join(`
84
- `));let N=Array.from(O.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),I=N.length===1?N[0]:void 0;if(an(C,d,x),x.size===0&&S.size>0){let e=/* @__PURE__ */ new Set;for(let t of M.values())if(t.emitsGlobalOptions||I!==void 0)for(let n of t.referencedScopes)e.add(n);an(e,d,S)}if(x.size>0)for(let e of d.values())e.options=e.options.filter(e=>!x.has(e.name)),e.extracted&&=gn(e.extracted,new Set(x.keys()));let L={};for(let[e,n]of Object.entries(w))t(L,e,n);let te=e=>e===``?0:e.split(` `).length,R=/* @__PURE__ */ new Map;for(let[e,t]of O.entries())for(let n of t.headingScopes){if(Object.prototype.hasOwnProperty.call(w,n))continue;let r=-1;for(let e of t.commandTreeRoots)J(n,e)&&(r=Math.max(r,te(e)));if(r<0)continue;let i=R.get(n);(!i||r>i.rootLen)&&R.set(n,{outputPath:e,rootLen:r})}for(let[e,{outputPath:n}]of R)t(L,e,n);let z=[],B=!1;for(let[e,t]of Object.entries(p)){let{fileConfig:n,specifiedCommands:r,commandPaths:s}=X(t,d,i);if(r.length===0||s.length===0)continue;let l=b?pn(c,e,p,d,i):[];if(b&&l.length===0)continue;let f=`match`,h=[],S=Math.min(...s.map(e=>d.get(e)?.depth??1)),C=Math.max(1,(a?.headingLevel??1)-(S-1)),ee=m&&g&&$(e)===$(g.path),w=m||u,T=W({...a,headingLevel:C,markerless:!w}),E=n.render??T;if(ee||b&&w){let t=je(e),a=mt(s,r),c=b?l:s;for(let r of c){let s=mn(r,d,E,e,L,g?.path,x.size>0,i);if(!s)throw Error(`Target command "${r}" not found in commands`);let c=await q(s,o);if(!t){if(_){let i=r===``&&n?ht(n):null,a=i?`${i}\n${c}`:c;K(e,a),t=a,f=`created`}else B=!0,f=`diff`,h.push(`File does not exist. Target command "${r}" section cannot be validated.`);continue}let l=bt(t,r);if(l.length===0)_?(t=St(t,r,c,a),K(e,t),f!==`created`&&(f=`updated`)):(B=!0,f=`diff`,h.push(`Existing file does not contain section markers for command "${r}"`));else{for(let n of l){let i=Q(t,n,r),a=Q(c,n,r);if(i){if(!a){let a=P(n,r)+`
85
- `+F(n,r);if(i!==a){if(_){let i=vt(t,n,r,a);if(!i)throw Error(`Failed to replace stale ${n} section for command "${r}"`);t=i.replace(/\n{3,}/g,`
83
+ `)}\n`}function vn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let{commandPaths:e}=X(a,t,n);for(let t of e)c(r,t,i)}return r}async function yn(e,t,n){for(let[r,i]of Object.entries(t)){let t=e.get(r);if(!t?.examples?.length)continue;let a=i===!0?{}:i,o=r?r.split(` `):[];t.exampleResults=await Ie(t.examples,a,n,o)}}function bn(e,t){if(typeof e==`string`)return{files:{[e]:Array.from(t.keys())},rootDocPath:e};let{root:n,commands:r={}}=e,i={},a=/* @__PURE__ */ new Set,o=Object.entries(r).sort(([e],[t])=>t.split(` `).length-e.split(` `).length);for(let[e,n]of o){i[n]||(i[n]={commands:[],noExpand:!0});let r=i[n];for(let n of t.keys())(n===e||n.startsWith(e+` `))&&!a.has(n)&&(r.commands.push(n),a.add(n))}return i[n]={commands:Array.from(t.keys()).filter(e=>!a.has(e)),noExpand:!0},{files:i,rootDocPath:n}}async function xn(e){let{command:n,ignores:r=[],format:i={},formatter:a,examples:o,targetCommands:s,globalArgs:l,customizable:u=!1}=e,d=await Fe(n),p,m=!1,h;if(e.path!==void 0){if(e.files!==void 0)throw Error(`Cannot specify both "path" and "files". Use one or the other.`);let t=bn(e.path,d);p=t.files,h=t.rootDocPath,m=!0}else if(e.files!==void 0)p=e.files;else if(e.templates!==void 0)p={};else throw Error(`Either "path", "files", or "templates" must be specified.`);let g=e.rootDoc;if(!g&&m&&(l||e.rootInfo)&&(g={path:h}),l&&g&&!g.globalOptions){let e=t(l).fields.filter(e=>!e.positional);if(e.length>0){let t=Object.fromEntries(e.map(e=>[e.name,e.schema]));g={...g,globalOptions:t}}}let _=Je(A),v=Je(j),y=!1;if(g&&!m){let e=$(g.path);if(Object.keys(p).some(t=>$(t)===e))throw Error(`rootDoc.path "${g.path}" must not also appear as a key in files.`)}o&&await yn(d,o,n);let b=s!==void 0&&s.length>0,x=Xt(g),S=/* @__PURE__ */ new Map;if(e.templates){if(x.size>0)for(let[e,t]of x)S.set(e,t);else{let e=Yt(l);if(e)for(let t of Kt(e))S.set(t.name,t)}}let C=b?en(s,p,d,r):$t(p,d,r),ee=[];for(let e of Object.values(p)){let t=at(e);ee.push(...t.commands)}pt(r,d),ft(ee,r,d);let w=vn(p,d,r),T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map;if(e.templates)for(let[t,n]of Object.entries(e.templates)){let e=je(n);T.set(t,e),e!==null&&E.set(t,Nt(nt(e),d))}let D=Object.entries(e.templates??{}),O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map;if(D.length>0){let e=g?$(g.path):null,t=new Set(Object.keys(p).map($)),n=/* @__PURE__ */ new Set,i=new Set(D.map(([e])=>$(e)));for(let[r,a]of D){let o=$(r),s=$(a);if(t.has(o))throw Error(`Template output path "${r}" conflicts with an existing files key.`);if(e&&o===e)throw Error(`Template output path "${r}" conflicts with rootDoc.path "${g.path}".`);if(n.has(o))throw Error(`Duplicate template output path: "${r}".`);if(n.add(o),s===o)throw Error(`Template output path "${r}" must not be the same as its source template path.`);if(t.has(s))throw Error(`Template source path "${a}" conflicts with a files output key.`);if(e&&s===e)throw Error(`Template source path "${a}" conflicts with rootDoc.path "${g.path}".`);if(i.has(s))throw Error(`Template source path "${a}" conflicts with a template output path.`)}let a=Array.from(d.keys()).join(`, `);for(let[e,t]of D){let n=T.get(e)??null,i=[];if(n===null){O.set(e,{referencedScopes:[],headingScopes:[],commandTreeRoots:[],emitsGlobalOptions:!1,emitsIndex:!1}),k.set(e,i);continue}try{Bt(n,t)}catch(e){i.push(e instanceof Error?e.message:String(e))}let o=Array.from(new Set(n.match(zt)??[])),s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,f=!1,p=!1,m=E.get(e)??it(/* @__PURE__ */ new Set),h=rt(n);for(let e of o){let n=$e(e);if(m.rawKeys.has(n)||Rt(n,m))continue;let o=Mt(e,d);if(!Lt(e,o,m)){if(o.kind===`invalid`)i.push(`${o.reason} (in template "${t}")`);else if(o.kind===`command`){let{scope:e,type:n}=o;if(!d.has(e)){let n=Vt(e,d);if(n){i.push(`${n} (in template "${t}")`);continue}i.push(`Unknown command scope "${e}" in template "${t}". Available: ${a}`);continue}if(r.some(t=>ct(e,t))){i.push(`Command scope "${e}" in template "${t}" conflicts with ignores configuration.`);continue}if(n===void 0){let t=It(e,d,r,m);Ft(e,`heading`,m)||u.add(e);for(let e of t)s.add(e),Ft(e,`heading`,m)||c.add(e)}else s.add(e),n===`heading`&&!Ft(e,`heading`,m)&&(c.add(e),u.add(e))}else o.kind===`global-options`?f=!0:o.kind===`index`&&(p=!0)}}f&&(g?.globalOptions||Yt(l)!==void 0||i.push(`Template "${t}" uses {{politty:global-options}} but no global options are configured (neither rootDoc.globalOptions nor globalArgs with non-positional options).`)),O.set(e,{referencedScopes:Array.from(s),headingScopes:Array.from(c),commandTreeRoots:Array.from(u),emitsGlobalOptions:f,emitsIndex:p,...h.title===void 0?{}:{indexTitle:h.title},...h.description===void 0?{}:{indexDescription:h.description}}),k.set(e,i)}for(let e of O.values())if(!b||rn(e,s))for(let t of e.referencedScopes)C.add(t)}if(b)for(let e of s){let t=fn(e,p,d,r),n=Array.from(O.values()).some(t=>nn(t,[e]));if(!t&&!n)throw Error(`Target command "${e}" not found in any file or template configuration`)}let M=b&&e.templates?new Map(Array.from(O.entries()).filter(([,e])=>rn(e,s))):O;for(let[e,t]of k.entries())if(t.length>0&&M.has(e))throw Error(t.join(`
84
+ `));let N=Array.from(O.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),I=N.length===1?N[0]:void 0;if(an(C,d,x),x.size===0&&S.size>0){let e=/* @__PURE__ */ new Set;for(let t of M.values())if(t.emitsGlobalOptions||I!==void 0)for(let n of t.referencedScopes)e.add(n);an(e,d,S)}if(x.size>0)for(let e of d.values())e.options=e.options.filter(e=>!x.has(e.name)),e.extracted&&=gn(e.extracted,new Set(x.keys()));let L={};for(let[e,t]of Object.entries(w))c(L,e,t);let te=e=>e===``?0:e.split(` `).length,R=/* @__PURE__ */ new Map;for(let[e,t]of O.entries())for(let n of t.headingScopes){if(Object.prototype.hasOwnProperty.call(w,n))continue;let r=-1;for(let e of t.commandTreeRoots)J(n,e)&&(r=Math.max(r,te(e)));if(r<0)continue;let i=R.get(n);(!i||r>i.rootLen)&&R.set(n,{outputPath:e,rootLen:r})}for(let[e,{outputPath:t}]of R)c(L,e,t);let z=[],B=!1;for(let[e,t]of Object.entries(p)){let{fileConfig:n,specifiedCommands:o,commandPaths:c}=X(t,d,r);if(o.length===0||c.length===0)continue;let l=b?pn(s,e,p,d,r):[];if(b&&l.length===0)continue;let f=`match`,h=[],S=Math.min(...c.map(e=>d.get(e)?.depth??1)),C=Math.max(1,(i?.headingLevel??1)-(S-1)),ee=m&&g&&$(e)===$(g.path),w=m||u,T=W({...i,headingLevel:C,markerless:!w}),E=n.render??T;if(ee||b&&w){let t=je(e),i=mt(c,o),s=b?l:c;for(let o of s){let s=mn(o,d,E,e,L,g?.path,x.size>0,r);if(!s)throw Error(`Target command "${o}" not found in commands`);let c=await q(s,a);if(!t){if(_){let r=o===``&&n?ht(n):null,i=r?`${r}\n${c}`:c;K(e,i),t=i,f=`created`}else B=!0,f=`diff`,h.push(`File does not exist. Target command "${o}" section cannot be validated.`);continue}let l=bt(t,o);if(l.length===0)_?(t=St(t,o,c,i),K(e,t),f!==`created`&&(f=`updated`)):(B=!0,f=`diff`,h.push(`Existing file does not contain section markers for command "${o}"`));else{for(let n of l){let r=Q(t,n,o),i=Q(c,n,o);if(r){if(!i){let i=P(n,o)+`
85
+ `+F(n,o);if(r!==i){if(_){let r=vt(t,n,o,i);if(!r)throw Error(`Failed to replace stale ${n} section for command "${o}"`);t=r.replace(/\n{3,}/g,`
86
86
 
87
- `),K(e,t),f!==`created`&&(f=`updated`)}else B=!0,f=`diff`,h.push(G(i,a))}}else if(i!==a){if(_){let i=vt(t,n,r,a);if(i)t=i,K(e,t),f!==`created`&&(f=`updated`);else throw Error(`Failed to replace ${n} section for command "${r}"`)}else B=!0,f=`diff`,h.push(G(i,a))}}}if(v||u){let n=bt(c,r),i=new Set(l);for(let a of n){if(i.has(a))continue;let n=Q(c,a,r);n&&(v&&_?(t=yt(t,a,r,n),K(e,t),f!==`created`&&(f=`updated`)):v?(B=!0,y=!0,f=`diff`,h.push(`[doctor] Missing section marker "${a}" for command "${Z(r)}". Run with ${j}=true ${A}=true to insert.\n${n}`)):console.warn(`[politty] Missing "${a}" section for command "${Z(r)}" in ${e}. Run with ${j}=true ${A}=true to insert it, or leave it removed to opt that section out.`))}}}}if(t){let n=xt(t),r=new Set(s);if(_){let i=!1;for(let e of n)r.has(e)||(t=Ct(t,e),i=!0);i&&(K(e,t),f!==`created`&&(f=`updated`))}else for(let e of n)r.has(e)||(B=!0,f=`diff`,h.push(`Found orphaned section markers for deleted command "${Z(e)}"`))}}else{let t=await q(_n(s,d,E,e,L,r,n,g?.path,x.size>0,i),o),a=Ae(t,e);a.match||(_?(K(e,t),f=a.fileExists?`updated`:`created`):(B=!0,f=`diff`,a.diff&&h.push(a.diff)))}h.length>0&&(f=`diff`),z.push({path:e,status:f,diff:h.length>0?h.join(`
87
+ `),K(e,t),f!==`created`&&(f=`updated`)}else B=!0,f=`diff`,h.push(G(r,i))}}else if(r!==i){if(_){let r=vt(t,n,o,i);if(r)t=r,K(e,t),f!==`created`&&(f=`updated`);else throw Error(`Failed to replace ${n} section for command "${o}"`)}else B=!0,f=`diff`,h.push(G(r,i))}}}if(v||u){let n=bt(c,o),r=new Set(l);for(let i of n){if(r.has(i))continue;let n=Q(c,i,o);n&&(v&&_?(t=yt(t,i,o,n),K(e,t),f!==`created`&&(f=`updated`)):v?(B=!0,y=!0,f=`diff`,h.push(`[doctor] Missing section marker "${i}" for command "${Z(o)}". Run with ${j}=true ${A}=true to insert.\n${n}`)):console.warn(`[politty] Missing "${i}" section for command "${Z(o)}" in ${e}. Run with ${j}=true ${A}=true to insert it, or leave it removed to opt that section out.`))}}}}if(t){let n=xt(t),r=new Set(c);if(_){let i=!1;for(let e of n)r.has(e)||(t=Ct(t,e),i=!0);i&&(K(e,t),f!==`created`&&(f=`updated`))}else for(let e of n)r.has(e)||(B=!0,f=`diff`,h.push(`Found orphaned section markers for deleted command "${Z(e)}"`))}}else{let t=await q(_n(c,d,E,e,L,o,n,g?.path,x.size>0,r),a),i=Ae(t,e);i.match||(_?(K(e,t),f=i.fileExists?`updated`:`created`):(B=!0,f=`diff`,i.diff&&h.push(i.diff)))}h.length>0&&(f=`diff`),z.push({path:e,status:f,diff:h.length>0?h.join(`
88
88
 
89
- `):void 0})}let V;if(g?.globalOptions)V=Jt(g.globalOptions);else{let e=Yt(l);e&&(V={args:e})}for(let[e,t]of D){if(!M.has(e))continue;let r=T.get(e)??null;if(r===null){B=!0,z.push({path:e,status:`diff`,diff:`Template file not found: ${t}`});continue}let s=O.get(e),c=Et(r),l=Xe(r),u=(s?.headingScopes??[]).map(e=>d.get(e)?.depth??1),f=u.length>0?Math.min(...u):1,m=kt((a?.headingLevel??1)-(f-1)),h=W({...a,headingLevel:m}),v=s?.emitsGlobalOptions??!1,y=(g!==void 0&&x.size>0||v||I!==void 0)&&S.size>0?new Set(S.keys()):void 0,b=y!==void 0,C=v?e:g?.path??I,ee=Array.from(new Set(l.match(zt)??[])),w=/* @__PURE__ */ new Map,D=E.get(e)??it(/* @__PURE__ */ new Set);for(let r of ee){let a=$e(r);if(D.rawKeys.has(a)||Rt(a,D)){w.set(r,``);continue}let o=Mt(r,d);if(Lt(r,o,D))w.set(r,``);else{if(o.kind===`invalid`)throw Error(`Internal error: unresolved placeholder "${r}" in template "${t}": ${o.reason}`);if(o.kind===`command`){let{scope:t,type:n}=o;if(n===void 0){let n=hn(t,d,h,i,e,L,C,b,y,D);if(n===null){w.set(r,``);continue}w.set(r,wt(n))}else{let a=mn(t,d,h,e,L,C,b,i,y,D);if(a===null){w.set(r,``);continue}let o=Q(a,n,t);w.set(r,o===null?``:wt(o))}}else if(o.kind===`global-options`)V?w.set(r,on(V)):w.set(r,``);else if(o.kind===`index`){let t=await qe(n,[...Zt(p,e,d,i),...Qt(O,e,e,d)],g?.index);w.set(r,t)}}}let k=l.replace(/((?:\r?\n)*)([ \t]*)(\{\{politty:[^{}]*\}\})([ \t]*)((?:\r?\n)*)/g,(e,n,r,i,a,o,s,c)=>{let l=w.get(i);if(l===void 0)throw Error(`Internal error: unresolved placeholder "${i}" in template "${t}".`);let u=n!==``||s===0||c[s-1]===`
90
- `,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(n===``||o===``)return``;let e=Dt(n),t=Dt(o),r=Math.max(e,t),i=Et(e>=t?n:o);return r>=2?i+i:r===1?i:``}return`${n}${r}${l}${a}${o}`});k=`${k.trimEnd()}${c}`,k=await q(k,o);let A=Ae(k,e),j=`match`,N;A.match||(_?(K(e,k),j=A.fileExists?`updated`:`created`):(B=!0,j=`diff`,A.diff&&(N=A.diff))),z.push({path:e,status:j,diff:N})}if(g){let t=g.path,r=`match`,a=[],s=je(t);if(s===null)B=!0,r=`diff`,a.push(`File does not exist. Cannot validate rootDoc markers.`);else{let c=s,l=!1,u=e.rootInfo,h={title:u?.title??n.name};g.headingLevel!==void 0&&(h.headingLevel=g.headingLevel);let v=u?.description??n.description;v!==void 0&&(h.description=v);let y=_t(c,h,_);if(c=y.content,y.diff&&a.push(y.diff),y.hasError&&(B=!0),y.wasUpdated&&(l=!0),u?.header){let e=await un(c,`Root header`,ne(),re(),u.header,_,o,m);c=e.content,a.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}if(!m){let e=xt(c);if(e.length>0){if(_){for(let t of e)c=Ct(c,t);l=!0}else B=!0,a.push(`Found unexpected section markers in rootDoc: ${e.map(e=>`"${Z(e)}"`).join(`, `)}.`)}}let b=Jt(g.globalOptions);if(b){let e=await ln(c,b,_,o,m);c=e.content,a.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}let x=Zt(p,t,d,i),S=f.relative(process.cwd(),t).replace(/\\/g,`/`),C=await dn(c,x,n,S,_,o,g.index);if(c=C.content,a.push(...C.diffs),C.hasError&&(B=!0),C.wasUpdated&&(l=!0),u?.footer){let e=await un(c,`Root footer`,ie(),ae(),u.footer,_,o,m);c=e.content,a.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}_&&l&&(K(t,c),r===`match`&&(r=`updated`))}a.length>0&&(r=`diff`),z.push({path:t,status:r,diff:a.length>0?a.join(`
89
+ `):void 0})}let V;if(g?.globalOptions)V=Jt(g.globalOptions);else{let e=Yt(l);e&&(V={args:e})}for(let[e,t]of D){if(!M.has(e))continue;let o=T.get(e)??null;if(o===null){B=!0,z.push({path:e,status:`diff`,diff:`Template file not found: ${t}`});continue}let s=O.get(e),c=Et(o),l=Xe(o),u=(s?.headingScopes??[]).map(e=>d.get(e)?.depth??1),f=u.length>0?Math.min(...u):1,m=kt((i?.headingLevel??1)-(f-1)),h=W({...i,headingLevel:m}),v=s?.emitsGlobalOptions??!1,y=(g!==void 0&&x.size>0||v||I!==void 0)&&S.size>0?new Set(S.keys()):void 0,b=y!==void 0,C=v?e:g?.path??I,ee=Array.from(new Set(l.match(zt)??[])),w=/* @__PURE__ */ new Map,D=E.get(e)??it(/* @__PURE__ */ new Set);for(let i of ee){let a=$e(i);if(D.rawKeys.has(a)||Rt(a,D)){w.set(i,``);continue}let o=Mt(i,d);if(Lt(i,o,D))w.set(i,``);else{if(o.kind===`invalid`)throw Error(`Internal error: unresolved placeholder "${i}" in template "${t}": ${o.reason}`);if(o.kind===`command`){let{scope:t,type:n}=o;if(n===void 0){let n=hn(t,d,h,r,e,L,C,b,y,D);if(n===null){w.set(i,``);continue}w.set(i,wt(n))}else{let a=mn(t,d,h,e,L,C,b,r,y,D);if(a===null){w.set(i,``);continue}let o=Q(a,n,t);w.set(i,o===null?``:wt(o))}}else if(o.kind===`global-options`)V?w.set(i,on(V)):w.set(i,``);else if(o.kind===`index`){let t=await qe(n,[...Zt(p,e,d,r),...Qt(O,e,e,d)],g?.index);w.set(i,t)}}}let k=l.replace(/((?:\r?\n)*)([ \t]*)(\{\{politty:[^{}]*\}\})([ \t]*)((?:\r?\n)*)/g,(e,n,r,i,a,o,s,c)=>{let l=w.get(i);if(l===void 0)throw Error(`Internal error: unresolved placeholder "${i}" in template "${t}".`);let u=n!==``||s===0||c[s-1]===`
90
+ `,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(n===``||o===``)return``;let e=Dt(n),t=Dt(o),r=Math.max(e,t),i=Et(e>=t?n:o);return r>=2?i+i:r===1?i:``}return`${n}${r}${l}${a}${o}`});k=`${k.trimEnd()}${c}`,k=await q(k,a);let A=Ae(k,e),j=`match`,N;A.match||(_?(K(e,k),j=A.fileExists?`updated`:`created`):(B=!0,j=`diff`,A.diff&&(N=A.diff))),z.push({path:e,status:j,diff:N})}if(g){let t=g.path,i=`match`,o=[],s=je(t);if(s===null)B=!0,i=`diff`,o.push(`File does not exist. Cannot validate rootDoc markers.`);else{let c=s,l=!1,u=e.rootInfo,h={title:u?.title??n.name};g.headingLevel!==void 0&&(h.headingLevel=g.headingLevel);let v=u?.description??n.description;v!==void 0&&(h.description=v);let y=_t(c,h,_);if(c=y.content,y.diff&&o.push(y.diff),y.hasError&&(B=!0),y.wasUpdated&&(l=!0),u?.header){let e=await un(c,`Root header`,ne(),re(),u.header,_,a,m);c=e.content,o.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}if(!m){let e=xt(c);if(e.length>0){if(_){for(let t of e)c=Ct(c,t);l=!0}else B=!0,o.push(`Found unexpected section markers in rootDoc: ${e.map(e=>`"${Z(e)}"`).join(`, `)}.`)}}let b=Jt(g.globalOptions);if(b){let e=await ln(c,b,_,a,m);c=e.content,o.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}let x=Zt(p,t,d,r),S=f.relative(process.cwd(),t).replace(/\\/g,`/`),C=await dn(c,x,n,S,_,a,g.index);if(c=C.content,o.push(...C.diffs),C.hasError&&(B=!0),C.wasUpdated&&(l=!0),u?.footer){let e=await un(c,`Root footer`,ie(),ae(),u.footer,_,a,m);c=e.content,o.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}_&&l&&(K(t,c),i===`match`&&(i=`updated`))}o.length>0&&(i=`diff`),z.push({path:t,status:i,diff:o.length>0?o.join(`
91
91
 
92
92
  `):void 0})}return{success:!B,files:z,error:B?`Documentation is out of date. ${y?`Run with ${j}=true ${A}=true to fix missing markers.`:`Run with ${A}=true to update.`}`:void 0}}async function Sn(e){let t=await xn(e);if(!t.success){let e=t.files.filter(e=>e.status===`diff`).map(e=>{let t=`File: ${e.path}\n`;return e.diff&&(t+=e.diff),t}).join(`
93
93
 
94
- `);throw Error(`Documentation does not match golden files.\n\n${e}\n\n`+(t.error??`Run with POLITTY_DOCS_UPDATE=true to update the documentation.`))}}function Cn(e,t){if(Je(`POLITTY_DOCS_UPDATE`)){if(typeof e==`string`)Me(e,t);else{let n=new Set(Object.values(e.templates??{}).map($));e.rootDoc&&n.add($(e.rootDoc.path));let r=e=>n.has($(e));if(e.files)for(let n of Object.keys(e.files))r(n)||Me(n,t);if(e.templates)for(let n of Object.keys(e.templates))r(n)||Me(n,t)}}}export{j as DOCTOR_ENV,I as GLOBAL_OPTIONS_MARKER_PREFIX,B as INDEX_MARKER_PREFIX,z as ROOT_FOOTER_MARKER_PREFIX,R as ROOT_HEADER_MARKER_PREFIX,N as SECTION_MARKER_PREFIX,M as SECTION_TYPES,A as UPDATE_GOLDEN_ENV,Sn as assertDocMatch,Ne as buildCommandInfo,Fe as collectAllCommands,Ae as compareWithExisting,W as createCommandRenderer,ke as defaultRenderers,Ie as executeExamples,G as formatDiff,xn as generateDoc,te as globalOptionsEndMarker,L as globalOptionsStartMarker,oe as indexEndMarker,V as indexStartMarker,Cn as initDocFile,Be as renderArgsTable,de as renderArgumentsList,we as renderArgumentsListFromArray,le as renderArgumentsTable,Ce as renderArgumentsTableFromArray,qe as renderCommandIndex,Ee as renderExamplesDefault,_e as renderOptionsList,U as renderOptionsListFromArray,ge as renderOptionsTable,H as renderOptionsTableFromArray,be as renderSubcommandsTable,Te as renderSubcommandsTableFromArray,ce as renderUsage,c as resolveLazyCommand,ae as rootFooterEndMarker,ie as rootFooterStartMarker,re as rootHeaderEndMarker,ne as rootHeaderStartMarker,F as sectionEndMarker,P as sectionStartMarker,K as writeFile};
94
+ `);throw Error(`Documentation does not match golden files.\n\n${e}\n\n`+(t.error??`Run with POLITTY_DOCS_UPDATE=true to update the documentation.`))}}function Cn(e,t){if(Je(`POLITTY_DOCS_UPDATE`)){if(typeof e==`string`)Me(e,t);else{let n=new Set(Object.values(e.templates??{}).map($));e.rootDoc&&n.add($(e.rootDoc.path));let r=e=>n.has($(e));if(e.files)for(let n of Object.keys(e.files))r(n)||Me(n,t);if(e.templates)for(let n of Object.keys(e.templates))r(n)||Me(n,t)}}}export{j as DOCTOR_ENV,I as GLOBAL_OPTIONS_MARKER_PREFIX,B as INDEX_MARKER_PREFIX,z as ROOT_FOOTER_MARKER_PREFIX,R as ROOT_HEADER_MARKER_PREFIX,N as SECTION_MARKER_PREFIX,M as SECTION_TYPES,A as UPDATE_GOLDEN_ENV,Sn as assertDocMatch,Ne as buildCommandInfo,Fe as collectAllCommands,Ae as compareWithExisting,W as createCommandRenderer,ke as defaultRenderers,Ie as executeExamples,G as formatDiff,xn as generateDoc,te as globalOptionsEndMarker,L as globalOptionsStartMarker,oe as indexEndMarker,V as indexStartMarker,Cn as initDocFile,Be as renderArgsTable,de as renderArgumentsList,we as renderArgumentsListFromArray,le as renderArgumentsTable,Ce as renderArgumentsTableFromArray,qe as renderCommandIndex,Ee as renderExamplesDefault,_e as renderOptionsList,U as renderOptionsListFromArray,ge as renderOptionsTable,H as renderOptionsTableFromArray,be as renderSubcommandsTable,Te as renderSubcommandsTableFromArray,ce as renderUsage,l as resolveLazyCommand,ae as rootFooterEndMarker,ie as rootFooterStartMarker,re as rootHeaderEndMarker,ne as rootHeaderStartMarker,F as sectionEndMarker,P as sectionStartMarker,K as writeFile};
@@ -0,0 +1 @@
1
+ export{t as createDynamicCompleteCommand}from"./dynamic-RKGUiswZ.js";
@@ -1,6 +1,6 @@
1
- import{d as e,p as t}from"./unflatten-DVeO9OZ_.js";import{a as n,n as r,u as i}from"./schema-extractor-Cwg_WAC-.js";import{n as a}from"./command-BXsTrIgI.js";import{c as o,i as s}from"./subcommand-router-40vA6Mka.js";import{n as c,o as l,r as u,s as d,u as f}from"./argv-parser-DVXJQeSu.js";import{t as p}from"./schema-BF9YOHU0.js";import{execSync as m}from"node:child_process";function h(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:_(e.valueCompletion,e.isGlobal===!0,t,n)}}function g(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:_(e.valueCompletion,!1,t,n)}}function _(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function v(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
2
- `?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function y(e){return`'${e.replace(/'/g,`'\\''`)}'`}function b(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function x(e){return e.length===1?`-${e}`:`--${e}`}function S(e,n){C(e,x(n)),n.length===1?C(e,`--${n}`):n.includes(`-`)&&C(e,`--${t(n)}`)}function C(e,t){e.includes(t)||e.push(t)}function w(e,n){let r=[`--${e}`];e.length===1&&r.push(`-${e}`),e.includes(`-`)&&r.push(`--${t(e)}`);for(let e of n??[])S(r,e);return r}function T(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function E(e,n,r,i){let a=new Set(w(e,n));if(r&&(a.add(`--${r}`),r.includes(`-`)&&a.add(`--${t(r)}`)),i?.frameOptions){if(i.isGlobal===!0){for(let e of i.frameOptions)if(e.isGlobal!==!0)for(let t of A(e.cliName,e.alias))a.delete(t)}else{let e=T(i.frameOptions);if(e.size>0){let t=new Set((n??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let n of e)t.has(n)||a.delete(n)}}}return[...a].map(e=>`"${e}"`)}function D(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&E(n.cliName,n.alias,n.negation,{frameOptions:t})})}function O(e,t,n,r=`$_pos_count`){let i=D(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function k(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of O(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function A(e,n){let r=[`--${e}`];e.includes(`-`)&&r.push(`--${t(e)}`);for(let e of n??[])S(r,e);return r}function j(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function M(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?N(e.args):[]}function N(e){return n(r(e)).map(P)}function P(t){let n=e(t);return{name:t.name,cliName:t.cliName,alias:n.length>0?n:void 0,negation:t.negationDisplay,negationDescription:t.negationDescription,description:t.description,takesValue:t.type!==`boolean`,valueType:t.type,required:t.required,defaultNegationAccepted:t.type===`boolean`&&t.negation===!0,valueCompletion:M(j(t))}}function F(e){return new Set(w(e.cliName,e.alias))}function te(e,t){let n=F(t);for(let t of e)for(let e of F(t))if(n.has(e))return t}function ne(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{G(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;if(u(i)){let{isGlobal:s,flags:l,valueOption:u}=z(i,t);if(!s)break;for(let{opt:e}of l)n[e.name]=!0,r.add(e.name);if(u?.value!==void 0)a(u.opt,u.value);else if(u){let t=e[o+1];if(t===void 0)break;c(t)&&(a(u.opt,t),o++)}o++;continue}if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let s=R(i),l=q(t,s);if(!l){if(de(t,s)){o++;continue}break}if(l.takesValue){if(B(i)){let e=i.indexOf(`=`);a(l,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(!c(t)){o++;continue}a(l,t),o+=2}else break}else{let e=V(l,s,i);e!==void 0&&(n[l.name]=e),r.add(l.name),o++}}return r}function re(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function ie(e,t){return t.length===0?e:[...e,...t]}function ae(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function I(e,t){return n=>{let r={...e};return l(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function oe(e,t,n){if(!e.args)return;let a=r(e.args),o=i(a,I(t,n));if(o!==a)return o.fields.filter(e=>e.named).map(P)}function se(e,t,n){if(!e.args)return[];let a=i(r(e.args),I(t,n));return l(a,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:M(j(e))}))}function ce(e){if(!e.subCommands)return[];let t=[];for(let[n,r]of Object.entries(e.subCommands)){if(n.startsWith(`__`))continue;t.push(n);let e=o(r);e?.aliases&&t.push(...e.aliases)}return t}function le(e,t){if(!e.subCommands)return null;let n=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(n)return o(n);let r=s(e,t);return r?o(e.subCommands[r]):null}function L(e){return e.startsWith(`-`)}function R(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function z(e,t){let n=(e,t)=>q(e,{name:t,isLong:!1}),r=t.filter(e=>e.isGlobal!==!0),i=t.filter(e=>e.isGlobal===!0),a=e=>!n(r,e)&&n(i,e)!==void 0,o=d(e.slice(1),e=>a(e)&&n(i,e).takesValue),s=o.flags.every(a),c=s?i:r,{flags:l,valueOption:u}=s?o:d(e.slice(1),e=>n(r,e)?.takesValue===!0);return{isGlobal:s,flags:l.flatMap(e=>{let t=n(c,e);return t?[{opt:t,name:e}]:[]}),valueOption:u&&{opt:n(c,u.name),value:u.value}}}function ue(e,t){let{valueOption:n}=z(e,t);return n?.value===void 0?n?.opt:void 0}function B(e){return e.includes(`=`)}function V(e,t,n){let r=fe(e,t);return B(n)?r?void 0:f(n.slice(n.indexOf(`=`)+1)):!r}function H(e,n,r){if(!r||e.valueType!==`boolean`)return!1;let i=[e.cliName,...e.alias??[]];for(let e of i){let r=`no-${e}`;if(n===r||n===t(r))return!0}return!1}function U(e,t,n){return e.defaultNegationAccepted===!0&&H(e,t,n)}function de(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&H(e,t.name,t.isLong))}function W(e,n){return e!==void 0&&e.includes(`-`)&&t(e)===n}function G(e,t,n,r){if(t.valueType!==`array`)e[t.name]=n;else if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function fe(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||W(e.negation,t.name))?!0:U(e,t.name,t.isLong):!1}function K(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:W(e.cliName,t)||e.alias?.some(e=>W(e,t))?!0:W(e.negation,t)}function q(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&K(e,t.name,t.isLong));if(r)return r}return e.find(e=>K(e,t.name,t.isLong))||e.find(e=>U(e,t.name,t.isLong))}function J(e,t,n){let r=Y(e,t,n);return r.variantOptions?Y(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function Y(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,o=[],s=n?N(n).map(e=>({...e,isGlobal:!0})):[],l=/* @__PURE__ */ new Set,d=!1,f=0,p={},m=[],h={},g=/* @__PURE__ */ new Set,_=0,v=/* @__PURE__ */ new Set,y=e=>{l.add(e.cliName);for(let t of e.alias??[])l.add(t);e.negation&&l.add(e.negation),d=!0},b=(e,t)=>{G(e.isGlobal===!0?h:p,e,t,v)},x=(e,t,n=``)=>{let r=e.isGlobal===!0?h:p,i=V(e,t,n);i!==void 0&&(r[e.name]=i)},S=0,C=ie(i(a),s),w=!1;for(;S<e.length-1;){let t=e[S];if(!w&&t===`--`){w=!0,S++;continue}if(!w&&u(t)){d=!0;let{flags:n,valueOption:r}=z(t,C);for(let{opt:e,name:t}of n)y(e),x(e,{name:t,isLong:!1});r&&(y(r.opt),r.value===void 0?S+1<e.length-1&&c(e[S+1])&&(b(r.opt,e[S+1]),S++):b(r.opt,r.value)),S++;continue}if(!w&&L(t)){d=!0;let n=R(t),r=q(C,n);if(r){if(y(r),r.takesValue){if(B(t)){let e=t.indexOf(`=`);b(r,t.slice(e+1))}else if(S+1<e.length-1){let t=e[S+1];c(t)&&(b(r,t),S++)}}else x(r,n,t)}S++;continue}let n=w?null:le(a,t);if(n){o.push(t);let r=i(a),c=e.slice(_,S);for(let e of ne(c,s,h))g.add(e);a=n,C=ie(i(a),s);for(let e of Object.keys(p)){let t=r.find(t=>t.name===e),n=s.find(t=>t.name===e)??(t?te(s,t):void 0);n&&(g.has(n.name)||(h[n.name]=re(p[e],n)))}l.clear(),f=0,p={},m=[],v=/* @__PURE__ */ new Set,_=S+1,S++}else m.push(t),f++,S++}let T=e[e.length-1]??``,E=e[e.length-2]??``,D=oe(a,p,m),O=se(a,p,m),k=ce(a);for(let e=0;e<O.length;e++){let t=O[e];if(t.variadic){p[t.name]=m.slice(e);break}e<m.length&&(p[t.name]=m[e])}let A,j,M;if(!w&&E&&L(E)&&!B(E)){let e=u(E)?ue(E,C):q(C,R(E));e&&e.takesValue?(A=`option-value`,j=e):T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f),A===`positional`&&(M=f))}else if(!w&&T.startsWith(`-`)&&B(T)){let e=q(C,R(T));e&&e.takesValue?(A=`option-value`,j=e):A=`option-name`}else!w&&T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f,w),A===`positional`&&(M=f));let P=[];if(j){if(j.valueType===`array`){let e=(j.isGlobal===!0?h:p)[j.name];P=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(A===`positional`&&M!==void 0){let e=ae(M,O);e!==void 0&&O[e]?.variadic&&(P=m.slice(e))}let F={...h,...p};return{context:{subcommandPath:o,currentCommand:a,currentWord:T,previousWord:E,completionType:A,targetOption:j,positionalIndex:M,options:C,subcommands:k,positionals:O,usedOptions:l,hasAnyOptionBeenUsed:d,providedPositionalCount:f,parsedArgs:F,previousValues:P},variantOptions:D}}function X(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const Z={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function pe(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function me(e,t){switch(e.completionType){case`subcommand`:return we(e);case`option-name`:return Te(e);case`option-value`:{let n=e.targetOption,r=n?pe(e.currentWord):void 0;return Q(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=he(e);return n?Q(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:Z.NoFileCompletion}}}}function he(e){let t=e.positionalIndex??0,n=ae(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function ge(e){try{return m(e,{encoding:`utf-8`,timeout:5e3}).split(`
3
- `).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function _e(e){return e?.type===`choices`?e.choices:void 0}function ve(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return _e(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return _e(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function ye(e,t){let n=!t.includes(`=`),r=n?be(e):xe(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function be(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function xe(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function Se(e,t,n,r,i){let a=[],o=Z.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=Z.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=Z.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=Z.FileCompletion)):o|=Z.FileCompletion;break;case`directory`:o|=Z.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...ge(e.shellCommand)),o|=Z.NoFileCompletion;break;case`none`:o|=Z.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??Z.FilterPrefix|Z.NoFileCompletion}catch{o=Z.NoFileCompletion|Z.Error}break;case`expand`:o|=Z.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=ve(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=/* @__PURE__ */ new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=Z.NoFileCompletion|Z.Error;break}o|=Z.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=ye(e.type===`runtime-expand`&&i===!0?Ce(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=Z.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function Ce(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function we(e){let t=[];for(let n of e.subcommands){let r=e.currentCommand.subCommands,i=r?.[n],a=i?void 0:s(e.currentCommand,n),c=i??(a?r?.[a]:void 0),l=c?o(c)?.description:void 0;t.push({value:n,description:l,type:`subcommand`})}if(t.length===0||e.currentWord.startsWith(`-`)){let n=Te(e);t.push(...n.candidates)}return{candidates:t,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Te(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Ee(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:De(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function De(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function Q(e,t,n,r,i,a){return r?Se(r,Ee(e,t,n),e,i,a):{candidates:[],directive:Z.FilterPrefix}}function Oe(e,t){switch(t.shell){case`bash`:return ke(e,t);case`zsh`:return Ae(e,t);case`fish`:return je(e,t)}}function $(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function ke(e,t){let n=((e.directive&Z.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return $(n,e),n.join(`
1
+ import{n as e}from"./command-BXsTrIgI.js";import{c as t,i as n}from"./subcommand-router-CfCW9eG4.js";import{a as r,n as i,u as a}from"./schema-extractor-Cwg_WAC-.js";import{n as o,o as s,r as c,s as l,u}from"./argv-parser-bI3e6XXA.js";import{d,p as f}from"./unflatten-DVeO9OZ_.js";import{t as p}from"./schema-BF9YOHU0.js";import{execSync as m}from"node:child_process";function h(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:_(e.valueCompletion,e.isGlobal===!0,t,n)}}function g(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:_(e.valueCompletion,!1,t,n)}}function _(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function v(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
2
+ `?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function y(e){return`'${e.replace(/'/g,`'\\''`)}'`}function b(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function x(e){return e.length===1?`-${e}`:`--${e}`}function S(e,t){C(e,x(t)),t.length===1?C(e,`--${t}`):t.includes(`-`)&&C(e,`--${f(t)}`)}function C(e,t){e.includes(t)||e.push(t)}function w(e,t){let n=[`--${e}`];e.length===1&&n.push(`-${e}`),e.includes(`-`)&&n.push(`--${f(e)}`);for(let e of t??[])S(n,e);return n}function T(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function E(e,t,n,r){let i=new Set(w(e,t));if(n&&(i.add(`--${n}`),n.includes(`-`)&&i.add(`--${f(n)}`)),r?.frameOptions){if(r.isGlobal===!0){for(let e of r.frameOptions)if(e.isGlobal!==!0)for(let t of A(e.cliName,e.alias))i.delete(t)}else{let e=T(r.frameOptions);if(e.size>0){let n=new Set((t??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let t of e)n.has(t)||i.delete(t)}}}return[...i].map(e=>`"${e}"`)}function D(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&E(n.cliName,n.alias,n.negation,{frameOptions:t})})}function O(e,t,n,r=`$_pos_count`){let i=D(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function k(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of O(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function A(e,t){let n=[`--${e}`];e.includes(`-`)&&n.push(`--${f(e)}`);for(let e of t??[])S(n,e);return n}function j(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function M(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?N(e.args):[]}function N(e){return r(i(e)).map(P)}function P(e){let t=d(e);return{name:e.name,cliName:e.cliName,alias:t.length>0?t:void 0,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:e.type===`boolean`&&e.negation===!0,valueCompletion:M(j(e))}}function F(e){return new Set(w(e.cliName,e.alias))}function te(e,t){let n=F(t);for(let t of e)for(let e of F(t))if(n.has(e))return t}function ne(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{G(n,e,t,i),r.add(e.name)},s=0;for(;s<e.length;){let i=e[s];if(i===`--`||!i.startsWith(`-`))break;if(c(i)){let{isGlobal:c,flags:l,valueOption:u}=z(i,t);if(!c)break;for(let{opt:e}of l)n[e.name]=!0,r.add(e.name);if(u?.value!==void 0)a(u.opt,u.value);else if(u){let t=e[s+1];if(t===void 0)break;o(t)&&(a(u.opt,t),s++)}s++;continue}if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let l=R(i),u=q(t,l);if(!u){if(de(t,l)){s++;continue}break}if(u.takesValue){if(B(i)){let e=i.indexOf(`=`);a(u,i.slice(e+1)),s++}else if(s+1<e.length){let t=e[s+1];if(!o(t)){s++;continue}a(u,t),s+=2}else break}else{let e=V(u,l,i);e!==void 0&&(n[u.name]=e),r.add(u.name),s++}}return r}function re(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function ie(e,t){return t.length===0?e:[...e,...t]}function ae(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function I(e,t){return n=>{let r={...e};return s(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function oe(e,t,n){if(!e.args)return;let r=i(e.args),o=a(r,I(t,n));if(o!==r)return o.fields.filter(e=>e.named).map(P)}function se(e,t,n){if(!e.args)return[];let r=a(i(e.args),I(t,n));return s(r,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:M(j(e))}))}function ce(e){if(!e.subCommands)return[];let n=[];for(let[r,i]of Object.entries(e.subCommands)){if(r.startsWith(`__`))continue;n.push(r);let e=t(i);e?.aliases&&n.push(...e.aliases)}return n}function le(e,r){if(!e.subCommands)return null;let i=Object.hasOwn(e.subCommands,r)?e.subCommands[r]:void 0;if(i)return t(i);let a=n(e,r);return a?t(e.subCommands[a]):null}function L(e){return e.startsWith(`-`)}function R(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function z(e,t){let n=(e,t)=>q(e,{name:t,isLong:!1}),r=t.filter(e=>e.isGlobal!==!0),i=t.filter(e=>e.isGlobal===!0),a=e=>!n(r,e)&&n(i,e)!==void 0,o=l(e.slice(1),e=>a(e)&&n(i,e).takesValue),s=o.flags.every(a),c=s?i:r,{flags:u,valueOption:d}=s?o:l(e.slice(1),e=>n(r,e)?.takesValue===!0);return{isGlobal:s,flags:u.flatMap(e=>{let t=n(c,e);return t?[{opt:t,name:e}]:[]}),valueOption:d&&{opt:n(c,d.name),value:d.value}}}function ue(e,t){let{valueOption:n}=z(e,t);return n?.value===void 0?n?.opt:void 0}function B(e){return e.includes(`=`)}function V(e,t,n){let r=fe(e,t);return B(n)?r?void 0:u(n.slice(n.indexOf(`=`)+1)):!r}function H(e,t,n){if(!n||e.valueType!==`boolean`)return!1;let r=[e.cliName,...e.alias??[]];for(let e of r){let n=`no-${e}`;if(t===n||t===f(n))return!0}return!1}function U(e,t,n){return e.defaultNegationAccepted===!0&&H(e,t,n)}function de(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&H(e,t.name,t.isLong))}function W(e,t){return e!==void 0&&e.includes(`-`)&&f(e)===t}function G(e,t,n,r){if(t.valueType!==`array`)e[t.name]=n;else if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function fe(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||W(e.negation,t.name))?!0:U(e,t.name,t.isLong):!1}function K(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:W(e.cliName,t)||e.alias?.some(e=>W(e,t))?!0:W(e.negation,t)}function q(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&K(e,t.name,t.isLong));if(r)return r}return e.find(e=>K(e,t.name,t.isLong))||e.find(e=>U(e,t.name,t.isLong))}function J(e,t,n){let r=Y(e,t,n);return r.variantOptions?Y(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function Y(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,s=[],l=n?N(n).map(e=>({...e,isGlobal:!0})):[],u=/* @__PURE__ */ new Set,d=!1,f=0,p={},m=[],h={},g=/* @__PURE__ */ new Set,_=0,v=/* @__PURE__ */ new Set,y=e=>{u.add(e.cliName);for(let t of e.alias??[])u.add(t);e.negation&&u.add(e.negation),d=!0},b=(e,t)=>{G(e.isGlobal===!0?h:p,e,t,v)},x=(e,t,n=``)=>{let r=e.isGlobal===!0?h:p,i=V(e,t,n);i!==void 0&&(r[e.name]=i)},S=0,C=ie(i(a),l),w=!1;for(;S<e.length-1;){let t=e[S];if(!w&&t===`--`){w=!0,S++;continue}if(!w&&c(t)){d=!0;let{flags:n,valueOption:r}=z(t,C);for(let{opt:e,name:t}of n)y(e),x(e,{name:t,isLong:!1});r&&(y(r.opt),r.value===void 0?S+1<e.length-1&&o(e[S+1])&&(b(r.opt,e[S+1]),S++):b(r.opt,r.value)),S++;continue}if(!w&&L(t)){d=!0;let n=R(t),r=q(C,n);if(r){if(y(r),r.takesValue){if(B(t)){let e=t.indexOf(`=`);b(r,t.slice(e+1))}else if(S+1<e.length-1){let t=e[S+1];o(t)&&(b(r,t),S++)}}else x(r,n,t)}S++;continue}let n=w?null:le(a,t);if(n){s.push(t);let r=i(a),o=e.slice(_,S);for(let e of ne(o,l,h))g.add(e);a=n,C=ie(i(a),l);for(let e of Object.keys(p)){let t=r.find(t=>t.name===e),n=l.find(t=>t.name===e)??(t?te(l,t):void 0);n&&(g.has(n.name)||(h[n.name]=re(p[e],n)))}u.clear(),f=0,p={},m=[],v=/* @__PURE__ */ new Set,_=S+1,S++}else m.push(t),f++,S++}let T=e[e.length-1]??``,E=e[e.length-2]??``,D=oe(a,p,m),O=se(a,p,m),k=ce(a);for(let e=0;e<O.length;e++){let t=O[e];if(t.variadic){p[t.name]=m.slice(e);break}e<m.length&&(p[t.name]=m[e])}let A,j,M;if(!w&&E&&L(E)&&!B(E)){let e=c(E)?ue(E,C):q(C,R(E));e&&e.takesValue?(A=`option-value`,j=e):T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f),A===`positional`&&(M=f))}else if(!w&&T.startsWith(`-`)&&B(T)){let e=q(C,R(T));e&&e.takesValue?(A=`option-value`,j=e):A=`option-name`}else!w&&T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f,w),A===`positional`&&(M=f));let P=[];if(j){if(j.valueType===`array`){let e=(j.isGlobal===!0?h:p)[j.name];P=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(A===`positional`&&M!==void 0){let e=ae(M,O);e!==void 0&&O[e]?.variadic&&(P=m.slice(e))}let F={...h,...p};return{context:{subcommandPath:s,currentCommand:a,currentWord:T,previousWord:E,completionType:A,targetOption:j,positionalIndex:M,options:C,subcommands:k,positionals:O,usedOptions:u,hasAnyOptionBeenUsed:d,providedPositionalCount:f,parsedArgs:F,previousValues:P},variantOptions:D}}function X(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const Z={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function pe(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function me(e,t){switch(e.completionType){case`subcommand`:return we(e);case`option-name`:return Te(e);case`option-value`:{let n=e.targetOption,r=n?pe(e.currentWord):void 0;return Q(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=he(e);return n?Q(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:Z.NoFileCompletion}}}}function he(e){let t=e.positionalIndex??0,n=ae(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function ge(e){try{return m(e,{encoding:`utf-8`,timeout:5e3}).split(`
3
+ `).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function _e(e){return e?.type===`choices`?e.choices:void 0}function ve(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return _e(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return _e(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function ye(e,t){let n=!t.includes(`=`),r=n?be(e):xe(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function be(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function xe(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function Se(e,t,n,r,i){let a=[],o=Z.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=Z.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=Z.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=Z.FileCompletion)):o|=Z.FileCompletion;break;case`directory`:o|=Z.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...ge(e.shellCommand)),o|=Z.NoFileCompletion;break;case`none`:o|=Z.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??Z.FilterPrefix|Z.NoFileCompletion}catch{o=Z.NoFileCompletion|Z.Error}break;case`expand`:o|=Z.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=ve(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=/* @__PURE__ */ new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=Z.NoFileCompletion|Z.Error;break}o|=Z.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=ye(e.type===`runtime-expand`&&i===!0?Ce(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=Z.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function Ce(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function we(e){let r=[];for(let i of e.subcommands){let a=e.currentCommand.subCommands,o=a?.[i],s=o?void 0:n(e.currentCommand,i),c=o??(s?a?.[s]:void 0),l=c?t(c)?.description:void 0;r.push({value:i,description:l,type:`subcommand`})}if(r.length===0||e.currentWord.startsWith(`-`)){let t=Te(e);r.push(...t.candidates)}return{candidates:r,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Te(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Ee(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:De(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function De(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function Q(e,t,n,r,i,a){return r?Se(r,Ee(e,t,n),e,i,a):{candidates:[],directive:Z.FilterPrefix}}function Oe(e,t){switch(t.shell){case`bash`:return ke(e,t);case`zsh`:return Ae(e,t);case`fish`:return je(e,t)}}function $(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function ke(e,t){let n=((e.directive&Z.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return $(n,e),n.join(`
4
4
  `)}function Ae(e,t){let n=e.candidates.map(e=>{let t=e.value.replace(/:/g,`\\:`);return e.description?`${t}:${e.description.replace(/:/g,`\\:`)}`:t});return $(n,e),n.join(`
5
5
  `)}function je(e,t){let n=e.candidates.map(e=>e.description?`${e.value}\t${e.description}`:e.value);return $(n,e),n.join(`
6
- `)}function Me(e,t,n){return a({name:`__complete`,args:p,async run(t){let r=J(t.args,e,n),i=r.completionType===`option-value`&&r.targetOption?pe(r.currentWord):void 0,a=i?r.currentWord.slice(i.length):r.currentWord,o=Oe(await me(r,{shell:t.shell}),{shell:t.shell,currentWord:a,inlinePrefix:i});console.log(o)}})}function Ne(e){return!!e.subCommands?.__complete}export{E as _,me as a,v as c,A as d,D as f,k as g,O as h,Z as i,w as l,g as m,Ne as n,J as o,h as p,Oe as r,j as s,Me as t,T as u,y as v,b as y};
6
+ `)}function Me(t,n,r){return e({name:`__complete`,args:p,async run(e){let n=J(e.args,t,r),i=n.completionType===`option-value`&&n.targetOption?pe(n.currentWord):void 0,a=i?n.currentWord.slice(i.length):n.currentWord,o=Oe(await me(n,{shell:e.shell}),{shell:e.shell,currentWord:a,inlinePrefix:i});console.log(o)}})}function Ne(e){return!!e.subCommands?.__complete}export{E as _,me as a,v as c,A as d,D as f,k as g,O as h,Z as i,w as l,g as m,Ne as n,J as o,h as p,Oe as r,j as s,Me as t,T as u,y as v,b as y};
@@ -0,0 +1,4 @@
1
+ // TypeScript does not read this file. politty's content mapper derives GlobalArgs from the
2
+ // globalArgs schema your entry passes to runMain, so commands get typed global args without
3
+ // createDefineCommand or a hand-written `declare module` augmentation.
4
+ // Enable it in tsconfig.json: "contentMappers": [{ "package": "<this package>", "extensions": [".politty"] }]
@@ -0,0 +1 @@
1
+ export{t as resolve}from"./import-meta-resolve-DQM0bLBb.js";
@@ -0,0 +1,3 @@
1
+ import{builtinModules as e}from"node:module";import t,{realpathSync as n,statSync as r}from"node:fs";import i from"node:path";import{fileURLToPath as a,pathToFileURL as o}from"node:url";import{format as s,inspect as c}from"node:util";import l from"node:assert";import u from"node:process";import d from"node:v8";const f={}.hasOwnProperty,ee=/^([A-Z][a-z\d]*)+$/,te=/* @__PURE__ */ new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),p={};function m(e,t=`and`){return e.length<3?e.join(` ${t} `):`${e.slice(0,-1).join(`, `)}, ${t} ${e[e.length-1]}`}const h=/* @__PURE__ */ new Map;let g;p.ERR_INVALID_ARG_TYPE=_(`ERR_INVALID_ARG_TYPE`,(e,t,n)=>{l.ok(typeof e==`string`,`'name' must be a string`),Array.isArray(t)||(t=[t]);let r=`The `;if(e.endsWith(` argument`))r+=`${e} `;else{let t=e.includes(`.`)?`property`:`argument`;r+=`"${e}" ${t} `}r+=`must be `;let i=[],a=[],o=[];for(let e of t)l.ok(typeof e==`string`,`All expected entries have to be of type string`),te.has(e)?i.push(e.toLowerCase()):ee.exec(e)===null?(l.ok(e!==`object`,`The value "object" should be written as "Object"`),o.push(e)):a.push(e);if(a.length>0){let e=i.indexOf(`object`);e!==-1&&(i.slice(e,1),a.push(`Object`))}return i.length>0&&(r+=`${i.length>1?`one of type`:`of type`} ${m(i,`or`)}`,(a.length>0||o.length>0)&&(r+=` or `)),a.length>0&&(r+=`an instance of ${m(a,`or`)}`,o.length>0&&(r+=` or `)),o.length>0&&(o.length>1?r+=`one of ${m(o,`or`)}`:(o[0].toLowerCase()!==o[0]&&(r+=`an `),r+=`${o[0]}`)),r+=`. Received ${y(n)}`,r},TypeError),p.ERR_INVALID_MODULE_SPECIFIER=_(`ERR_INVALID_MODULE_SPECIFIER`,(e,t,n=void 0)=>`Invalid module "${e}" ${t}${n?` imported from ${n}`:``}`,TypeError),p.ERR_INVALID_PACKAGE_CONFIG=_(`ERR_INVALID_PACKAGE_CONFIG`,(e,t,n)=>`Invalid package config ${e}${t?` while importing ${t}`:``}${n?`. ${n}`:``}`,Error),p.ERR_INVALID_PACKAGE_TARGET=_(`ERR_INVALID_PACKAGE_TARGET`,(e,t,n,r=!1,i=void 0)=>{let a=typeof n==`string`&&!r&&n.length>0&&!n.startsWith(`./`);return t===`.`?(l.ok(r===!1),`Invalid "exports" main target ${JSON.stringify(n)} defined in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`):`Invalid "${r?`imports`:`exports`}" target ${JSON.stringify(n)} defined for '${t}' in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`},Error),p.ERR_MODULE_NOT_FOUND=_(`ERR_MODULE_NOT_FOUND`,(e,t,n=!1)=>`Cannot find ${n?`module`:`package`} '${e}' imported from ${t}`,Error),p.ERR_NETWORK_IMPORT_DISALLOWED=_(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error),p.ERR_PACKAGE_IMPORT_NOT_DEFINED=_(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(e,t,n)=>`Package import specifier "${e}" is not defined${t?` in package ${t}package.json`:``} imported from ${n}`,TypeError),p.ERR_PACKAGE_PATH_NOT_EXPORTED=_(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(e,t,n=void 0)=>t===`.`?`No "exports" main defined in ${e}package.json${n?` imported from ${n}`:``}`:`Package subpath '${t}' is not defined by "exports" in ${e}package.json${n?` imported from ${n}`:``}`,Error),p.ERR_UNSUPPORTED_DIR_IMPORT=_(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),p.ERR_UNSUPPORTED_RESOLVE_REQUEST=_(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),p.ERR_UNKNOWN_FILE_EXTENSION=_(`ERR_UNKNOWN_FILE_EXTENSION`,(e,t)=>`Unknown file extension "${e}" for ${t}`,TypeError),p.ERR_INVALID_ARG_VALUE=_(`ERR_INVALID_ARG_VALUE`,(e,t,n=`is invalid`)=>{let r=c(t);return r.length>128&&(r=`${r.slice(0,128)}...`),`The ${e.includes(`.`)?`property`:`argument`} '${e}' ${n}. Received ${r}`},TypeError);function _(e,t,n){return h.set(e,t),ne(n,e)}function ne(e,t){return n;function n(...n){let r=Error.stackTraceLimit;v()&&(Error.stackTraceLimit=0);let i=new e;v()&&(Error.stackTraceLimit=r);let a=ae(t,n,i);return Object.defineProperties(i,{message:{value:a,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),ie(i),i.code=t,i}}function v(){try{if(d.startupSnapshot.isBuildingSnapshot())return!1}catch{}let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):f.call(e,`writable`)&&e.writable!==void 0?e.writable:e.set!==void 0}function re(e){let t=`__node_internal_`+e.name;return Object.defineProperty(e,"name",{value:t}),e}const ie=re(function(e){let t=v();return t&&(g=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(e),t&&(Error.stackTraceLimit=g),e});function ae(e,t,n){let r=h.get(e);if(l.ok(r!==void 0,"expected `message` to be found"),typeof r==`function`)return l.ok(r.length<=t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${r.length}).`),Reflect.apply(r,n,t);let i=/%[dfijoOs]/g,a=0;for(;i.exec(r)!==null;)a++;return l.ok(a===t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${a}).`),t.length===0?r:(t.unshift(r),Reflect.apply(s,null,t))}function y(e){if(e==null)return String(e);if(typeof e==`function`&&e.name)return`function ${e.name}`;if(typeof e==`object`)return e.constructor&&e.constructor.name?`an instance of ${e.constructor.name}`:`${c(e,{depth:-1})}`;let t=c(e,{colors:!1});return t.length>28&&(t=`${t.slice(0,25)}...`),`type ${typeof e} (${t})`}const b={}.hasOwnProperty,{ERR_INVALID_PACKAGE_CONFIG:oe}=p,x=/* @__PURE__ */ new Map;function S(e,{base:n,specifier:r}){let o=x.get(e);if(o)return o;let s;try{s=t.readFileSync(i.toNamespacedPath(e),`utf8`)}catch(e){let t=e;if(t.code!==`ENOENT`)throw t}let c={exists:!1,pjsonPath:e,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(s!==void 0){let t;try{t=JSON.parse(s)}catch(t){let i=t,o=new oe(e,(n?`"${r}" from `:``)+a(n||r),i.message);throw o.cause=i,o}c.exists=!0,b.call(t,`name`)&&typeof t.name==`string`&&(c.name=t.name),b.call(t,`main`)&&typeof t.main==`string`&&(c.main=t.main),b.call(t,`exports`)&&(c.exports=t.exports),b.call(t,`imports`)&&(c.imports=t.imports),b.call(t,`type`)&&(t.type===`commonjs`||t.type===`module`)&&(c.type=t.type)}return x.set(e,c),c}function C(e){let t=new URL(`package.json`,e);for(;!t.pathname.endsWith(`node_modules/package.json`);){let n=S(a(t),{specifier:e});if(n.exists)return n;let r=t;if(t=new URL(`../package.json`,t),t.pathname===r.pathname)break}return{pjsonPath:a(t),exists:!1,type:`none`}}function w(e){return C(e).type}const{ERR_UNKNOWN_FILE_EXTENSION:se}=p,ce={}.hasOwnProperty,le={__proto__:null,".cjs":`commonjs`,".js":`module`,".json":`json`,".mjs":`module`};function ue(e){return e&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(e)?`module`:e===`application/json`?`json`:null}const T={__proto__:null,"data:":de,"file:":pe,"http:":E,"https:":E,"node:"(){return`builtin`}};function de(e){let{1:t}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(e.pathname)||[null,null,null];return ue(t)}function fe(e){let t=e.pathname,n=t.length;for(;n--;){let e=t.codePointAt(n);if(e===47)return``;if(e===46)return t.codePointAt(n-1)===47?``:t.slice(n)}return``}function pe(e,t,n){let r=fe(e);if(r===`.js`){let t=w(e);return t===`none`?`commonjs`:t}if(r===``){let t=w(e);return t===`none`||t===`commonjs`?`commonjs`:`module`}let i=le[r];if(i)return i;if(n)return;let o=a(e);throw new se(r,o)}function E(){}function D(e,t){let n=e.protocol;return ce.call(T,n)&&T[n](e,t,!0)||null}const{ERR_INVALID_ARG_VALUE:me}=p,O=Object.freeze([`node`,`import`]),he=new Set(O);function ge(){return O}function _e(){return he}function k(e){if(e!==void 0&&e!==ge()){if(!Array.isArray(e))throw new me(`conditions`,e,`expected an array`);return new Set(e)}return _e()}const A=RegExp.prototype[Symbol.replace],{ERR_NETWORK_IMPORT_DISALLOWED:j,ERR_INVALID_MODULE_SPECIFIER:M,ERR_INVALID_PACKAGE_CONFIG:N,ERR_INVALID_PACKAGE_TARGET:ve,ERR_MODULE_NOT_FOUND:P,ERR_PACKAGE_IMPORT_NOT_DEFINED:F,ERR_PACKAGE_PATH_NOT_EXPORTED:ye,ERR_UNSUPPORTED_DIR_IMPORT:be,ERR_UNSUPPORTED_RESOLVE_REQUEST:I}=p,L={}.hasOwnProperty,R=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,z=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,xe=/^\.|%|\\/,B=/\*/g,Se=/%2f|%5c/i,V=/* @__PURE__ */ new Set,Ce=/[/\\]{2}/;function H(e,t,n,r,i,o,s){if(u.noDeprecation)return;let c=a(r),l=Ce.exec(s?e:t)!==null;u.emitWarning(`Use of deprecated ${l?`double slash`:`leading or trailing slash matching`} resolving "${e}" for module request "${t}" ${t===n?``:`matched to "${n}" `}in the "${i?`imports`:`exports`}" field module resolution of the package at ${c}${o?` imported from ${a(o)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function U(e,t,n,r){if(u.noDeprecation||D(e,{parentURL:n.href})!==`module`)return;let o=a(e.href),s=a(new URL(`.`,t)),c=a(n);r?i.resolve(s,r)!==o&&u.emitWarning(`Package ${s} has a "main" field set to "${r}", excluding the full filename and extension to the resolved file at "${o.slice(s.length)}", imported from ${c}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):u.emitWarning(`No "main" or "exports" field defined in the package.json for ${s} resolving the main entry point "${o.slice(s.length)}", imported from ${c}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function W(e){try{return r(e)}catch{}}function G(e){let t=r(e,{throwIfNoEntry:!1});return(t?t.isFile():void 0)??!1}function we(e,t,n){let r;if(t.main!==void 0){if(r=new URL(t.main,e),G(r))return r;let i=[`./${t.main}.js`,`./${t.main}.json`,`./${t.main}.node`,`./${t.main}/index.js`,`./${t.main}/index.json`,`./${t.main}/index.node`],a=-1;for(;++a<i.length&&(r=new URL(i[a],e),!G(r));)r=void 0;if(r)return U(r,e,n,t.main),r}let i=[`./index.js`,`./index.json`,`./index.node`],o=-1;for(;++o<i.length&&(r=new URL(i[o],e),!G(r));)r=void 0;if(r)return U(r,e,n,t.main),r;throw new P(a(new URL(`.`,e)),a(n))}function Te(e,t,r){if(Se.exec(e.pathname)!==null)throw new M(e.pathname,`must not include encoded "/" or "\\" characters`,a(t));let s;try{s=a(e)}catch(n){let r=n;throw Object.defineProperty(r,"input",{value:String(e)}),Object.defineProperty(r,"module",{value:String(t)}),r}let c=W(s.endsWith(`/`)?s.slice(-1):s);if(c&&c.isDirectory()){let n=new be(s,a(t));throw n.url=String(e),n}if(!c||!c.isFile()){let n=new P(s||e.pathname,t&&a(t),!0);throw n.url=String(e),n}if(!r){let t=n(s),{search:r,hash:a}=e;e=o(t+(s.endsWith(i.sep)?`/`:``)),e.search=r,e.hash=a}return e}function Ee(e,t,n){return new F(e,t&&a(new URL(`.`,t)),a(n))}function K(e,t,n){return new ye(a(new URL(`.`,t)),e,n&&a(n))}function De(e,t,n,r,i){let o=`request is not a valid match in pattern "${t}" for the "${r?`imports`:`exports`}" resolution of ${a(n)}`;throw new M(e,o,i&&a(i))}function q(e,t,n,r,i){return t=typeof t==`object`&&t?JSON.stringify(t,null,``):`${t}`,new ve(a(new URL(`.`,n)),e,t,r,i&&a(i))}function Oe(e,t,n,r,i,a,o,s,c){if(t!==``&&!a&&e[e.length-1]!==`/`)throw q(n,e,r,o,i);if(!e.startsWith(`./`)){if(o&&!e.startsWith(`../`)&&!e.startsWith(`/`)){let n=!1;try{new URL(e),n=!0}catch{}if(!n)return Z(a?A.call(B,e,()=>t):e+t,r,c)}throw q(n,e,r,o,i)}if(R.exec(e.slice(2))!==null){if(z.exec(e.slice(2))===null){if(!s){let s=a?n.replace(`*`,()=>t):n+t;H(a?A.call(B,e,()=>t):e,s,n,r,o,i,!0)}}else throw q(n,e,r,o,i)}let l=new URL(e,r),u=l.pathname,d=new URL(`.`,r).pathname;if(!u.startsWith(d))throw q(n,e,r,o,i);if(t===``)return l;if(R.exec(t)!==null){let c=a?n.replace(`*`,()=>t):n+t;z.exec(t)===null?s||H(a?A.call(B,e,()=>t):e,c,n,r,o,i,!1):De(c,n,r,o,i)}return a?new URL(A.call(B,l.href,()=>t)):new URL(t,l)}function ke(e){let t=Number(e);return`${t}`===e&&t>=0&&t<4294967295}function J(e,t,n,r,i,o,s,c,l){if(typeof t==`string`)return Oe(t,n,r,e,i,o,s,c,l);if(Array.isArray(t)){let a=t;if(a.length===0)return null;let u,d=-1;for(;++d<a.length;){let t=a[d],f;try{f=J(e,t,n,r,i,o,s,c,l)}catch(e){let t=e;if(u=t,t.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw e}if(f!==void 0){if(f===null)u=null;else return f}}if(u==null)return null;throw u}if(typeof t==`object`&&t){let u=Object.getOwnPropertyNames(t),d=-1;for(;++d<u.length;){let t=u[d];if(ke(t))throw new N(a(e),i,`"exports" cannot contain numeric property keys.`)}for(d=-1;++d<u.length;){let a=u[d];if(a==="default"||l&&l.has(a)){let u=t[a],d=J(e,u,n,r,i,o,s,c,l);if(d===void 0)continue;return d}}return null}if(t===null)return null;throw q(r,t,e,s,i)}function Ae(e,t,n){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let r=Object.getOwnPropertyNames(e),i=!1,o=0,s=-1;for(;++s<r.length;){let e=r[s],c=e===``||e[0]!==`.`;if(o++===0)i=c;else if(i!==c)throw new N(a(t),n,`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return i}function je(e,t,n){if(u.noDeprecation)return;let r=a(t);V.has(r+`|`+e)||(V.add(r+`|`+e),u.emitWarning(`Use of deprecated trailing slash pattern mapping "${e}" in the "exports" field module resolution of the package at ${r}${n?` imported from ${a(n)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function Y(e,t,n,r,i){let a=n.exports;if(Ae(a,e,r)&&(a={".":a}),L.call(a,t)&&!t.includes(`*`)&&!t.endsWith(`/`)){let n=a[t],o=J(e,n,``,t,r,!1,!1,!1,i);if(o==null)throw K(t,e,r);return o}let o=``,s=``,c=Object.getOwnPropertyNames(a),l=-1;for(;++l<c.length;){let n=c[l],i=n.indexOf(`*`);if(i!==-1&&t.startsWith(n.slice(0,i))){t.endsWith(`/`)&&je(t,e,r);let a=n.slice(i+1);t.length>=n.length&&t.endsWith(a)&&X(o,n)===1&&n.lastIndexOf(`*`)===i&&(o=n,s=t.slice(i,t.length-a.length))}}if(o){let n=a[o],c=J(e,n,s,o,r,!0,!1,t.endsWith(`/`),i);if(c==null)throw K(t,e,r);return c}throw K(t,e,r)}function X(e,t){let n=e.indexOf(`*`),r=t.indexOf(`*`),i=n===-1?e.length:n+1,a=r===-1?t.length:r+1;return i>a?-1:a>i||n===-1?1:r===-1||e.length>t.length?-1:+(t.length>e.length)}function Me(e,t,n){if(e===`#`||e.startsWith(`#/`)||e.endsWith(`/`))throw new M(e,`is not a valid internal imports specifier name`,a(t));let r,i=C(t);if(i.exists){r=o(i.pjsonPath);let a=i.imports;if(a){if(L.call(a,e)&&!e.includes(`*`)){let i=J(r,a[e],``,e,t,!1,!0,!1,n);if(i!=null)return i}else{let i=``,o=``,s=Object.getOwnPropertyNames(a),c=-1;for(;++c<s.length;){let t=s[c],n=t.indexOf(`*`);if(n!==-1&&e.startsWith(t.slice(0,-1))){let r=t.slice(n+1);e.length>=t.length&&e.endsWith(r)&&X(i,t)===1&&t.lastIndexOf(`*`)===n&&(i=t,o=e.slice(n,e.length-r.length))}}if(i){let e=a[i],s=J(r,e,o,i,t,!0,!0,!1,n);if(s!=null)return s}}}}throw Ee(e,r,t)}function Ne(e,t){let n=e.indexOf(`/`),r=!0,i=!1;e[0]===`@`&&(i=!0,n===-1||e.length===0?r=!1:n=e.indexOf(`/`,n+1));let o=n===-1?e:e.slice(0,n);if(xe.exec(o)!==null&&(r=!1),!r)throw new M(e,`is not a valid package name`,a(t));return{packageName:o,packageSubpath:`.`+(n===-1?``:e.slice(n)),isScoped:i}}function Z(t,n,r){if(e.includes(t))return new URL(`node:`+t);let{packageName:i,packageSubpath:s,isScoped:c}=Ne(t,n),l=C(n);
2
+ /* c8 ignore next 16 */
3
+ if(l.exists){let e=o(l.pjsonPath);if(l.name===i&&l.exports!==void 0&&l.exports!==null)return Y(e,s,l,n,r)}let u=new URL(`./node_modules/`+i+`/package.json`,n),d=a(u),f;do{let e=W(d.slice(0,-13));if(!e||!e.isDirectory()){f=d,u=new URL((c?`../../../../node_modules/`:`../../../node_modules/`)+i+`/package.json`,u),d=a(u);continue}let o=S(d,{base:n,specifier:t});return o.exports!==void 0&&o.exports!==null?Y(u,s,o,n,r):s===`.`?we(u,o,n):new URL(s,u)}while(d.length!==f.length);throw new P(i,a(n),!1)}function Pe(e){return!(e[0]!==`.`||e.length!==1&&e[1]!==`/`&&(e[1]!==`.`||e.length!==2&&e[2]!==`/`))}function Q(e){return e===``?!1:e[0]===`/`||Pe(e)}function $(t,n,r,i){r===void 0&&(r=k());let a=n.protocol,o=a===`data:`||a===`http:`||a===`https:`,s;if(Q(t))try{s=new URL(t,n)}catch(e){let r=new I(t,n);throw r.cause=e,r}else if(a===`file:`&&t[0]===`#`)s=Me(t,n,r);else try{s=new URL(t)}catch(i){if(o&&!e.includes(t)){let e=new I(t,n);throw e.cause=i,e}s=Z(t,n,r)}return l.ok(s!==void 0,`expected to be defined`),s.protocol===`file:`?Te(s,n,i):s}function Fe(t,n,r){if(r){let i=r.protocol;if(i===`http:`||i===`https:`){if(Q(t)){let e=n?.protocol;if(e&&e!==`https:`&&e!==`http:`)throw new j(t,r,`remote imports cannot import from a local location.`);return{url:n?.href||``}}throw e.includes(t)?new j(t,r,`remote imports cannot import from a local location.`):new j(t,r,`only relative and absolute specifiers are supported.`)}}}function Ie(e){return!!(e&&typeof e==`object`&&`href`in e&&typeof e.href==`string`&&`protocol`in e&&typeof e.protocol==`string`&&e.href&&e.protocol)}function Le(e){if(e!==void 0&&typeof e!=`string`&&!Ie(e))throw new p.ERR_INVALID_ARG_TYPE(`parentURL`,[`string`,`URL`],e)}function Re(e,t={}){let{parentURL:n}=t;l.ok(n!==void 0,"expected `parentURL` to be defined"),Le(n);let r;if(n)try{r=new URL(n)}catch{}let i,a;try{if(i=Q(e)?new URL(e,r):new URL(e),a=i.protocol,a===`data:`)return{url:i.href,format:null}}catch{}let o=Fe(e,i,r);if(o)return o;if(a===void 0&&i&&(a=i.protocol),a===`node:`||i&&i.protocol===`node:`)return{url:e};let s=k(t.conditions),c=$(e,new URL(n),s,!1);return{url:c.href,format:D(c,{parentURL:n})}}function ze(e,t){if(!t)throw Error("Please pass `parent`: `import-meta-resolve` cannot ponyfill that");try{return Re(e,{parentURL:t}).url}catch(e){let t=e;if((t.code===`ERR_UNSUPPORTED_DIR_IMPORT`||t.code===`ERR_MODULE_NOT_FOUND`)&&typeof t.url==`string`)return t.url;throw e}}export{$ as n,ze as t};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,20 @@
1
- import { r as KnownAgentId, t as AgentInfo } from "./detect-agent-hU93hctO.js";
1
+ // @ts-ignore
2
+ import "./global-args.politty";
3
+ /**
4
+ * @politty/valibot - politty with valibot schemas
5
+ *
6
+ * The user-facing entry point for building politty CLIs with valibot:
7
+ * installs the valibot validator adapter into `@politty/core` and
8
+ * re-exports the core API, with the schema-taking functions re-pinned to
9
+ * valibot's `GenericSchema` so a schema from another Standard Schema
10
+ * library is rejected at the type level instead of failing at runtime in
11
+ * the registered adapter.
12
+ *
13
+ * @packageDocumentation
14
+ */
2
15
  import { $ as PromptType, A as SubCommandValue, B as toKebabCase, C as RunCommandOptions, D as RunResultSuccess, E as RunResultFailure, F as lazy, G as CompletionMeta, H as UnflattenOptions, I as ExtractedFields, J as EffectContext, K as CompletionType, L as ResolvedFieldMeta, M as UnknownSubcommandHandler, N as LazyCommand, O as RunnableCommand, P as isLazyCommand, Q as PromptMeta, R as UnknownKeysMode, S as PromptResolverContext, T as RunResult, U as ArgFn, V as Unflatten, W as ArgMeta, X as PromptChoicesContext, Y as PromptChoices, Z as PromptChoicesResolver, _ as LogStream, a as ArgsSchema$1, at as DynamicCompletionCandidate, b as NonRunnableCommand, c as Command, ct as DynamicCompletionResult, d as GlobalArgs, dt as InferSchemaOutput, et as ValidateArgMeta, f as GlobalCleanupContext, ft as SchemaLike, g as LogLevel, h as LogEntry, i as ArgSource, it as CompletionDirectiveMask, j as SubCommandsRecord, k as SetupContext, l as CommandBase, lt as PackageRequirement, m as IsEmpty, n as AgentHelpContext, nt as ExpandCompletion, o as CleanupContext, ot as DynamicCompletionContext, p as GlobalSetupContext, q as CustomCompletion, r as AnyCommand, rt as ResolvedExpandCandidate, s as CollectedLogs, st as DynamicCompletionResolver, t as AgentHelp, tt as ExpandCandidate, u as Example, ut as loadPackage, v as Logger, w as RunInvocation, x as PromptResolver, y as MainOptions, z as toCamelCase } from "./types-DItR4zZu.js";
3
16
  import { _ as CompletionResult, g as CompletionOptions, i as GenerateBundledCompletionWorkerResult, n as withCompletionCommand, r as GenerateBundledCompletionWorkerOptions, t as WithCompletionOptions, x as InternalArgsSchema } from "./with-completion-command-c3Re1EXL.js";
17
+ import { r as KnownAgentId, t as AgentInfo } from "./detect-agent-hU93hctO.js";
4
18
  import * as v from "valibot";
5
19
  import { GenericSchema } from "valibot";
6
20
  /**
@@ -340,6 +354,37 @@ interface NonRunnableConfig<TArgsSchema extends ArgsSchema$1 | undefined, TGloba
340
354
  */
341
355
  defaultSubCommand?: DefaultSubCommandKey<TSubCommands> | undefined;
342
356
  }
357
+ interface EnvFileRequest {
358
+ path: string;
359
+ ifExists: boolean;
360
+ }
361
+ export declare class EnvFileNotFoundError extends Error {
362
+ constructor(envPath: string);
363
+ }
364
+ interface LoadEnvFilesFromArgsOptions {
365
+ /** Command-line arguments to read. Defaults to `process.argv.slice(2)`. */
366
+ argv?: readonly string[];
367
+ }
368
+ /**
369
+ * Load env files into `process.env` with the semantics of Node.js
370
+ * `--env-file`: a later file overrides an earlier one, and a variable that was
371
+ * already set before the first file was read is left alone.
372
+ *
373
+ * Pass the requests to load, or the `globalArgs` schema to load the files its
374
+ * `envFile` options name on the command line. The second form reads every
375
+ * `envFile` option wherever it sits in `argv`, so a CLI can load the files
376
+ * before it hands the arguments to a plugin that politty does not parse. Files
377
+ * load in option declaration order, then in the order given on the command
378
+ * line. Nothing after `--` is read, and no file is read when help or the
379
+ * version is requested. A bundle of short flags counts only when every option
380
+ * in it is defined in `globalArgs`, so `-fe file` is skipped when `-f` is a
381
+ * plugin's own flag.
382
+ *
383
+ * A missing required file throws {@link EnvFileNotFoundError} and applies no
384
+ * file.
385
+ */
386
+ export declare function loadEnvFiles(requests: readonly EnvFileRequest[]): void;
387
+ export declare function loadEnvFiles(globalArgs: ArgsSchema$1, options?: LoadEnvFilesFromArgsOptions): void;
343
388
  /**
344
389
  * Run a command with the given arguments (programmatic/test usage)
345
390
  *
@@ -1099,4 +1144,4 @@ export type ArgsSchema = GenericSchema<unknown, Record<string, any>>;
1099
1144
  export declare const defineCommand: DefineCommandFn<ArgsSchema>;
1100
1145
  export declare const createDefineCommand: CreateDefineCommandFn<ArgsSchema>;
1101
1146
  export declare const arg: ArgFn<GenericSchema<unknown, unknown>>;
1102
- export { type AgentHelp, type AgentHelpContext, type AgentInfo, type AnyCommand, type ArgFn, type ArgMeta, type ArgSource, type BoundDefineCommandFn, type BuiltinOptionDescriptions, type CamelCase, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CreateDefineCommandFn, type CustomCompletion, type DefineCommandFn, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GenerateCompileCacheShimOptions, type GenerateCompileCacheShimResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpData, type HelpDataOptions, type HelpFieldData, type HelpOptions, type HelpSubcommandData, type HelpUsageData, type HelpVariantData, type InferSchemaOutput, type KebabCase, type KnownAgentId, type LazyCommand, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type PackageRequirement, type ParsedArgv, type ParserOptions, type PromptChoices, type PromptChoicesContext, type PromptChoicesResolver, type PromptMeta, type PromptResolver, type PromptResolverContext, type PromptType, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunInvocation, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SchemaLike, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidateArgMeta, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, isLazyCommand, lazy, loadPackage, toCamelCase, toKebabCase, withCompletionCommand };
1147
+ export { type AgentHelp, type AgentHelpContext, type AgentInfo, type AnyCommand, type ArgFn, type ArgMeta, type ArgSource, type BoundDefineCommandFn, type BuiltinOptionDescriptions, type CamelCase, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CreateDefineCommandFn, type CustomCompletion, type DefineCommandFn, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type EnvFileRequest, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GenerateCompileCacheShimOptions, type GenerateCompileCacheShimResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpData, type HelpDataOptions, type HelpFieldData, type HelpOptions, type HelpSubcommandData, type HelpUsageData, type HelpVariantData, type InferSchemaOutput, type KebabCase, type KnownAgentId, type LazyCommand, type LoadEnvFilesFromArgsOptions, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type PackageRequirement, type ParsedArgv, type ParserOptions, type PromptChoices, type PromptChoicesContext, type PromptChoicesResolver, type PromptMeta, type PromptResolver, type PromptResolverContext, type PromptType, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunInvocation, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SchemaLike, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidateArgMeta, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, isLazyCommand, lazy, loadPackage, toCamelCase, toKebabCase, withCompletionCommand };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,c as t,m as n,o as r,p as i,t as a}from"./unflatten-DVeO9OZ_.js";import{t as o}from"./register-ZdhcM-o7.js";import{i as s,n as c}from"./schema-extractor-Cwg_WAC-.js";import{n as l,t as u}from"./cli-main-I1ZrqkyB.js";import{n as d,t as f}from"./command-BXsTrIgI.js";import{d as p,o as m,s as h}from"./subcommand-router-40vA6Mka.js";import{C as g,D as _,E as v,O as y,S as b,T as x,_ as S,a as C,b as w,c as T,d as E,f as D,g as O,h as k,i as ee,l as A,m as j,n as M,o as N,p as P,r as F,s as I,t as L,u as R,v as z,w as B,x as V,y as H}from"./runner-BpOAXgAg.js";import{a as U,i as W,n as G,r as K,t as q}from"./logger-CoeDrmRr.js";import{a as J}from"./argv-parser-DVXJQeSu.js";import{t as Y}from"./with-completion-command-DkZmjiSe.js";import*as X from"valibot";function Z(n,i={}){let o=e(i);a(Object.keys(n.entries),i);let s=X.pipe(n,X.rawTransform(({dataset:e,addIssue:n,NEVER:r})=>{let i=t(e.value,o);if(!i.issues)return i.value;for(let t of i.issues){let r=t.path[0];n({message:t.message,path:[{type:`object`,origin:`value`,input:e.value,key:r,value:e.value[r]}]})}return r}));return r(s,i)}const Q=l(`@politty/valibot`),$=d,te=f,ne=o;export{O as CaseVariantCollisionError,S as DefaultSubCommandError,z as DuplicateAliasError,H as DuplicateFieldError,w as DuplicateNegationError,V as FieldTypeConflictError,b as PositionalConfigError,g as ReservedAliasError,B as ReservedFieldNameError,ne as arg,l as createCompileCacheShimGenerator,te as createDefineCommand,F as createDualCaseProxy,$ as defineCommand,c as extractFields,C as formatCommandValidationErrors,ee as formatValidationErrors,Q as generateCompileCacheShim,x as generateHelp,v as generateHelpData,s as getUnknownKeysMode,q as isColorEnabled,m as isLazyCommand,h as lazy,p as loadPackage,G as logger,J as parseArgv,_ as renderInline,y as renderMarkdown,L as runCommand,M as runMain,u as runPolittyCli,K as setColorEnabled,W as styles,U as symbols,i as toCamelCase,n as toKebabCase,Z as unflatten,N as validateCaseVariantCollisions,I as validateCommand,T as validateCrossSchemaCollisions,A as validateDefaultSubCommand,R as validateDuplicateAliases,E as validateDuplicateFields,D as validateDuplicateNegations,P as validatePositionalConfig,j as validateReservedAliases,k as validateReservedFieldNames,Y as withCompletionCommand};
1
+ import{t as e}from"./register-ZdhcM-o7.js";import{n as t,t as n}from"./cli-main-wqT-qsdF.js";import{i as r,n as i}from"./schema-extractor-Cwg_WAC-.js";import{t as a}from"./with-completion-command-BojrmP1a.js";import{n as o,t as s}from"./command-BXsTrIgI.js";import{d as c,o as l,s as u}from"./subcommand-router-CfCW9eG4.js";import{A as d,C as f,D as p,E as m,O as h,S as g,T as _,_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,i as E,k as D,l as O,m as k,n as A,o as ee,p as j,r as M,s as N,t as P,u as F,v as I,w as L,x as R,y as z}from"./runner-DiDJDnhR.js";import{a as B,i as V,n as H,r as U,t as W}from"./logger-CoeDrmRr.js";import{a as G}from"./argv-parser-bI3e6XXA.js";import{a as K,c as q,m as J,o as Y,p as X,t as Z}from"./unflatten-DVeO9OZ_.js";import*as Q from"valibot";function $(e,t={}){let n=K(t);Z(Object.keys(e.entries),t);let r=Q.pipe(e,Q.rawTransform(({dataset:e,addIssue:t,NEVER:r})=>{let i=q(e.value,n);if(!i.issues)return i.value;for(let n of i.issues){let r=n.path[0];t({message:n.message,path:[{type:`object`,origin:`value`,input:e.value,key:r,value:e.value[r]}]})}return r}));return Y(r,t)}const te=t(`@politty/valibot`),ne=o,re=s,ie=e;export{I as CaseVariantCollisionError,z as DefaultSubCommandError,b as DuplicateAliasError,R as DuplicateFieldError,g as DuplicateNegationError,M as EnvFileNotFoundError,f as FieldTypeConflictError,L as PositionalConfigError,_ as ReservedAliasError,m as ReservedFieldNameError,ie as arg,t as createCompileCacheShimGenerator,re as createDefineCommand,y as createDualCaseProxy,ne as defineCommand,i as extractFields,N as formatCommandValidationErrors,ee as formatValidationErrors,te as generateCompileCacheShim,p as generateHelp,h as generateHelpData,r as getUnknownKeysMode,W as isColorEnabled,l as isLazyCommand,u as lazy,E as loadEnvFiles,c as loadPackage,H as logger,G as parseArgv,D as renderInline,d as renderMarkdown,P as runCommand,A as runMain,n as runPolittyCli,U as setColorEnabled,V as styles,B as symbols,X as toCamelCase,J as toKebabCase,$ as unflatten,x as validateCaseVariantCollisions,O as validateCommand,F as validateCrossSchemaCollisions,S as validateDefaultSubCommand,C as validateDuplicateAliases,j as validateDuplicateFields,k as validateDuplicateNegations,T as validatePositionalConfig,w as validateReservedAliases,v as validateReservedFieldNames,a as withCompletionCommand};