@politty/zod 0.6.3 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/{arg-registry-DnqF81M6.d.ts → arg-registry-biPCZomY.d.ts} +54 -30
- package/dist/{argv-parser-BEwhz0XV.js → argv-parser-DVXJQeSu.js} +1 -1
- package/dist/augment.d.ts +2 -4
- package/dist/cli-main-BSBIN1DS.js +1 -0
- package/dist/{cli-main-BsyGhwyB.js → cli-main-I1ZrqkyB.js} +2 -2
- package/dist/cli-run-6gcq15BA.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/compile-cache.d.ts +1 -3
- package/dist/completion-BbIgv0cR.js +1 -0
- package/dist/{completion-RBkmaGLn.js → completion-DXVkj0Uc.js} +1 -1
- package/dist/completion.d.ts +2 -22
- package/dist/completion.js +1 -1
- package/dist/{detect-agent-EHaSY1KW.d.ts → detect-agent-hU93hctO.d.ts} +0 -4
- package/dist/docs.d.ts +1 -21
- package/dist/docs.js +32 -32
- package/dist/{dynamic-AmMBCPar.js → dynamic-CvUL5rZa.js} +2 -2
- package/dist/dynamic-CznEuQ3H.js +1 -0
- package/dist/index.d.ts +16 -50
- package/dist/index.js +1 -1
- package/dist/prompt-CNSDU99O.js +1 -0
- package/dist/prompt-clack.d.ts +2 -4
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +2 -4
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +2 -10
- package/dist/prompt.js +1 -1
- package/dist/{register-BIQ84gFS.js → register-BWzt6u5k.js} +1 -1
- package/dist/runner-BpOAXgAg.js +33 -0
- package/dist/runner-yzfeOFoF.js +1 -0
- package/dist/schema-BF9YOHU0.js +1 -0
- package/dist/schema-extractor-Cwg_WAC-.js +1 -0
- package/dist/skill.d.ts +7 -24
- package/dist/skill.js +2 -2
- package/dist/unflatten-DVeO9OZ_.js +1 -0
- package/dist/{with-completion-command--PiSDYyQ.d.ts → with-completion-command-BY-z7NOc.d.ts} +1 -9
- package/dist/{with-completion-command-BgHLkxlC.js → with-completion-command-DkZmjiSe.js} +2 -2
- package/package.json +2 -2
- package/dist/cli-main-CZOGMS_f.js +0 -1
- package/dist/cli-run-BbCf_3it.js +0 -1
- package/dist/completion-_yIqaSyj.js +0 -1
- package/dist/dynamic-B4ySeN2Q.js +0 -1
- package/dist/prompt-Ck3bxfpN.js +0 -1
- package/dist/runner-BGXVXKYA.js +0 -33
- package/dist/runner-NhDk7c4r.js +0 -1
- package/dist/schema-extractor-B5rHXThz.js +0 -1
- package/dist/schema-nhwR4VMN.js +0 -1
- package/dist/unflatten-D6YJ7e-J.js +0 -1
package/dist/docs.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as Example, C as AnyCommand, T as ArgsSchema, X as SubCommandValue, ft as SchemaLike, nt as ExtractedFields, rt as ResolvedFieldMeta } from "./arg-registry-biPCZomY.js";
|
|
2
2
|
import * as fs$1 from "node:fs";
|
|
3
|
-
//#region ../core/src/executor/subcommand-router.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Resolve a lazy-loaded command (sync or async)
|
|
6
5
|
*
|
|
@@ -8,14 +7,10 @@ import * as fs$1 from "node:fs";
|
|
|
8
7
|
* @returns The resolved command
|
|
9
8
|
*/
|
|
10
9
|
export declare function resolveLazyCommand(cmd: SubCommandValue, useMetadata?: (meta: AnyCommand) => boolean): Promise<AnyCommand>;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region ../core/src/docs/option-rows.d.ts
|
|
13
10
|
/**
|
|
14
11
|
* Column identifiers for the options markdown table, in their canonical order.
|
|
15
12
|
*/
|
|
16
13
|
type ColumnId = "option" | "alias" | "description" | "required" | "default" | "env";
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region ../core/src/docs/render-args.d.ts
|
|
19
14
|
/**
|
|
20
15
|
* Args shape type (Record of string keys to field schemas of the CLI's
|
|
21
16
|
* schema library). This matches the typical structure of `commonArgs`,
|
|
@@ -53,8 +48,6 @@ type ArgsTableOptions = {
|
|
|
53
48
|
* @returns Rendered markdown table string
|
|
54
49
|
*/
|
|
55
50
|
export declare function renderArgsTable(args: ArgsShape, options?: ArgsTableOptions): string;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region ../core/src/docs/types.d.ts
|
|
58
51
|
/** Heading level for markdown headings (1-6) */
|
|
59
52
|
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
60
53
|
/**
|
|
@@ -545,8 +538,6 @@ export declare function indexStartMarker(scope: string): string;
|
|
|
545
538
|
* Generate end marker for an index section
|
|
546
539
|
*/
|
|
547
540
|
export declare function indexEndMarker(scope: string): string;
|
|
548
|
-
//#endregion
|
|
549
|
-
//#region ../core/src/docs/default-renderers.d.ts
|
|
550
541
|
/**
|
|
551
542
|
* Render usage line
|
|
552
543
|
*/
|
|
@@ -638,8 +629,6 @@ export declare const defaultRenderers: {
|
|
|
638
629
|
/** List style options */
|
|
639
630
|
listStyle: RenderFunction;
|
|
640
631
|
};
|
|
641
|
-
//#endregion
|
|
642
|
-
//#region ../core/src/docs/doc-comparator.d.ts
|
|
643
632
|
/**
|
|
644
633
|
* Comparison result
|
|
645
634
|
*/
|
|
@@ -670,8 +659,6 @@ interface DeleteFileFs {
|
|
|
670
659
|
existsSync: typeof fs$1.existsSync;
|
|
671
660
|
unlinkSync: typeof fs$1.unlinkSync;
|
|
672
661
|
}
|
|
673
|
-
//#endregion
|
|
674
|
-
//#region ../core/src/docs/doc-generator.d.ts
|
|
675
662
|
/**
|
|
676
663
|
* Build CommandInfo from a command
|
|
677
664
|
*/
|
|
@@ -681,8 +668,6 @@ export declare function buildCommandInfo(command: AnyCommand, rootName: string,
|
|
|
681
668
|
* Returns a map of command path -> CommandInfo
|
|
682
669
|
*/
|
|
683
670
|
export declare function collectAllCommands(command: AnyCommand, rootName?: string): Promise<Map<string, CommandInfo>>;
|
|
684
|
-
//#endregion
|
|
685
|
-
//#region ../core/src/docs/example-executor.d.ts
|
|
686
671
|
/**
|
|
687
672
|
* Execute examples for a command and capture output
|
|
688
673
|
*
|
|
@@ -693,8 +678,6 @@ export declare function collectAllCommands(command: AnyCommand, rootName?: strin
|
|
|
693
678
|
* @returns Array of execution results with captured stdout/stderr
|
|
694
679
|
*/
|
|
695
680
|
export declare function executeExamples(examples: Example[], config: ExampleCommandConfig, rootCommand: AnyCommand, commandPath?: string[]): Promise<ExampleExecutionResult[]>;
|
|
696
|
-
//#endregion
|
|
697
|
-
//#region ../core/src/docs/golden-test.d.ts
|
|
698
681
|
/**
|
|
699
682
|
* Generate documentation from command definition
|
|
700
683
|
*/
|
|
@@ -712,8 +695,6 @@ export declare function assertDocMatch(config: GenerateDocConfig): Promise<void>
|
|
|
712
695
|
* @param fileSystem - Optional fs implementation (useful when fs is mocked)
|
|
713
696
|
*/
|
|
714
697
|
export declare function initDocFile(config: Pick<GenerateDocConfig, "files" | "templates" | "rootDoc"> | string, fileSystem?: DeleteFileFs): void;
|
|
715
|
-
//#endregion
|
|
716
|
-
//#region ../core/src/docs/render-index.d.ts
|
|
717
698
|
/**
|
|
718
699
|
* Configuration for a command category
|
|
719
700
|
*/
|
|
@@ -766,5 +747,4 @@ type CommandCategory = {
|
|
|
766
747
|
* @returns Rendered markdown string
|
|
767
748
|
*/
|
|
768
749
|
export declare function renderCommandIndex(command: AnyCommand, categories: CommandCategory[], options?: CommandIndexOptions): Promise<string>;
|
|
769
|
-
//#endregion
|
|
770
750
|
export type { ArgsShape, ArgsTableOptions, ArgumentsRenderContext, ArgumentsRenderFunction, CommandCategory, CommandIndexOptions, CommandInfo, DefaultRendererOptions, DeleteFileFs, ExampleCommandConfig, ExampleConfig, ExampleExecutionResult, ExamplesRenderContext, ExamplesRenderFunction, ExamplesRenderOptions, FileConfig, FileMapping, FormatterFunction, GenerateDocConfig, GenerateDocResult, HeadingLevel, OptionsRenderContext, OptionsRenderFunction, PathConfig, RenderContentOptions, RenderFunction, RootCommandInfo, RootDocConfig, SectionRenderFunction, SectionType, SimpleRenderContext, SimpleRenderFunction, SubCommandInfo, SubcommandsRenderContext, SubcommandsRenderFunction, SubcommandsRenderOptions };
|
package/dist/docs.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import{
|
|
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(
|
|
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
|
|
1
|
+
import{h as e,l as t}from"./unflatten-DVeO9OZ_.js";import"./register-BWzt6u5k.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(`
|
|
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(`
|
|
4
4
|
|
|
5
|
-
`)}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 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(`
|
|
6
6
|
|
|
7
|
-
`)}function
|
|
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(`
|
|
8
8
|
|
|
9
|
-
`)}function U(e){return k(
|
|
10
|
-
`)}function
|
|
11
|
-
`)}function
|
|
12
|
-
`)}function
|
|
13
|
-
`)}function
|
|
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
|
+
`)}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(`
|
|
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`${P(e,t)}\n${n}\n${F(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 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: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
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${
|
|
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`?H(t):U(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=>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=
|
|
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
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:
|
|
24
|
-
`)}async function
|
|
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(`
|
|
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(`
|
|
27
27
|
`)&&n.endsWith(`
|
|
28
|
-
`)?n.slice(0,-1):n}function
|
|
29
|
-
`);n.push(r??``)}return null}function
|
|
28
|
+
`)?n.slice(0,-1):n}function Je(e){let t=process.env[e];return t===`true`||t===`1`}function Ye(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 Xe(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);else 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 Ze(e){let t=e.trim();return t.length>=2&&(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))?t.slice(1,-1):t}function Qe(e){let t=Ze(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 $e(e){return e.slice(2,-2).slice(8)}function et(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 tt(e,t){let n=Qe(t);n!==null&&e.add(n)}function nt(e){let t=/* @__PURE__ */ new Set,n=Ye(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 et(e))tt(t,n)}continue}if(!i)continue;let c=e.match(/^(\s*)-\s*(.+)$/);!c||(c[1]?.length??0)<=a?i=!1:tt(t,c[2]??``)}return t}function rt(e){let t=Ye(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=Ze(c[2]??``);l===`title`?a.title=u:l===`description`&&(a.description=u)}return a}function it(e){return{rawKeys:e,commandScopes:/* @__PURE__ */ new Set,commandSections:/* @__PURE__ */ new Map,globalOptions:!1,index:!1}}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 J(e,t){return t===``||e===t||e.startsWith(t+` `)}function Y(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(Y(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 J(e,t)}function lt(e,t){let n=/* @__PURE__ */ new Set,r=e.flatMap(e=>Y(e)?st(e,t):[e]);for(let e of r)for(let r of t.keys())J(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)Y(r)?n.push(...st(r,t)):t.has(r)&&n.push(r);return n}function X(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=Y(i)?st(i,n):[i];for(let n of e)for(let e of t)Y(e)?ot(n,e)&&r.push(`"${n}" is both in files and ignored by "${e}"`):(n===e||J(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
30
|
- `)}`)}function pt(e,t){let n=[];for(let r of e)Y(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=/* @__PURE__ */ 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
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]===`
|
|
@@ -65,30 +65,30 @@ import{m as e}from"./unflatten-D6YJ7e-J.js";import"./register-BIQ84gFS.js";impor
|
|
|
65
65
|
`)}function Et(e){return e.includes(`\r
|
|
66
66
|
`)?`\r
|
|
67
67
|
`:`
|
|
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=
|
|
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
|
|
71
|
-
- `)}`)}function on(e){return[`<a id="global-options"></a>`,
|
|
72
|
-
`)}function sn(e){return[L(),on(e),
|
|
73
|
-
`)}async function cn(e,t,n,r){let i=V(n),a=
|
|
74
|
-
`)}function $(e){return
|
|
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(`
|
|
71
|
+
- `)}`)}function on(e){return[`<a id="global-options"></a>`,Be(e.args,e.options)].join(`
|
|
72
|
+
`)}function sn(e){return[L(),on(e),te()].join(`
|
|
73
|
+
`)}async function cn(e,t,n,r){let i=V(n),a=oe(n);return[i,await qe(t,e,r),a].join(`
|
|
74
|
+
`)}function $(e){return f.resolve(e)}async function ln(e,t,n,r,i){let a=e,o=[],s=!1,c=!1,l=L(),u=te(),d=await q(sn(t),r),f=Ht(a,l,u);if(!f)return n&&i?(a=a.trimEnd()+`
|
|
75
75
|
|
|
76
76
|
`+d+`
|
|
77
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=Ut(a,l,u,d);e?(a=e,c=!0):(s=!0,o.push(`Failed to replace global options section`))}else s=!0,o.push(G(f,d))}return{content:a,diffs:o,hasError:s,wasUpdated:c}}async function un(e,t,n,r,i,a,o,s){let c=e,l=[],u=!1,d=!1,f=[n,await q(i,o),r].join(`
|
|
78
78
|
`),p=Ht(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=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=
|
|
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,
|
|
84
|
-
`));let N=Array.from(O.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),I=N.length===1?N[0]:void 0;if(an(
|
|
85
|
-
`+F(n,
|
|
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,`
|
|
86
86
|
|
|
87
|
-
`),K(e,t),
|
|
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(`
|
|
88
88
|
|
|
89
|
-
`):void 0})}let V;if(
|
|
90
|
-
`,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(
|
|
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(`
|
|
91
91
|
|
|
92
|
-
`):void 0})}return{success:!B,files:z,error:B?`Documentation is out of date. ${
|
|
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(
|
|
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};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
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(t,n){C(t,x(n)),n.length===1?C(t,`--${n}`):n.includes(`-`)&&C(t,`--${e(n)}`)}function C(e,t){e.includes(t)||e.push(t)}function w(t,n){let r=[`--${t}`];t.length===1&&r.push(`-${t}`),t.includes(`-`)&&r.push(`--${e(t)}`);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(t,n,r,i){let a=new Set(w(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 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(t,n){let r=[`--${t}`];t.includes(`-`)&&r.push(`--${e(t)}`);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(i(e)).map(P)}function P(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: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)},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=i(e.args),o=r(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=r(i(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(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 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(t,n){return t!==void 0&&t.includes(`-`)&&e(t)===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(`
|
|
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
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(`
|
|
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(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as createDynamicCompleteCommand}from"./dynamic-CvUL5rZa.js";
|