@politty/zod 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{arg-registry-DdEs3jd0.d.ts → arg-registry-Dvi0co21.d.ts} +9 -2
- package/dist/argv-parser-DZQ0qnXG.js +1 -0
- package/dist/augment.d.ts +4 -2
- package/dist/cli-main-BX5IVgNq.js +1 -0
- package/dist/{cli-main-DWQYfxFO.js → cli-main-uRzr666k.js} +2 -2
- package/dist/cli-run-DtG5fM18.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/completion-8frPuaX8.js +1 -0
- package/dist/completion-OvSe3W9y.js +116 -0
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +47 -47
- package/dist/dynamic-4uRohypH.js +6 -0
- package/dist/dynamic-C5e2NuDv.js +1 -0
- package/dist/{field-meta-D7G8a7IG.js → field-meta-_l-FHbh7.js} +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/{register-D0mDOOyc.js → register-BXOytPt7.js} +1 -1
- package/dist/runner-BTD1-gUd.js +30 -0
- package/dist/runner-BTF0HIGj.js +1 -0
- package/dist/{schema-ohwvrBGz.js → schema-DhMPssIJ.js} +1 -1
- package/dist/{schema-extractor-QpSHJvwI.js → schema-extractor-Du9ipDD4.js} +1 -1
- package/dist/skill.d.ts +3 -3
- package/dist/skill.js +2 -2
- package/dist/{with-completion-command-Bi7v_Wlq.d.ts → with-completion-command-BKHwbzEc.d.ts} +1 -1
- package/dist/{with-completion-command-CZ9qcezN.js → with-completion-command-CQcqFHq8.js} +2 -2
- package/package.json +2 -2
- package/dist/cli-main-X_a3vjMI.js +0 -1
- package/dist/cli-run-BfhO1D3b.js +0 -1
- package/dist/completion-CDwNvtfE.js +0 -1
- package/dist/completion-DwBjO-3Q.js +0 -116
- package/dist/dynamic-BBr42fJH.js +0 -1
- package/dist/dynamic-BK6Tq_FR.js +0 -6
- package/dist/runner-DPQ3GQA7.js +0 -1
- package/dist/runner-DtJbfhOs.js +0 -30
package/dist/docs.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import{o as e}from"./field-meta-
|
|
2
|
-
`)}function
|
|
3
|
-
`)}const
|
|
4
|
-
`)}function V(e){if(e.positionalArgs.length===0)return``;let t=[];for(let n of e.positionalArgs){let e=n.required?`(required)`:`(optional)`,r=n.description?` - ${m(n.description)}`:``;t.push(`- \`${n.name}\`${r} ${e}`)}return t.join(`
|
|
5
|
-
`)}function ae(e){return C(p(e.options))}function oe(e){return w(p(e.options))}function se(e){return e.join(`-`).toLowerCase()}function ce(e,t){let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`);return s.posix.relative(s.posix.dirname(n),r)}function le(e,t=!0){return me(e.subCommands,e,t)}function H(e){return C(p(e))}function ue(e,t=`table`){let n=e.unionOptions??[];if(n.length===0)return``;let r=[],i=new Set;for(let e of n)for(let t of e.fields)i.add(t.name);let a=new Set;for(let e of i)n.every(t=>t.fields.some(t=>t.name===e))&&a.add(e);let o=e.fields.filter(e=>a.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 i=n[e];if(!i)continue;let o=i.fields.filter(e=>!a.has(e.name)&&!e.positional),s=i.description??`Variant ${e+1}`;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(`
|
|
1
|
+
import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";import{c as t,n,o as r,r as i,s as a,t as o}from"./schema-extractor-Du9ipDD4.js";import{t as s}from"./log-collector-DICKib75.js";import{r as c}from"./subcommand-router-D8GTMXYL.js";import*as l from"node:fs";import*as u from"node:path";import d from"node:path";import{isDeepStrictEqual as f}from"node:util";const p=[`option`,`alias`,`description`,`required`,`default`];function m(e){return`(↔ \`--${e.cliName}\`)`}function h(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function g(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${h(e)}>`}function _(e){let t=g(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:m(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 v(e){return e.map(_)}function y(e){return e.replace(/\r?\n/g,`<br>`)}function b(e){return y(e.replace(/\|/g,`\\|`))}function x(e){return`\`${e}\``}function S(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function C(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 ee(e,t){switch(t){case`option`:{let t=x(e.longFlag);return e.inlineNegation?`${t} / ${x(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(x).join(`, `):`-`;case`description`:return b(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return S(e);case`env`:return C(e.env)}}function E(e,t){switch(t){case`option`:return x(e.flag);case`description`:return`${b(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function D(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...p,`env`]:p),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=>ee(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>E(t.negationRow,e)).join(` | `)} |`);return r.join(`
|
|
2
|
+
`)}function O(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(x).join(`, `);n.inlineNegation&&(i+=` / ${x(n.inlineNegation)}`);let a=n.description?` - ${y(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(`- ${x(n.negationRow.flag)} - ${y(n.negationRow.description)} ${n.negationRow.relationMarker}`)}return t.join(`
|
|
3
|
+
`)}const k=`POLITTY_DOCS_UPDATE`,A=`POLITTY_DOCS_DOCTOR`,j=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],M=`politty:command`;function N(e,t){return`<!-- ${M}:${t}:${e}:start -->`}function P(e,t){return`<!-- ${M}:${t}:${e}:end -->`}const F=`politty:global-options`;function I(){return`<!-- ${F}:start -->`}function te(){return`<!-- ${F}:end -->`}const L=`politty:root-header`;function ne(){return`<!-- ${L}:start -->`}function re(){return`<!-- ${L}:end -->`}const R=`politty:root-footer`;function ie(){return`<!-- ${R}:start -->`}function ae(){return`<!-- ${R}:end -->`}const z=`politty:index`;function B(e){return`<!-- ${z}:${e}:start -->`}function oe(e){return`<!-- ${z}:${e}:end -->`}function se(e){return y(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}\`, \`${g(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?o(r):void 0,a=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)&&a.has(e.name));n.length>0&&s.push(`${e.label}\n\n${t(n)}`)}return s.join(`
|
|
6
4
|
|
|
7
|
-
`)}function
|
|
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 D(v(e.options))}function _e(e){return O(v(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 V(e){return D(v(e))}function xe(e,t=`table`){let n=e.unionOptions??[];if(n.length===0)return``;let r=[],i=o(n),a=e.fields.filter(e=>i.has(e.name)&&!e.positional);a.length>0&&r.push(t===`table`?V(a):H(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`?V(o):H(o);r.push(`${s}\n\n${c}`)}return r.join(`
|
|
8
6
|
|
|
9
|
-
`)}function
|
|
10
|
-
`)}function pe(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.required?`(required)`:`(optional)`,r=n.description?` - ${m(n.description)}`:``;t.push(`- \`${n.name}\`${r} ${e}`)}return t.join(`
|
|
11
|
-
`)}function me(e,t,n=!0){if(e.length===0)return``;let r=e.some(e=>e.aliases&&e.aliases.length>0),i=[];r?(i.push(`| Command | Aliases | Description |`),i.push(`|---------|---------|-------------|`)):(i.push(`| Command | Description |`),i.push(`|---------|-------------|`));let a=t.filePath,o=t.fileMap;for(let t of e){let e=t.fullPath.join(` `),s=R(t.description??``),c=t.fullPath.join(` `),l=r?t.aliases&&t.aliases.length>0?t.aliases.map(e=>`\`${R(e)}\``).join(`, `):`-`:``,u;if(n){let n=se(t.fullPath),r=o!==void 0&&Object.prototype.hasOwnProperty.call(o,c),i=r?o[c]:void 0;u=a&&i&&a!==i?`[\`${e}\`](${ce(a,i)}#${n})`:o&&!r?`\`${e}\``:`[\`${e}\`](#${n})`}else u=`\`${e}\``;r?i.push(`| ${u} | ${l} | ${s} |`):i.push(`| ${u} | ${s} |`)}return i.join(`
|
|
12
|
-
`)}function he(e,t,n){if(e.length===0)return``;let r=n?.showOutput??!0,i=n?.commandPrefix?`${n.commandPrefix} `:``,a=[];for(let n=0;n<e.length;n++){let o=e[n];if(!o)continue;let s=t?.[n];a.push(`**${o.desc}**`),a.push(``),a.push("```bash"),a.push(`$ ${i}${o.cmd}`),r&&(s?(s.stdout&&a.push(s.stdout),s.stderr&&a.push(`[stderr] ${s.stderr}`)):o.output&&a.push(o.output)),a.push("```"),a.push(``)}for(;a.length>0&&a[a.length-1]===``;)a.pop();return a.join(`
|
|
13
|
-
`)}function ge(e,t,n){return`${k(e,t)}\n${n}\n${A(e,t)}`}function _e(e){return!e.hasGlobalOptions||e.commandPath===``?null:`See [Global Options](${e.rootDocPath&&e.filePath&&e.filePath!==e.rootDocPath?`${ce(e.filePath,e.rootDocPath)}#global-options`:`#global-options`}) for options available to all commands.`}function W(e={}){let{headingLevel:t=1,optionStyle:n=`table`,generateAnchors:r=!0,includeSubcommandDetails:i=!0,markerless:a=!1,renderDescription:o,renderUsage:s,renderArguments:c,renderOptions:l,renderSubcommands:u,renderNotes:d,renderFooter:f,renderExamples:p}=e,m=a?(e,t,n)=>n:ge;return e=>{let a=[],h=e.commandPath,g=Math.min(t+(e.depth-1),6),_=`#`.repeat(g),v=e.commandPath||e.name;a.push(m(`heading`,h,`${_} ${v}`));{let t=[];if(e.description&&t.push(e.description),e.aliases&&e.aliases.length>0&&t.push(`**Aliases:** ${e.aliases.map(e=>`\`${e}\``).join(`, `)}`),t.length>0){let n={content:t.join(`
|
|
7
|
+
`)}function Se(e,t=`table`){let n=e.discriminator,i=e.variants??[];if(!n||i.length===0)return``;let a=[],s=o(i,n),c=r(e,n),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&&a.push(t===`table`?V(u):H(u));for(let e of i){let r=e.fields.filter(e=>e.name!==n&&!s.has(e.name)&&!e.positional);if(r.length===0)continue;let i=me(n,e),o=t===`table`?V(r):H(r);a.push(`${i}\n\n${o}`)}return a.join(`
|
|
14
8
|
|
|
15
|
-
`)
|
|
9
|
+
`)}function H(e){return O(v(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
|
+
`)}function we(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.required?`(required)`:`(optional)`,r=n.description?` - ${y(n.description)}`:``;t.push(`- ${ue(n)}${r} ${e}`)}return t.join(`
|
|
11
|
+
`)}function Te(e,t,n=!0){if(e.length===0)return``;let r=e.some(e=>e.aliases&&e.aliases.length>0),i=[];r?(i.push(`| Command | Aliases | Description |`),i.push(`|---------|---------|-------------|`)):(i.push(`| Command | Description |`),i.push(`|---------|-------------|`));let a=t.filePath,o=t.fileMap;for(let t of e){let e=t.fullPath.join(` `),s=se(t.description??``),c=t.fullPath.join(` `),l=r?t.aliases&&t.aliases.length>0?t.aliases.map(e=>`\`${se(e)}\``).join(`, `):`-`:``,u;if(n){let n=ve(t.fullPath),r=o!==void 0&&Object.prototype.hasOwnProperty.call(o,c),i=r?o[c]:void 0;u=a&&i&&a!==i?`[\`${e}\`](${ye(a,i)}#${n})`:o&&!r?`\`${e}\``:`[\`${e}\`](#${n})`}else u=`\`${e}\``;r?i.push(`| ${u} | ${l} | ${s} |`):i.push(`| ${u} | ${s} |`)}return i.join(`
|
|
12
|
+
`)}function Ee(e,t,n){if(e.length===0)return``;let r=n?.showOutput??!0,i=n?.commandPrefix?`${n.commandPrefix} `:``,a=[];for(let n=0;n<e.length;n++){let o=e[n];if(!o)continue;let s=t?.[n];a.push(`**${o.desc}**`),a.push(``),a.push("```bash"),a.push(`$ ${i}${o.cmd}`),r&&(s?(s.stdout&&a.push(s.stdout),s.stderr&&a.push(`[stderr] ${s.stderr}`)):o.output&&a.push(o.output)),a.push("```"),a.push(``)}for(;a.length>0&&a[a.length-1]===``;)a.pop();return a.join(`
|
|
13
|
+
`)}function De(e,t,n){return`${N(e,t)}\n${n}\n${P(e,t)}`}function Oe(e){return!e.hasGlobalOptions||e.commandPath===``?null:`See [Global Options](${e.rootDocPath&&e.filePath&&e.filePath!==e.rootDocPath?`${ye(e.filePath,e.rootDocPath)}#global-options`:`#global-options`}) for options available to all commands.`}function U(e={}){let{headingLevel:t=1,optionStyle:n=`table`,generateAnchors:r=!0,includeSubcommandDetails:i=!0,markerless:a=!1,renderDescription:o,renderUsage:s,renderArguments:c,renderOptions:l,renderSubcommands:u,renderNotes:d,renderFooter:f,renderExamples:p}=e,m=a?(e,t,n)=>n:De;return e=>{let a=[],h=e.commandPath,g=Math.min(t+(e.depth-1),6),_=`#`.repeat(g),v=e.commandPath||e.name;a.push(m(`heading`,h,`${_} ${v}`));{let t=[];if(e.description&&t.push(e.description),e.aliases&&e.aliases.length>0&&t.push(`**Aliases:** ${e.aliases.map(e=>`\`${e}\``).join(`, `)}`),t.length>0){let n={content:t.join(`
|
|
14
|
+
|
|
15
|
+
`),heading:``,info:e},r=o?o(n):n.content;r&&a.push(m(`description`,h,r))}}{let t={content:`**Usage**\n\n\`\`\`\n${ce(e)}\n\`\`\``,heading:`**Usage**`,info:e},n=s?s(t):t.content;n&&a.push(m(`usage`,h,n))}if(e.positionalArgs.length>0){let t=(t,r)=>{let i=r?.style??n,a=r?.withHeading??!0,o=i===`table`?Ce:we,s=pe(e.extracted).length>0?fe(e,o,t):o(t);return a?`**Arguments**\n\n${s}`:s},r={args:e.positionalArgs,render:t,heading:`**Arguments**`,info:e},i=c?c(r):t(r.args);i&&a.push(m(`arguments`,h,i))}if(e.options.length>0){let t=(t,r)=>{let i=r?.style??n,a=r?.withHeading??!0,o=e.extracted,s;return s=o&&(o.schemaType===`union`||o.schemaType===`xor`)&&o.unionOptions?xe(o,i):o&&o.schemaType===`discriminatedUnion`&&o.discriminator?Se(o,i):i===`table`?V(t):H(t),a?`**Options**\n\n${s}`:s},r={options:e.options,render:t,heading:`**Options**`,info:e},i=l?l(r):t(r.options);i&&a.push(m(`options`,h,i))}{let t=Oe(e);t&&a.push(m(`global-options-link`,h,t))}if(e.subCommands.length>0){let t=r&&i,n=(n,r)=>{let i=r?.generateAnchors??t,a=r?.withHeading??!0,o=Te(n,e,i);return a?`**Commands**\n\n${o}`:o},o={subcommands:e.subCommands,render:n,heading:`**Commands**`,info:e},s=u?u(o):n(o.subcommands);s&&a.push(m(`subcommands`,h,s))}if(e.examples&&e.examples.length>0){let t=(t,n,r)=>{let i=r?.withHeading??!0,a=Ee(t,n,{commandPrefix:e.fullCommandPath,...r});return i?`**Examples**\n\n${a}`:a},n={examples:e.examples,results:e.exampleResults,render:t,heading:`**Examples**`,info:e},r=p?p(n):t(n.examples,n.results);r&&a.push(m(`examples`,h,r))}if(e.notes){let t={content:`**Notes**\n\n${e.notes}`,heading:`**Notes**`,info:e},n=d?d(t):t.content;n&&a.push(m(`notes`,h,n))}{let t={content:``,heading:``,info:e},n=f?f(t):t.content;n&&a.push(n)}return a.join(`
|
|
16
16
|
|
|
17
17
|
`)+`
|
|
18
|
-
`}}const
|
|
18
|
+
`}}const ke={command:e=>U(e),tableStyle:U({optionStyle:`table`}),listStyle:U({optionStyle:`list`})};function Ae(e,t){let n=u.resolve(t);if(!l.existsSync(n))return{match:!1,fileExists:!1};let r=l.readFileSync(n,`utf-8`);return e===r?{match:!0,fileExists:!0}:{match:!1,diff:W(r,e),fileExists:!0}}function W(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
|
|
21
|
+
`)}function G(e,t){let n=u.resolve(e),r=u.dirname(n);l.existsSync(r)||l.mkdirSync(r,{recursive:!0}),l.writeFileSync(n,t,`utf-8`)}function je(e){let t=u.resolve(e);return l.existsSync(t)?l.readFileSync(t,`utf-8`):null}function Me(e,t=l){let n=u.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,n,r=[]){let o=i(e),s=o?t(o):[],l=o?a(o):[],u=[];if(e.subCommands)for(let[t,n]of Object.entries(e.subCommands)){let e=await c(n),i=[...r,t];u.push({name:t,description:e.description,aliases:e.aliases,fullPath:i})}return{name:e.name??``,description:e.description,aliases:e.aliases,fullCommandPath:r.length>0?`${n} ${r.join(` `)}`:n,commandPath:r.join(` `),depth:r.length+1,positionalArgs:s,options:l,subCommands:u,extracted:o,command:e,notes:e.notes,examples:e.examples}}async function Pe(e,t){let n=t??e.name??`command`,r=new Map;async function i(e,t){let a=await Ne(e,n,t),o=t.join(` `);if(r.set(o,a),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await c(r),[...t,n])}return await i(e,[]),r}async function Fe(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Ie(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Ie(e,t,n){let r=Le(e.cmd),i=[...n,...r],a=s({passthrough:!1});a.start();let o=!0;try{let{runCommand:e}=await import(`./runner-BTF0HIGj.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 c=a.getLogs(),l=c.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
|
|
22
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:
|
|
24
|
-
`)}async function
|
|
23
|
+
`);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:l,stderr:u,success:o}}function Le(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 Re(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t))}function ze(e,t){let n=Re(e).filter(e=>!e.positional);return n.length===0?``:D(v(n),t?.columns)}function Be(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function Ve(e){return e.replace(/\s+/g,`-`).toLowerCase()}function He(e){return e.subCommands.length===0}function Ue(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function We(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(He(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(He(a)||!n)&&r.push(e)}}return r}function Ge(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:We(e.commands,t,r),s=o,c=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=>Ue(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)&&!He(i))continue;let o=n||i.name,s=Ve(o),l=Be(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
|
|
24
|
+
`)}async function Ke(e,t,n){let r=n?.headingLevel??3,i=n?.leafOnly??!0,a=await Pe(e),o=[];for(let e of t){let t=Ge(e,a,r,i);o.push(t)}return o.join(`
|
|
25
25
|
|
|
26
|
-
`)}async function
|
|
26
|
+
`)}async function K(e,t){if(!t)return e;let n=await t(e);return!e.endsWith(`
|
|
27
27
|
`)&&n.endsWith(`
|
|
28
|
-
`)?n.slice(0,-1):n}function
|
|
29
|
-
`);n.push(r??``)}return null}function
|
|
30
|
-
- `)}`)}function
|
|
31
|
-
`)}function
|
|
28
|
+
`)?n.slice(0,-1):n}function qe(e){let t=process.env[e];return t===`true`||t===`1`}function Je(e){let t=e.split(/\r?\n/);if(t[0]!==`---`)return null;let n=[];for(let e=1;e<t.length;e++){let r=t[e];if(r===`---`||r===`...`)return n.join(`
|
|
29
|
+
`);n.push(r??``)}return null}function Ye(e){let t=Et(e),n=e.split(/\r?\n/);if(n[0]!==`---`)return e;let r=-1;for(let e=1;e<n.length;e++){let t=n[e];if(t===`---`||t===`...`){r=e;break}}if(r===-1)return e;let i=n.slice(1,r),a=[];for(let e=0;e<i.length;e++){let t=i[e]??``;if(!/^politty\s*:\s*(.*)$/.test(t)){a.push(t);continue}for(;e+1<i.length;){let t=i[e+1]??``;if(t.trim()!==``&&!t.startsWith(` `)&&!t.startsWith(` `))break;e++}}let o=n.slice(r+1);return a.some(e=>e.trim()!==``)?[`---`,...a,n[r]??`---`,...o].join(t):o.join(t).replace(RegExp(`^${t}`),``)}function Xe(e){let t=e.trim();return t.length>=2&&(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))?t.slice(1,-1):t}function Ze(e){let t=Xe(e);if(t===``)return null;let n=t.match(/^\{\{politty:([^{}]*)\}\}$/);return n?t=n[1]??``:t.startsWith(`politty:`)&&(t=t.slice(8)),t===``?null:t}function Qe(e){return e.slice(2,-2).slice(8)}function $e(e){let t=e.trim();return!t.startsWith(`[`)||!t.endsWith(`]`)?[t]:t.slice(1,-1).split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function et(e,t){let n=Ze(t);n!==null&&e.add(n)}function tt(e){let t=new Set,n=Je(e);if(n===null)return t;let r=!1,i=!1,a=0;for(let e of n.split(/\r?\n/)){let n=e.trim();if(n===``||n.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){r=(o[1]?.trim()??``)===``,i=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){r=!1,i=!1;continue}if(!r)continue;let s=e.match(/^(\s+)(?:exclude|excludes)\s*:\s*(.*)$/);if(s){let e=s[2]?.trim()??``;if(e===``)i=!0,a=s[1]?.length??0;else{i=!1;for(let n of $e(e))et(t,n)}continue}if(!i)continue;let c=e.match(/^(\s*)-\s*(.+)$/);if(!c||(c[1]?.length??0)<=a){i=!1;continue}et(t,c[2]??``)}return t}function nt(e){let t=Je(e);if(t===null)return{};let n=!1,r=!1,i=0,a={};for(let e of t.split(/\r?\n/)){let t=e.trim();if(t===``||t.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){n=(o[1]?.trim()??``)===``,r=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){n=!1,r=!1;continue}if(!n)continue;let s=e.match(/^(\s+)index\s*:\s*(.*)$/);if(s){r=(s[2]?.trim()??``)===``,i=s[1]?.length??0;continue}if(!r)continue;if((e.match(/^(\s*)/)?.[1]?.length??0)<=i){r=!1;continue}let c=e.match(/^\s+(title|description)\s*:\s*(.+)$/);if(!c)continue;let l=c[1],u=Xe(c[2]??``);l===`title`?a.title=u:l===`description`&&(a.description=u)}return a}function rt(e){return{rawKeys:e,commandScopes:new Set,commandSections:new Map,globalOptions:!1,index:!1}}function it(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function at(e){if(Array.isArray(e))return{commands:e};if(!(`commands`in e)||!Array.isArray(e.commands))throw Error(`Invalid file config: object form must include a "commands" array. Use [] to skip generation intentionally.`);return e}function q(e,t){return t===``||e===t||e.startsWith(t+` `)}function J(e){return e.includes(`*`)}function ot(e,t){let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);if(n.length!==r.length)return!1;for(let e=0;e<r.length;e++){let t=r[e],i=n[e];if(t!==`*`&&t!==i)return!1}return!0}function st(e,t){let n=[];for(let r of t.keys())ot(r,e)&&n.push(r);return n}function ct(e,t){if(J(t)){if(ot(e,t))return!0;let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);return n.length>r.length&&ot(n.slice(0,r.length).join(` `),t)}return q(e,t)}function lt(e,t){let n=new Set,r=e.flatMap(e=>J(e)?st(e,t):[e]);for(let e of r)for(let r of t.keys())q(r,e)&&n.add(r);return Array.from(n)}function ut(e,t){return e.filter(e=>!t.some(t=>ct(e,t)))}function dt(e,t){let n=[];for(let r of e)J(r)?n.push(...st(r,t)):t.has(r)&&n.push(r);return n}function Y(e,t,n){let r=at(e),i=r.commands;return{fileConfig:r,specifiedCommands:i,commandPaths:ut(r.noExpand?i.filter(e=>t.has(e)):lt(i,t),n),topLevelCommands:ut(dt(i,t),n)}}function ft(e,t,n){let r=[];for(let i of e){let e=J(i)?st(i,n):[i];for(let n of e)for(let e of t)J(e)?ot(n,e)&&r.push(`"${n}" is both in files and ignored by "${e}"`):(n===e||q(n,e))&&r.push(`"${n}" is both in files and ignored by "${e}"`)}if(r.length>0)throw Error(`Conflict between files and ignores:\n - ${r.join(`
|
|
30
|
+
- `)}`)}function pt(e,t){let n=[];for(let r of e)J(r)?st(r,t).length===0&&n.push(`"${r}"`):t.has(r)||n.push(`"${r}"`);if(n.length>0)throw Error(`Ignored command paths do not exist: ${n.join(`, `)}`)}function mt(e,t){let n=new Set(e),r=t.filter(e=>n.has(e));for(let t of e)(t===``?0:t.split(` `).length)===1&&!r.includes(t)&&r.push(t);let i=[],a=new Set;function o(t){if(a.has(t)||!n.has(t))return;a.add(t),i.push(t);let r=e.filter(e=>e===t||a.has(e)?!1:t===``?e.split(` `).length===1:e.startsWith(t+` `)&&e.split(` `).length===t.split(` `).length+1).sort((e,t)=>e.localeCompare(t));for(let e of r)o(e)}for(let e of r)o(e);for(let t of e)a.has(t)||i.push(t);return i}function ht(e){if(!e.title&&!e.description)return null;let t=[];if(e.title){let n=`#`.repeat(e.headingLevel??1);t.push(`${n} ${e.title}`)}return e.description&&(t.push(``),t.push(e.description)),t.push(``),t.join(`
|
|
31
|
+
`)}function gt(e){if(!/^#{1,6} /.test(e))return null;let t=e.indexOf(`
|
|
32
32
|
`);if(t===-1)return e;let n=t+1;for(e[n]===`
|
|
33
33
|
`&&(n+=1);n<e.length;){let t=e.indexOf(`
|
|
34
|
-
`,n),r=t===-1?e.slice(n):e.slice(n,t);if(r.length===0||/^#{1,6}\s/.test(r)||r.startsWith(`<!-- politty:`))break;n=t===-1?e.length:t+1}return e.slice(0,n)}function
|
|
34
|
+
`,n),r=t===-1?e.slice(n):e.slice(n,t);if(r.length===0||/^#{1,6}\s/.test(r)||r.startsWith(`<!-- politty:`))break;n=t===-1?e.length:t+1}return e.slice(0,n)}function _t(e,t,n){let r=ht(t);if(!r||e.startsWith(r))return{content:e,hasError:!1,wasUpdated:!1};let i=gt(e)??``;return n?{content:`${r}${(i?e.slice(i.length):e).replace(/^\n+/,``)}`,hasError:!1,wasUpdated:!0}:{content:e,diff:W(i,r),hasError:!0,wasUpdated:!1}}function X(e){return e===``?`<root>`:e}function Z(e,t,n){return Vt(e,N(t,n),P(t,n))}function vt(e,t,n,r){return Ht(e,N(t,n),P(t,n),r)}function yt(e,t,n,r){let i=j.indexOf(t),a=N(t,n),o=P(t,n),s=null;for(let t=i-1;t>=0;t--){let r=j[t],i=P(r,n),a=e.indexOf(i);if(a!==-1){s=a+i.length;break}}let c=null;for(let t=i+1;t<j.length;t++){let r=j[t],i=N(r,n),a=e.indexOf(i);if(a!==-1){c=a;break}}if(s!=null&&c!=null){let t=a+e.slice(s,c).replace(/^\n+/,`
|
|
35
35
|
`).replace(/\n+$/,`
|
|
36
36
|
`)+o;return e.slice(0,s)+`
|
|
37
37
|
|
|
@@ -48,47 +48,47 @@ import{o as e}from"./field-meta-D7G8a7IG.js";import"./register-D0mDOOyc.js";impo
|
|
|
48
48
|
|
|
49
49
|
`;return e.slice(0,t)+n+r+`
|
|
50
50
|
|
|
51
|
-
`+e.slice(c)}throw Error(`No insertion point found for section "${t}" (scope="${n}"). This should be unreachable when at least one marker exists for the command.`)}function
|
|
51
|
+
`+e.slice(c)}throw Error(`No insertion point found for section "${t}" (scope="${n}"). This should be unreachable when at least one marker exists for the command.`)}function bt(e,t){let n=[];for(let r of j)Z(e,r,t)!==null&&n.push(r);return n}function xt(e){let t=j.join(`|`),n=RegExp(`<!--\\s*politty:command:(.*?):(?:${t}):start\\s*-->`,`g`),r=new Set;for(let t of e.matchAll(n))r.add(t[1]??``);return Array.from(r)}function St(e,t,n,r){let i=r.indexOf(t);if(i===-1)return e.trimEnd()+`
|
|
52
52
|
|
|
53
53
|
`+n+`
|
|
54
|
-
`;for(let t=i+1;t<r.length;t++){let i=r[t];if(i===void 0)continue;let a=
|
|
54
|
+
`;for(let t=i+1;t<r.length;t++){let i=r[t];if(i===void 0)continue;let a=N(`heading`,i),o=e.indexOf(a);if(o!==-1){let t=o;for(;t>0&&e[t-1]===`
|
|
55
55
|
`;)t--;return t<o&&t++,e.slice(0,t)+n+`
|
|
56
|
-
`+e.slice(o)}}for(let t=i-1;t>=0;t--){let i=r[t];if(i===void 0)continue;let a=
|
|
56
|
+
`+e.slice(o)}}for(let t=i-1;t>=0;t--){let i=r[t];if(i===void 0)continue;let a=bt(e,i);if(a.length>0){let t=a[a.length-1],r=P(t,i),o=e.indexOf(r);if(o!==-1){let t=o+r.length;return e.slice(0,t)+`
|
|
57
57
|
`+n+e.slice(t)}}}return e.trimEnd()+`
|
|
58
58
|
`+n+`
|
|
59
|
-
`}function
|
|
59
|
+
`}function Ct(e,t){let n=bt(e,t);for(let r of n){let n=N(r,t),i=P(r,t),a=e.indexOf(n);for(;a!==-1;){let t=e.indexOf(i,a);if(t===-1)break;e=e.slice(0,a)+e.slice(t+i.length),a=e.indexOf(n,a)}}return e=e.replace(/\n{3,}/g,`
|
|
60
60
|
|
|
61
|
-
`),e}function
|
|
61
|
+
`),e}function wt(e){let t=Tt(e.split(`
|
|
62
62
|
`).filter(e=>!/^<!-- politty:.*-->$/.test(e.trim())).join(`
|
|
63
|
-
`));return t=t.replace(/^\n+/,``).replace(/\n+$/,``),t}function
|
|
63
|
+
`));return t=t.replace(/^\n+/,``).replace(/\n+$/,``),t}function Tt(e){let t=e.split(`
|
|
64
64
|
`),n=[],r=!1,i=0;for(let e of t){let t=e.trim();if(t.startsWith("```")||t.startsWith(`~~~`)){r=!r,i=0,n.push(e);continue}if(!r&&e.trim()===``){if(i++,i>=2)continue}else r||(i=0);n.push(e)}return n.join(`
|
|
65
|
-
`)}function
|
|
65
|
+
`)}function Et(e){return e.includes(`\r
|
|
66
66
|
`)?`\r
|
|
67
67
|
`:`
|
|
68
|
-
`}function
|
|
68
|
+
`}function Dt(e){return(e.match(/\n/g)??[]).length}function Ot(e){return j.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 "${X(i)}". Valid section types: ${j.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=rt(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=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 Q(e,t){for(let n of t)if(q(e,n))return!0;return!1}function Pt(e,t,n){return Q(e,n.commandScopes)?!0:n.commandSections.get(e)?.has(t)??!1}function Ft(e,t,n,r){return mt(ut(lt([e],t),n).filter(e=>!Q(e,r.commandScopes)),[e])}function It(e,t,n){return n.rawKeys.has(Qe(e))?!0:t.kind===`command`?Q(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 Lt(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 Rt=/\{\{politty:[^{}]*\}\}/g;function zt(e,t){let n=new Set;for(let r of e.matchAll(Rt)){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
|
|
71
|
-
- `)}`)}function
|
|
72
|
-
`)}function
|
|
73
|
-
`)}async function
|
|
74
|
-
`)}function $(e){return
|
|
70
|
+
`)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Bt(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 "${X(r)}". Valid section types: ${j.join(`, `)}`}function Vt(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 Ht(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 Ut(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 Wt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Ut(e.args)}function Gt(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t)).filter(e=>!e.positional)}function Kt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return f(r,a)}function qt(e){if(e)return Wt(e)?e:{args:e}}function Jt(e){if(!e)return;let t=n(e).fields.filter(e=>!e.positional);if(t.length!==0)return Object.fromEntries(t.map(e=>[e.name,e.schema]))}function Yt(e){let t=new Map;if(!e?.globalOptions)return t;let n=qt(e.globalOptions);if(!n)return t;for(let e of Gt(n.args))t.set(e.name,e);return t}function Xt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=Y(o,n,r);if(e.length===0)continue;let c=`./`+u.relative(u.dirname(t),a).replace(/\\/g,`/`),l=e[0],d=l===void 0?void 0:n.get(l),f=Array.isArray(o)?void 0:o;i.push({title:f?.title??d?.name??u.basename(a,u.extname(a)),description:f?.description??d?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Zt(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=`./`+u.relative(u.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??u.basename(t,u.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function Qt(e,t,n){let r=new Set;for(let i of Object.values(e)){let{commandPaths:e}=Y(i,t,n);for(let t of e)r.add(t)}return r}function $t(e,t,n,r){let i=new Set;for(let a of Object.keys(t)){let o=fn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function en(e,t){return t.some(t=>q(e,t))}function tn(e,t){return e.referencedScopes.some(e=>en(e,t))}function nn(e,t){return e.emitsIndex||e.emitsGlobalOptions||tn(e,t)}function rn(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&&(Kt(e,t)||r.push(`Command "${X(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
|
+
- `)}`)}function an(e){return[`<a id="global-options"></a>`,ze(e.args,e.options)].join(`
|
|
72
|
+
`)}function on(e){return[I(),an(e),te()].join(`
|
|
73
|
+
`)}async function sn(e,t,n,r){let i=B(n),a=oe(n);return[i,await Ke(t,e,r),a].join(`
|
|
74
|
+
`)}function $(e){return u.resolve(e)}async function cn(e,t,n,r,i){let a=e,o=[],s=!1,c=!1,l=I(),u=te(),d=await K(on(t),r),f=Vt(a,l,u);if(!f)return n&&i?(a=a.trimEnd()+`
|
|
75
75
|
|
|
76
76
|
`+d+`
|
|
77
|
-
`,c=!0,{content:a,diffs:o,hasError:s,wasUpdated:c}):(s=!0,o.push(`Global options marker not found in file. Expected markers:\n${l}\n...\n${u}`),{content:a,diffs:o,hasError:s,wasUpdated:c});if(f!==d){if(n){let e=
|
|
78
|
-
`),p=
|
|
77
|
+
`,c=!0,{content:a,diffs:o,hasError:s,wasUpdated:c}):(s=!0,o.push(`Global options marker not found in file. Expected markers:\n${l}\n...\n${u}`),{content:a,diffs:o,hasError:s,wasUpdated:c});if(f!==d){if(n){let e=Ht(a,l,u,d);e?(a=e,c=!0):(s=!0,o.push(`Failed to replace global options section`))}else s=!0,o.push(W(f,d))}return{content:a,diffs:o,hasError:s,wasUpdated:c}}async function ln(e,t,n,r,i,a,o,s){let c=e,l=[],u=!1,d=!1,f=[n,await K(i,o),r].join(`
|
|
78
|
+
`),p=Vt(c,n,r);if(!p)return a&&s?(c=c.trimEnd()+`
|
|
79
79
|
|
|
80
80
|
`+f+`
|
|
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=
|
|
82
|
-
`)}function
|
|
83
|
-
`)}\n`}function
|
|
84
|
-
`));let
|
|
85
|
-
`+
|
|
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=Ht(c,n,r,f);e?(c=e,d=!0):(u=!0,l.push(`Failed to replace ${t} section`))}else u=!0,l.push(W(p,f))}return{content:c,diffs:l,hasError:u,wasUpdated:d}}async function un(e,t,n,r,i,a,o){let s=e,c=[],l=!1,u=!1,d=B(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=Vt(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 K(await sn(t,n,r,o),a);if(h!==g){if(i){let e=Ht(s,d,f,g);e?(s=e,u=!0):(l=!0,c.push(`Failed to replace index section`))}else l=!0,c.push(W(h,g))}return{content:s,diffs:c,hasError:l,wasUpdated:u}}function dn(e,t,n,r){for(let[i,a]of Object.entries(t)){let{commandPaths:t}=Y(a,n,r);if(t.includes(e))return i}return null}function fn(e,t,n,r,i){let a=n[t];if(!a)return[];let{specifiedCommands:o,commandPaths:s}=Y(a,r,i),c=new Set;for(let t of e)if(s.includes(t)){c.add(t);for(let e of s)q(e,t)&&!o.includes(e)&&c.add(e)}return Array.from(c)}function pn(e,t,n,r,i,a,o,s=[],c,l){let u=t.get(e);if(!u||l&&Q(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&&Q(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=hn(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=Z(f,n,e);t!==null&&(f=f.replace(t,``))}f=Tt(f)}}return f}function mn(e,t,n,r,i,a,o,s,c,l){let u=Ft(e,t,r,l),d=[];for(let e of u){let u=pn(e,t,n,i,a,o,s,r,c,l);u!==null&&d.push(u)}return d.length===0?null:d.join(`
|
|
82
|
+
`)}function hn(e,t){let n={...e,fields:e.fields.filter(e=>!t.has(e.name))};return e.unionOptions&&(n.unionOptions=e.unionOptions.map(e=>hn(e,t))),e.variants&&(n.variants=e.variants.map(e=>({...e,fields:e.fields.filter(e=>!t.has(e.name))}))),n}function gn(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=pn(e,t,n,r,i,s,c,l);a&&u.push(a)}return`${u.join(`
|
|
83
|
+
`)}\n`}function _n(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let{commandPaths:e}=Y(a,t,n);for(let t of e)it(r,t,i)}return r}async function vn(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 Fe(t.examples,a,n,o)}}function yn(e,t){if(typeof e==`string`)return{files:{[e]:Array.from(t.keys())},rootDocPath:e};let{root:n,commands:r={}}=e,i={},a=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 bn(e){let{command:t,ignores:r=[],format:i={},formatter:a,examples:o,targetCommands:s,globalArgs:c,customizable:l=!1}=e,d=await Pe(t),f,p=!1,m;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=yn(e.path,d);f=t.files,m=t.rootDocPath,p=!0}else if(e.files!==void 0)f=e.files;else if(e.templates!==void 0)f={};else throw Error(`Either "path", "files", or "templates" must be specified.`);let h=e.rootDoc;if(!h&&p&&(c||e.rootInfo)&&(h={path:m}),c&&h&&!h.globalOptions){let e=n(c).fields.filter(e=>!e.positional);if(e.length>0){let t=Object.fromEntries(e.map(e=>[e.name,e.schema]));h={...h,globalOptions:t}}}let g=qe(k),_=qe(A),v=!1;if(h&&!p){let e=$(h.path);if(Object.keys(f).some(t=>$(t)===e))throw Error(`rootDoc.path "${h.path}" must not also appear as a key in files.`)}o&&await vn(d,o,t);let y=s!==void 0&&s.length>0,b=Yt(h),x=new Map;if(e.templates){if(b.size>0)for(let[e,t]of b)x.set(e,t);else{let e=Jt(c);if(e)for(let t of Gt(e))x.set(t.name,t)}}let S=y?$t(s,f,d,r):Qt(f,d,r),C=[];for(let e of Object.values(f)){let t=at(e);C.push(...t.commands)}pt(r,d),ft(C,r,d);let w=_n(f,d,r),T=new Map,ee=new Map;if(e.templates)for(let[t,n]of Object.entries(e.templates)){let e=je(n);T.set(t,e),e!==null&&ee.set(t,Nt(tt(e),d))}let E=Object.entries(e.templates??{}),D=new Map,O=new Map;if(E.length>0){let e=h?$(h.path):null,t=new Set(Object.keys(f).map($)),n=new Set,i=new Set(E.map(([e])=>$(e)));for(let[r,a]of E){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 "${h.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 "${h.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 E){let n=T.get(e)??null,i=[];if(n===null){D.set(e,{referencedScopes:[],headingScopes:[],commandTreeRoots:[],emitsGlobalOptions:!1,emitsIndex:!1}),O.set(e,i);continue}try{zt(n,t)}catch(e){i.push(e instanceof Error?e.message:String(e))}let o=Array.from(new Set(n.match(Rt)??[])),s=new Set,l=new Set,u=new Set,f=!1,p=!1,m=ee.get(e)??rt(new Set),g=nt(n);for(let e of o){let n=Qe(e);if(m.rawKeys.has(n)||Lt(n,m))continue;let o=Mt(e,d);if(!It(e,o,m)){if(o.kind===`invalid`){i.push(`${o.reason} (in template "${t}")`);continue}if(o.kind===`command`){let{scope:e,type:n}=o;if(!d.has(e)){let n=Bt(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=Ft(e,d,r,m);Pt(e,`heading`,m)||u.add(e);for(let e of t)s.add(e),Pt(e,`heading`,m)||l.add(e)}else s.add(e),n===`heading`&&!Pt(e,`heading`,m)&&(l.add(e),u.add(e))}else o.kind===`global-options`?f=!0:o.kind===`index`&&(p=!0)}}f&&(h?.globalOptions||Jt(c)!==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).`)),D.set(e,{referencedScopes:Array.from(s),headingScopes:Array.from(l),commandTreeRoots:Array.from(u),emitsGlobalOptions:f,emitsIndex:p,...g.title===void 0?{}:{indexTitle:g.title},...g.description===void 0?{}:{indexDescription:g.description}}),O.set(e,i)}for(let e of D.values())if(!y||nn(e,s))for(let t of e.referencedScopes)S.add(t)}if(y)for(let e of s){let t=dn(e,f,d,r),n=Array.from(D.values()).some(t=>tn(t,[e]));if(!t&&!n)throw Error(`Target command "${e}" not found in any file or template configuration`)}let j=y&&e.templates?new Map(Array.from(D.entries()).filter(([,e])=>nn(e,s))):D;for(let[e,t]of O.entries())if(t.length>0&&j.has(e))throw Error(t.join(`
|
|
84
|
+
`));let M=Array.from(D.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),F=M.length===1?M[0]:void 0;if(rn(S,d,b),b.size===0&&x.size>0){let e=new Set;for(let t of j.values())if(t.emitsGlobalOptions||F!==void 0)for(let n of t.referencedScopes)e.add(n);rn(e,d,x)}if(b.size>0)for(let e of d.values())e.options=e.options.filter(e=>!b.has(e.name)),e.extracted&&=hn(e.extracted,new Set(b.keys()));let I={};for(let[e,t]of Object.entries(w))it(I,e,t);let te=e=>e===``?0:e.split(` `).length,L=new Map;for(let[e,t]of D.entries())for(let n of t.headingScopes){if(Object.prototype.hasOwnProperty.call(w,n))continue;let r=-1;for(let e of t.commandTreeRoots)q(n,e)&&(r=Math.max(r,te(e)));if(r<0)continue;let i=L.get(n);(!i||r>i.rootLen)&&L.set(n,{outputPath:e,rootLen:r})}for(let[e,{outputPath:t}]of L)it(I,e,t);let R=[],z=!1;for(let[e,t]of Object.entries(f)){let{fileConfig:n,specifiedCommands:o,commandPaths:c}=Y(t,d,r);if(o.length===0||c.length===0)continue;let u=y?fn(s,e,f,d,r):[];if(y&&u.length===0)continue;let m=`match`,x=[],S=Math.min(...c.map(e=>d.get(e)?.depth??1)),C=Math.max(1,(i?.headingLevel??1)-(S-1)),w=p&&h&&$(e)===$(h.path),T=p||l,ee=U({...i,headingLevel:C,markerless:!T}),E=n.render??ee;if(w||y&&T){let t=je(e),i=mt(c,o),s=y?u:c;for(let o of s){let s=pn(o,d,E,e,I,h?.path,b.size>0,r);if(!s)throw Error(`Target command "${o}" not found in commands`);let c=await K(s,a);if(!t){if(g){let r=o===``&&n?ht(n):null,i=r?`${r}\n${c}`:c;G(e,i),t=i,m=`created`}else z=!0,m=`diff`,x.push(`File does not exist. Target command "${o}" section cannot be validated.`);continue}let u=bt(t,o);if(u.length===0){g?(t=St(t,o,c,i),G(e,t),m!==`created`&&(m=`updated`)):(z=!0,m=`diff`,x.push(`Existing file does not contain section markers for command "${o}"`));continue}for(let n of u){let r=Z(t,n,o),i=Z(c,n,o);if(r){if(!i){let i=N(n,o)+`
|
|
85
|
+
`+P(n,o);if(r!==i){if(g){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
|
-
`),
|
|
87
|
+
`),G(e,t),m!==`created`&&(m=`updated`)}else z=!0,m=`diff`,x.push(W(r,i))}continue}if(r!==i){if(g){let r=vt(t,n,o,i);if(r)t=r,G(e,t),m!==`created`&&(m=`updated`);else throw Error(`Failed to replace ${n} section for command "${o}"`)}else z=!0,m=`diff`,x.push(W(r,i))}}}if(_||l){let n=bt(c,o),r=new Set(u);for(let i of n){if(r.has(i))continue;let n=Z(c,i,o);n&&(_&&g?(t=yt(t,i,o,n),G(e,t),m!==`created`&&(m=`updated`)):_?(z=!0,v=!0,m=`diff`,x.push(`[doctor] Missing section marker "${i}" for command "${X(o)}". Run with ${A}=true ${k}=true to insert.\n${n}`)):console.warn(`[politty] Missing "${i}" section for command "${X(o)}" in ${e}. Run with ${A}=true ${k}=true to insert it, or leave it removed to opt that section out.`))}}}if(t){let n=xt(t),r=new Set(c);if(g){let i=!1;for(let e of n)r.has(e)||(t=Ct(t,e),i=!0);i&&(G(e,t),m!==`created`&&(m=`updated`))}else for(let e of n)r.has(e)||(z=!0,m=`diff`,x.push(`Found orphaned section markers for deleted command "${X(e)}"`))}}else{let t=await K(gn(c,d,E,e,I,o,n,h?.path,b.size>0,r),a),i=Ae(t,e);i.match||(g?(G(e,t),m=i.fileExists?`updated`:`created`):(z=!0,m=`diff`,i.diff&&x.push(i.diff)))}x.length>0&&(m=`diff`),R.push({path:e,status:m,diff:x.length>0?x.join(`
|
|
88
88
|
|
|
89
|
-
`):void 0})}let
|
|
90
|
-
`,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(t===``||o===``)return``;let e=
|
|
89
|
+
`):void 0})}let B;if(h?.globalOptions)B=qt(h.globalOptions);else{let e=Jt(c);e&&(B={args:e})}for(let[e,n]of E){if(!j.has(e))continue;let o=T.get(e)??null;if(o===null){z=!0,R.push({path:e,status:`diff`,diff:`Template file not found: ${n}`});continue}let s=D.get(e),c=Et(o),l=Ye(o),u=(s?.headingScopes??[]).map(e=>d.get(e)?.depth??1),p=u.length>0?Math.min(...u):1,m=kt((i?.headingLevel??1)-(p-1)),_=U({...i,headingLevel:m}),v=s?.emitsGlobalOptions??!1,y=(h!==void 0&&b.size>0||v||F!==void 0)&&x.size>0?new Set(x.keys()):void 0,S=y!==void 0,C=v?e:h?.path??F,w=Array.from(new Set(l.match(Rt)??[])),E=new Map,O=ee.get(e)??rt(new Set);for(let i of w){let a=Qe(i);if(O.rawKeys.has(a)||Lt(a,O)){E.set(i,``);continue}let o=Mt(i,d);if(It(i,o,O)){E.set(i,``);continue}if(o.kind===`invalid`)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}": ${o.reason}`);if(o.kind===`command`){let{scope:t,type:n}=o;if(n===void 0){let n=mn(t,d,_,r,e,I,C,S,y,O);if(n===null){E.set(i,``);continue}E.set(i,wt(n))}else{let a=pn(t,d,_,e,I,C,S,r,y,O);if(a===null){E.set(i,``);continue}let o=Z(a,n,t);E.set(i,o===null?``:wt(o))}}else if(o.kind===`global-options`)B?E.set(i,an(B)):E.set(i,``);else if(o.kind===`index`){let n=await Ke(t,[...Xt(f,e,d,r),...Zt(D,e,e,d)],h?.index);E.set(i,n)}}let k=l.replace(/((?:\r?\n)*)([ \t]*)(\{\{politty:[^{}]*\}\})([ \t]*)((?:\r?\n)*)/g,(e,t,r,i,a,o,s,c)=>{let l=E.get(i);if(l===void 0)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}".`);let u=t!==``||s===0||c[s-1]===`
|
|
90
|
+
`,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(t===``||o===``)return``;let e=Dt(t),n=Dt(o),r=Math.max(e,n),i=Et(e>=n?t:o);return r>=2?i+i:r===1?i:``}return`${t}${r}${l}${a}${o}`});k=`${k.trimEnd()}${c}`,k=await K(k,a);let A=Ae(k,e),M=`match`,N;A.match||(g?(G(e,k),M=A.fileExists?`updated`:`created`):(z=!0,M=`diff`,A.diff&&(N=A.diff))),R.push({path:e,status:M,diff:N})}if(h){let n=h.path,i=`match`,o=[],s=je(n);if(s===null)z=!0,i=`diff`,o.push(`File does not exist. Cannot validate rootDoc markers.`);else{let c=s,l=!1,m=e.rootInfo,_={title:m?.title??t.name};h.headingLevel!==void 0&&(_.headingLevel=h.headingLevel);let v=m?.description??t.description;v!==void 0&&(_.description=v);let y=_t(c,_,g);if(c=y.content,y.diff&&o.push(y.diff),y.hasError&&(z=!0),y.wasUpdated&&(l=!0),m?.header){let e=await ln(c,`Root header`,ne(),re(),m.header,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(z=!0),e.wasUpdated&&(l=!0)}if(!p){let e=xt(c);if(e.length>0){if(g){for(let t of e)c=Ct(c,t);l=!0}else z=!0,o.push(`Found unexpected section markers in rootDoc: ${e.map(e=>`"${X(e)}"`).join(`, `)}.`)}}let b=qt(h.globalOptions);if(b){let e=await cn(c,b,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(z=!0),e.wasUpdated&&(l=!0)}let x=Xt(f,n,d,r),S=u.relative(process.cwd(),n).replace(/\\/g,`/`),C=await un(c,x,t,S,g,a,h.index);if(c=C.content,o.push(...C.diffs),C.hasError&&(z=!0),C.wasUpdated&&(l=!0),m?.footer){let e=await ln(c,`Root footer`,ie(),ae(),m.footer,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(z=!0),e.wasUpdated&&(l=!0)}g&&l&&(G(n,c),i===`match`&&(i=`updated`))}o.length>0&&(i=`diff`),R.push({path:n,status:i,diff:o.length>0?o.join(`
|
|
91
91
|
|
|
92
|
-
`):void 0})}return{success:!
|
|
92
|
+
`):void 0})}return{success:!z,files:R,error:z?`Documentation is out of date. ${v?`Run with ${A}=true ${k}=true to fix missing markers.`:`Run with ${k}=true to update.`}`:void 0}}async function xn(e){let t=await bn(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
|
|
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 Sn(e,t){if(qe(`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{A as DOCTOR_ENV,F as GLOBAL_OPTIONS_MARKER_PREFIX,z as INDEX_MARKER_PREFIX,R as ROOT_FOOTER_MARKER_PREFIX,L as ROOT_HEADER_MARKER_PREFIX,M as SECTION_MARKER_PREFIX,j as SECTION_TYPES,k as UPDATE_GOLDEN_ENV,xn as assertDocMatch,Ne as buildCommandInfo,Pe as collectAllCommands,Ae as compareWithExisting,U as createCommandRenderer,ke as defaultRenderers,Fe as executeExamples,W as formatDiff,bn as generateDoc,te as globalOptionsEndMarker,I as globalOptionsStartMarker,oe as indexEndMarker,B as indexStartMarker,Sn as initDocFile,ze as renderArgsTable,de as renderArgumentsList,we as renderArgumentsListFromArray,le as renderArgumentsTable,Ce as renderArgumentsTableFromArray,Ke as renderCommandIndex,Ee as renderExamplesDefault,_e as renderOptionsList,H as renderOptionsListFromArray,ge as renderOptionsTable,V 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,P as sectionEndMarker,N as sectionStartMarker,G as writeFile};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{i as e,n as t}from"./field-meta-_l-FHbh7.js";import{a as n,l as r,n as i}from"./schema-extractor-Du9ipDD4.js";import{n as a}from"./command-tLHaJHe6.js";import{c as o,i as s}from"./subcommand-router-D8GTMXYL.js";import{i as c}from"./argv-parser-DZQ0qnXG.js";import{t as l}from"./schema-DhMPssIJ.js";import{execSync as u}from"node:child_process";function d(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:p(e.valueCompletion,e.isGlobal===!0,t,n)}}function f(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:p(e.valueCompletion,!1,t,n)}}function p(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=new Set,a=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 m(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 h(e){return`'${e.replace(/'/g,`'\\''`)}'`}function g(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 _(e){return e.length===1?`-${e}`:`--${e}`}function v(t,n){y(t,_(n)),n.length===1?y(t,`--${n}`):n.includes(`-`)&&y(t,`--${e(n)}`)}function y(e,t){e.includes(t)||e.push(t)}function b(t,n){let r=[`--${t}`];t.length===1&&r.push(`-${t}`),t.includes(`-`)&&r.push(`--${e(t)}`);for(let e of n??[])v(r,e);return r}function x(e){let t=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 S(t,n,r,i){let a=new Set(b(t,n));if(r&&(a.add(`--${r}`),r.includes(`-`)&&a.add(`--${e(r)}`)),i?.frameOptions){if(i.isGlobal===!0){for(let e of i.frameOptions)if(e.isGlobal!==!0)for(let t of E(e.cliName,e.alias))a.delete(t)}else{let e=x(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 C(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&S(n.cliName,n.alias,n.negation,{frameOptions:t})})}function w(e,t,n,r=`$_pos_count`){let i=C(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 T(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 w(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 E(t,n){let r=[`--${t}`];t.includes(`-`)&&r.push(`--${e(t)}`);for(let e of n??[])v(r,e);return r}function D(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 O(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?te(e.args):[]}function te(e){return n(i(e)).map(k)}function k(e){let n=t(e);return{name:e.name,cliName:e.cliName,alias:n.length>0?n: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:O(D(e))}}function A(e){return new Set(b(e.cliName,e.alias))}function ne(e,t){let n=A(t);for(let t of e)for(let e of A(t))if(n.has(e))return t}function re(e,t,n){let r=new Set;if(t.length===0)return r;let i=new Set,a=(e,t)=>{B(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;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=F(i),c=U(t,s);if(!c){if(le(t,s)){o++;continue}break}if(c.takesValue){if(I(i)){let e=i.indexOf(`=`);a(c,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(t.startsWith(`-`)){o++;continue}a(c,t),o+=2}else break}else n[c.name]=!V(c,s),r.add(c.name),o++}return r}function ie(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function j(e,t){return t.length===0?e:[...e,...t]}function M(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function N(e,t){return n=>{let r={...e};return c(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function ae(e,t,n){if(!e.args)return;let a=i(e.args),o=r(a,N(t,n));if(o!==a)return o.fields.filter(e=>e.named).map(k)}function oe(e,t,n){if(!e.args)return[];let a=r(i(e.args),N(t,n));return c(a,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:O(D(e))}))}function se(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 ce(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 P(e){return e.startsWith(`-`)}function F(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 I(e){return e.includes(`=`)}function L(t,n,r){if(!r||t.valueType!==`boolean`)return!1;let i=[t.cliName,...t.alias??[]];for(let t of i){let r=`no-${t}`;if(n===r||n===e(r))return!0}return!1}function R(e,t,n){return e.defaultNegationAccepted===!0&&L(e,t,n)}function le(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&L(e,t.name,t.isLong))}function z(t,n){return t!==void 0&&t.includes(`-`)&&e(t)===n}function B(e,t,n,r){if(t.valueType!==`array`){e[t.name]=n;return}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 V(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||z(e.negation,t.name))?!0:R(e,t.name,t.isLong):!1}function H(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:z(e.cliName,t)||e.alias?.some(e=>z(e,t))?!0:z(e.negation,t)}function U(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&&H(e,t.name,t.isLong));if(r)return r}return e.find(e=>H(e,t.name,t.isLong))||e.find(e=>R(e,t.name,t.isLong))}function W(e,t,n){let r=G(e,t,n);return r.variantOptions?G(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function G(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,o=[],s=n?te(n).map(e=>({...e,isGlobal:!0})):[],c=new Set,l=!1,u=0,d={},f=[],p={},m=new Set,h=0,g=new Set,_=e=>{c.add(e.cliName);for(let t of e.alias??[])c.add(t);e.negation&&c.add(e.negation),l=!0},v=(e,t)=>{B(e.isGlobal===!0?p:d,e,t,g)},y=(e,t)=>{let n=e.isGlobal===!0?p:d;n[e.name]=!V(e,t)},b=0,x=j(i(a),s),S=!1;for(;b<e.length-1;){let t=e[b];if(!S&&t===`--`){S=!0,b++;continue}if(!S&&t.startsWith(`-`)&&!t.startsWith(`--`)&&t.length>2&&!t.includes(`=`)){l=!0;let e=Array.from(t.slice(1)),n=x.filter(e=>e.isGlobal!==!0);for(let t of e){let e=U(n,{name:t,isLong:!1});e&&!e.takesValue&&(_(e),y(e,{name:t,isLong:!1}))}b++;continue}if(!S&&P(t)){l=!0;let n=F(t),r=U(x,n);if(r){if(_(r),r.takesValue){if(I(t)){let e=t.indexOf(`=`);v(r,t.slice(e+1))}else if(b+1<e.length-1){let t=e[b+1];P(t)||(v(r,t),b++)}}else y(r,n)}b++;continue}let n=S?null:ce(a,t);if(n){o.push(t);let r=i(a),l=e.slice(h,b);for(let e of re(l,s,p))m.add(e);a=n,x=j(i(a),s);for(let e of Object.keys(d)){let t=r.find(t=>t.name===e),n=s.find(t=>t.name===e)??(t?ne(s,t):void 0);n&&(m.has(n.name)||(p[n.name]=ie(d[e],n)))}c.clear(),u=0,d={},f=[],g=new Set,h=b+1,b++;continue}f.push(t),u++,b++}let C=e[e.length-1]??``,w=e[e.length-2]??``,T=ae(a,d,f),E=oe(a,d,f),D=se(a);for(let e=0;e<E.length;e++){let t=E[e];if(t.variadic){d[t.name]=f.slice(e);break}e<f.length&&(d[t.name]=f[e])}let O,k,A;if(!S&&w&&P(w)&&!I(w)){let e=U(x,F(w));e&&e.takesValue?(O=`option-value`,k=e):C.startsWith(`-`)?O=`option-name`:(O=K(C,D,E,u),O===`positional`&&(A=u))}else if(!S&&C.startsWith(`-`)&&I(C)){let e=U(x,F(C));e&&e.takesValue?(O=`option-value`,k=e):O=`option-name`}else!S&&C.startsWith(`-`)?O=`option-name`:(O=K(C,D,E,u,S),O===`positional`&&(A=u));let N=[];if(k){if(k.valueType===`array`){let e=(k.isGlobal===!0?p:d)[k.name];N=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(O===`positional`&&A!==void 0){let e=M(A,E);e!==void 0&&E[e]?.variadic&&(N=f.slice(e))}let L={...p,...d};return{context:{subcommandPath:o,currentCommand:a,currentWord:C,previousWord:w,completionType:O,targetOption:k,positionalIndex:A,options:x,subcommands:D,positionals:E,usedOptions:c,hasAnyOptionBeenUsed:l,providedPositionalCount:u,parsedArgs:L,previousValues:N},variantOptions:T}}function K(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 q={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function J(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function Y(e,t){switch(e.completionType){case`subcommand`:return ve(e);case`option-name`:return Z(e);case`option-value`:{let n=e.targetOption,r=n?J(e.currentWord):void 0;return xe(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=ue(e);return n?xe(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:q.NoFileCompletion}}}}function ue(e){let t=e.positionalIndex??0,n=M(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function de(e){try{return u(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 X(e){return e?.type===`choices`?e.choices:void 0}function fe(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return X(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return X(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function pe(e,t){let n=!t.includes(`=`),r=n?me(e):he(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function me(e){let t=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 he(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function ge(e,t,n,r,i){let a=[],o=q.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|=q.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|=q.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|=q.FileCompletion)):o|=q.FileCompletion;break;case`directory`:o|=q.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...de(e.shellCommand)),o|=q.NoFileCompletion;break;case`none`:o|=q.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??q.FilterPrefix|q.NoFileCompletion}catch{o=q.NoFileCompletion|q.Error}break;case`expand`:o|=q.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=fe(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=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=q.NoFileCompletion|q.Error;break}o|=q.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=pe(e.type===`runtime-expand`&&i===!0?_e(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=q.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function _e(e,t){let n=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 ve(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=Z(e);t.push(...n.candidates)}return{candidates:t,directive:q.FilterPrefix|q.NoFileCompletion}}function Z(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:q.FilterPrefix|q.NoFileCompletion}}function ye(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:be(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function be(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function xe(e,t,n,r,i,a){return r?ge(r,ye(e,t,n),e,i,a):{candidates:[],directive:q.FilterPrefix}}function Q(e,t){switch(t.shell){case`bash`:return Se(e,t);case`zsh`:return Ce(e,t);case`fish`:return we(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 Se(e,t){let n=((e.directive&q.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
|
+
`)}function Ce(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
|
+
`)}function we(e,t){let n=e.candidates.map(e=>e.description?`${e.value}\t${e.description}`:e.value);return $(n,e),n.join(`
|
|
6
|
+
`)}function Te(e,t,n){return a({name:`__complete`,args:l,async run(t){let r=W(t.args,e,n),i=r.completionType===`option-value`&&r.targetOption?J(r.currentWord):void 0,a=i?r.currentWord.slice(i.length):r.currentWord,o=Q(await Y(r,{shell:t.shell}),{shell:t.shell,currentWord:a,inlinePrefix:i});console.log(o)}})}function Ee(e){return!!e.subCommands?.__complete}export{S as _,Y as a,m as c,E as d,C as f,T as g,w as h,q as i,b as l,f as m,Ee as n,W as o,d as p,Q as r,D as s,Te as t,x as u,h as v,g as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./dynamic-4uRohypH.js";export{e as createDynamicCompleteCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let e;function t(t){e=t}function n(){if(!e)throw Error('No validator adapter registered. Import politty through an adapter package (e.g. `import { defineCommand } from "@politty/zod"` or `from "politty"`) so the schema library integration is set up.');return e}const r=new Set([`help`,`help-all`,`help-json`,`version`]);function i(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function a(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function o(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function s(e,t){let n=t.argMeta,a=n?.description??t.description,o=i(e),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(t,n)=>{if(t==null)return;let r=(Array.isArray(t)?t:[t]).map(t=>{if(typeof t!=`string`)throw Error(`Invalid ${n} for field "${e}": expected string or string[], received ${typeof t}.`);let r=t.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${n} "${t}" for field "${e}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(n?.alias,`alias`),u=new Set(l??[]),d=c(n?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=t.type,m=n?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${e}": expected string or boolean, received ${typeof m}.`);let t=m.trim().replace(/^-+/,``);if(t.length===0||!s.test(t))throw Error(`Invalid negation "${m}" for field "${e}": negation names must match ${s}.`);if(r.has(t))throw Error(`Invalid negation "${m}" for field "${e}": negation cannot use reserved built-in flag names (${[...r].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=t}}let g=n?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${e}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${e}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${e}": negationDescription requires \`negation\` to be set (string or true).`);let t=g.trim();if(t.length===0)throw Error(`Invalid negationDescription for field "${e}": negationDescription must be a non-empty string.`);_=t}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y={name:e,cliName:o,alias:l,hiddenAlias:f,description:a,positional:
|
|
1
|
+
let e;function t(t){e=t}function n(){if(!e)throw Error('No validator adapter registered. Import politty through an adapter package (e.g. `import { defineCommand } from "@politty/zod"` or `from "politty"`) so the schema library integration is set up.');return e}const r=new Set([`help`,`help-all`,`help-json`,`version`]);function i(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function a(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function o(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function s(e,t){let n=t.argMeta,a=n?.description??t.description,o=i(e),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(t,n)=>{if(t==null)return;let r=(Array.isArray(t)?t:[t]).map(t=>{if(typeof t!=`string`)throw Error(`Invalid ${n} for field "${e}": expected string or string[], received ${typeof t}.`);let r=t.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${n} "${t}" for field "${e}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(n?.alias,`alias`),u=new Set(l??[]),d=c(n?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=t.type,m=n?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${e}": expected string or boolean, received ${typeof m}.`);let t=m.trim().replace(/^-+/,``);if(t.length===0||!s.test(t))throw Error(`Invalid negation "${m}" for field "${e}": negation names must match ${s}.`);if(r.has(t))throw Error(`Invalid negation "${m}" for field "${e}": negation cannot use reserved built-in flag names (${[...r].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=t}}let g=n?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${e}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${e}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${e}": negationDescription requires \`negation\` to be set (string or true).`);let t=g.trim();if(t.length===0)throw Error(`Invalid negationDescription for field "${e}": negationDescription must be a non-empty string.`);_=t}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y=n?.positional,b={name:e,cliName:o,alias:l,hiddenAlias:f,description:a,positional:y!==void 0&&y!==!1,named:typeof y==`object`?y.named===!0:y!==!0,placeholder:n?.placeholder,env:n?.env,required:t.required,defaultValue:t.defaultValue,type:p,schema:t.schema,enumValues:t.enumValues,completion:n?.completion,prompt:n?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:n?.effect};return n&&`overrideBuiltinAlias`in n&&n.overrideBuiltinAlias===!0&&(b.overrideBuiltinAlias=!0),b}export{i as a,a as i,o as n,n as o,s as r,t as s,r as t};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as toCamelCase, A as LogEntry, B as RunResultFailure, C as Command, D as GlobalCleanupContext, E as GlobalArgs, F as NonRunnableCommand, G as SubCommandsRecord, H as RunnableCommand, I as PromptResolver, J as isLazyCommand, K as UnknownSubcommandHandler, L as RunCommandOptions, M as LogStream, N as Logger, O as GlobalSetupContext, P as MainOptions, Q as UnknownKeysMode, R as RunInvocation, S as CollectedLogs, T as Example, U as SetupContext, V as RunResultSuccess, W as SubCommandValue, X as ExtractedFields, Y as lazy, Z as ResolvedFieldMeta, _ as DynamicCompletionResult, a as CustomCompletion, b as ArgsSchema$1, c as PromptType, d as ExpandCompletion, et as toKebabCase, f as ResolvedExpandCandidate, g as DynamicCompletionResolver, h as DynamicCompletionContext, i as CompletionType, j as LogLevel, k as IsEmpty, l as ValidateArgMeta, m as DynamicCompletionCandidate, n as ArgMeta, nt as SchemaLike, o as EffectContext, p as CompletionDirectiveMask, q as LazyCommand, r as CompletionMeta, s as PromptMeta, t as ArgFn, tt as InferSchemaOutput, u as ExpandCandidate, v as AnyCommand, w as CommandBase, x as CleanupContext, y as ArgSource, z as RunResult } from "./arg-registry-
|
|
2
|
-
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-
|
|
1
|
+
import { $ as toCamelCase, A as LogEntry, B as RunResultFailure, C as Command, D as GlobalCleanupContext, E as GlobalArgs, F as NonRunnableCommand, G as SubCommandsRecord, H as RunnableCommand, I as PromptResolver, J as isLazyCommand, K as UnknownSubcommandHandler, L as RunCommandOptions, M as LogStream, N as Logger, O as GlobalSetupContext, P as MainOptions, Q as UnknownKeysMode, R as RunInvocation, S as CollectedLogs, T as Example, U as SetupContext, V as RunResultSuccess, W as SubCommandValue, X as ExtractedFields, Y as lazy, Z as ResolvedFieldMeta, _ as DynamicCompletionResult, a as CustomCompletion, b as ArgsSchema$1, c as PromptType, d as ExpandCompletion, et as toKebabCase, f as ResolvedExpandCandidate, g as DynamicCompletionResolver, h as DynamicCompletionContext, i as CompletionType, j as LogLevel, k as IsEmpty, l as ValidateArgMeta, m as DynamicCompletionCandidate, n as ArgMeta, nt as SchemaLike, o as EffectContext, p as CompletionDirectiveMask, q as LazyCommand, r as CompletionMeta, s as PromptMeta, t as ArgFn, tt as InferSchemaOutput, u as ExpandCandidate, v as AnyCommand, w as CommandBase, x as CleanupContext, y as ArgSource, z as RunResult } from "./arg-registry-Dvi0co21.js";
|
|
2
|
+
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-BKHwbzEc.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region ../core/src/core/schema-extractor.d.ts
|
|
5
5
|
/**
|
|
@@ -461,6 +461,8 @@ interface HelpFieldData {
|
|
|
461
461
|
cliName: string;
|
|
462
462
|
/** Whether this is a positional argument */
|
|
463
463
|
positional: boolean;
|
|
464
|
+
/** Whether this is accepted as a long option (`--cli-name`), including a named positional */
|
|
465
|
+
named: boolean;
|
|
464
466
|
/** Whether this argument is required */
|
|
465
467
|
required: boolean;
|
|
466
468
|
/** Detected type from schema */
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t}from"./field-meta-
|
|
1
|
+
import{a as e,i as t}from"./field-meta-_l-FHbh7.js";import{t as n}from"./register-BXOytPt7.js";import{i as r,n as i}from"./schema-extractor-Du9ipDD4.js";import{n as a,t as o}from"./cli-main-uRzr666k.js";import{n as s,t as c}from"./command-tLHaJHe6.js";import{C as l,D as u,E as d,O as f,S as p,T as m,_ as h,a as g,b as _,c as v,d as y,f as b,g as x,h as S,i as C,l as w,m as T,n as E,o as D,p as O,r as k,s as A,t as j,u as M,v as N,w as P,x as F,y as I}from"./runner-BTD1-gUd.js";import{o as L,s as R}from"./subcommand-router-D8GTMXYL.js";import{a as z,i as B,n as V,r as H,t as U}from"./logger-CoeDrmRr.js";import{r as W}from"./argv-parser-DZQ0qnXG.js";import{t as G}from"./with-completion-command-CQcqFHq8.js";const K=a(`@politty/zod`),q=s,J=c,Y=n;export{x as CaseVariantCollisionError,h as DefaultSubCommandError,N as DuplicateAliasError,I as DuplicateFieldError,_ as DuplicateNegationError,F as FieldTypeConflictError,p as PositionalConfigError,l as ReservedAliasError,P as ReservedFieldNameError,Y as arg,a as createCompileCacheShimGenerator,J as createDefineCommand,k as createDualCaseProxy,q as defineCommand,i as extractFields,g as formatCommandValidationErrors,C as formatValidationErrors,K as generateCompileCacheShim,m as generateHelp,d as generateHelpData,r as getUnknownKeysMode,U as isColorEnabled,L as isLazyCommand,R as lazy,V as logger,W as parseArgv,u as renderInline,f as renderMarkdown,j as runCommand,E as runMain,o as runPolittyCli,H as setColorEnabled,B as styles,z as symbols,t as toCamelCase,e as toKebabCase,D as validateCaseVariantCollisions,A as validateCommand,v as validateCrossSchemaCollisions,w as validateDefaultSubCommand,M as validateDuplicateAliases,y as validateDuplicateFields,b as validateDuplicateNegations,O as validatePositionalConfig,T as validateReservedAliases,S as validateReservedFieldNames,G as withCompletionCommand};
|
package/dist/prompt-clack.d.ts
CHANGED
package/dist/prompt-clack.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-BXOytPt7.js";import{t as e}from"./prompt-CqmGq1_N.js";import{confirm as t,isCancel as n,password as r,select as i,text as a}from"@clack/prompts";function o(){return{text:e=>a({message:e.message,...e.placeholder!==void 0&&{placeholder:e.placeholder}}),password:e=>r(e),confirm:e=>t(e),select:e=>i(e),isCancelled:n}}const s=(t,n)=>e(t,n,{adapter:o()});export{s as prompt};
|
package/dist/prompt-inquirer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-BXOytPt7.js";import{t as e}from"./prompt-CqmGq1_N.js";import{confirm as t,input as n,password as r,select as i}from"@inquirer/prompts";const a=Symbol(`inquirer-cancel`);async function o(e){try{return await e()}catch(e){if(e instanceof Error&&e.name===`ExitPromptError`)return a;throw e}}function s(){return{text:e=>o(()=>n({message:e.message,...e.placeholder!==void 0&&{default:e.placeholder}})),password:e=>o(()=>r({message:e.message})),confirm:e=>o(()=>t({message:e.message})),select:e=>o(()=>i({message:e.message,choices:e.options.map(e=>({name:e.label,value:e.value}))})),isCancelled:e=>e===a}}const c=(t,n)=>e(t,n,{adapter:s()});export{c as prompt};
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as ExtractedFields, Z as ResolvedFieldMeta } from "./arg-registry-
|
|
1
|
+
import { X as ExtractedFields, Z as ResolvedFieldMeta } from "./arg-registry-Dvi0co21.js";
|
|
2
2
|
//#region ../core/src/prompt/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Resolved prompt configuration for a single field
|
package/dist/prompt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-BXOytPt7.js";import{i as e,n as t,r as n,t as r}from"./prompt-CqmGq1_N.js";export{n as getFieldsToPrompt,t as isInteractive,r as promptMissingArgs,e as resolvePromptConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e,s as t}from"./field-meta-
|
|
1
|
+
import{r as e,s as t}from"./field-meta-_l-FHbh7.js";const n=new WeakMap;function r(e,t){return t&&n.set(e,t),e}function i(e){return n.get(e)}function a(e,t=new Set){if(t.has(e))return;t.add(e);let n=i(e);if(n)return n;if(typeof e.meta==`function`){let t=e.meta();if(t&&typeof t==`object`)return t}let r=e,s=r.def??r._def;if(s?.argMeta)return s.argMeta;if(s?.meta)return s.meta;let c=o(e);if(c===`optional`||c===`nullable`||c==="default"){let e=s?.innerType;if(e)return a(e,t)}if(c===`pipe`){let e=s?.in??s?.schema;if(e)return a(e,t)}}function o(e){let t=e;return t.def?.type??t._def?.type??t.type}function s(e){let t=c(e),n=(t.def??t._def)?.catchall;if(!n)return`strip`;let r=o(n);return r===`never`?`strict`:r===`unknown`||r===`any`?`passthrough`:`strip`}function c(e){let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return c(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return c(e)}return e}function l(e){switch(o(c(e))){case`string`:case`enum`:return`string`;case`number`:case`int`:return`number`;case`boolean`:return`boolean`;case`array`:return`array`;default:return`unknown`}}function u(e){let t=c(e),n=o(t),r=t,i=r.def??r._def;if(n===`enum`){let e=i?.entries;if(e&&typeof e==`object`)return Object.values(e);let t=i?.values;if(Array.isArray(t))return t;let n=r.options;if(Array.isArray(n))return n}if(n===`array`){let e=i?.element;if(e)return u(e)}if(n===`union`){let e=i?.options;if(Array.isArray(e)){let t=[];for(let n of e)if(o(n)===`literal`){let e=n.def??n._def,r=e?.value,i=e?.values,a=r??i?.[0];typeof a==`string`&&t.push(a)}if(t.length===e.length&&t.length>0)return t}}}function d(e){return!e.isOptional()}function f(e){let t=o(e),n=e,r=n.def??n._def;if(t==="default"){let e=r?.defaultValue;return typeof e==`function`?e():e}if(t===`optional`||t===`nullable`){let e=r?.innerType;if(e)return f(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return f(e)}}function p(e){if(e.description)return e.description;let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return p(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return p(e)}}function m(t,n){let r=a(n);return e(t,{argMeta:r,description:p(n),required:d(n),defaultValue:f(n),type:l(n),enumValues:u(n),schema:n})}function h(e){let t=e;return(t.def??t._def)?.shape??t.shape??{}}function g(e){let t=h(e);return Object.entries(t).map(([e,t])=>m(e,t))}function _(e){let t=e,n=t.def??t._def,r=n?.discriminator??``,i=n?.options??[],a=new Map,c=[];for(let e of i){let t=h(e),n=[],i=``,s=t[r];if(s){let e=o(s);if(e===`literal`){let e=s.def??s._def,t=e?.value,n=e?.values;i=String(t??n?.[0]??``)}else if(e===`enum`){let e=u(s);e&&e.length===1&&(i=e[0])}}for(let[e,r]of Object.entries(t)){let t=m(e,r);n.push(t),a.has(e)||a.set(e,t)}let l=p(e);c.push({discriminatorValue:i,fields:n,...l?{description:l}:{}})}let l=p(e);return{fields:Array.from(a.values()),schema:e,schemaType:`discriminatedUnion`,unknownKeysMode:s(e),discriminator:r,variants:c,...l?{description:l}:{}}}function v(e,t){let n=e,r=(n.def??n._def)?.options??[],i=new Map,a=[];for(let e of r){let t=x(e);a.push(t);for(let e of t.fields)i.has(e.name)||i.set(e.name,e)}let o=p(e);return{fields:Array.from(i.values()),schema:e,schemaType:t,unknownKeysMode:s(e),unionOptions:a,...o?{description:o}:{}}}function y(e){let t=e,n=t.def??t._def,r=n?.left,i=n?.right,a=new Map,o=e=>{if(!e)return;let t=x(e);for(let e of t.fields)a.has(e.name)||a.set(e.name,e)};o(r),o(i);let c=p(e);return{fields:Array.from(a.values()),schema:e,schemaType:`intersection`,unknownKeysMode:s(e),...c?{description:c}:{}}}const b=new WeakMap;function x(e){let t=b.get(e);if(t)return t;let n=e,r,i=o(n),a=n,c=a.def??a._def;switch(i){case`object`:{let t=p(n);r={fields:g(n),schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}case`union`:r=c?.discriminator?_(n):v(n,`union`);break;case`xor`:r=v(n,`xor`);break;case`intersection`:r=y(n);break;case`optional`:case`nullable`:case`default`:case`pipe`:{let t=c?.innerType??c?.in??c?.schema;if(t){let i=x(t),a=p(n);r={...i,schema:e,...a?{description:a}:{}};break}let i=p(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...i?{description:i}:{}};break}default:{let t=p(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}}return b.set(e,r),r}function S(e){return e.issues.map(e=>({path:e.path.map(String),message:e.message,code:e.code,received:`received`in e?e.received:void 0,expected:`expected`in e?String(e.expected):void 0}))}function C(e,t){let n=t.safeParse(e);return n.success?{success:!0,data:n.data}:{success:!1,errors:S(n.error)}}t({vendor:`zod`,extractFields:x,resolveFieldMeta:(e,t)=>m(e,t),getUnknownKeysMode:e=>s(e),validate:C});export{r as t};
|