@politty/zod 0.4.0 → 0.4.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/argv-parser-CawJSYjw.js +1 -0
- package/dist/cli-main-C7vClSAF.js +2 -0
- package/dist/cli-main-dbj7bXjm.js +1 -0
- package/dist/cli-run-CitZgzLl.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/completion-CizQSJgq.js +1 -0
- package/dist/{completion-OvSe3W9y.js → completion-nNzHfI1i.js} +3 -3
- package/dist/completion.js +1 -1
- package/dist/docs.js +12 -12
- package/dist/dynamic-DG-l9V-y.js +1 -0
- package/dist/dynamic-DbvYJg3o.js +6 -0
- package/dist/field-meta-D9ySul7J.js +1 -0
- package/dist/index.js +1 -1
- package/dist/log-collector-uhRWYT-z.js +1 -0
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/register-TbOCQNeI.js +1 -0
- package/dist/runner-BKyUtmoD.js +1 -0
- package/dist/runner-CBG2DbVY.js +30 -0
- package/dist/schema-extractor-fZZ2_WAZ.js +1 -0
- package/dist/{schema-DhMPssIJ.js → schema-tWeEQULd.js} +1 -1
- package/dist/skill.js +1 -1
- package/dist/{subcommand-router-D8GTMXYL.js → subcommand-router-DR2KBQAt.js} +1 -1
- package/dist/{with-completion-command-CQcqFHq8.js → with-completion-command-DG-C9_0Z.js} +2 -2
- package/package.json +1 -1
- package/dist/argv-parser-DZQ0qnXG.js +0 -1
- package/dist/cli-main-BX5IVgNq.js +0 -1
- package/dist/cli-main-uRzr666k.js +0 -2
- package/dist/cli-run-DtG5fM18.js +0 -1
- package/dist/completion-8frPuaX8.js +0 -1
- package/dist/dynamic-4uRohypH.js +0 -6
- package/dist/dynamic-C5e2NuDv.js +0 -1
- package/dist/field-meta-_l-FHbh7.js +0 -1
- package/dist/log-collector-DICKib75.js +0 -1
- package/dist/register-BXOytPt7.js +0 -1
- package/dist/runner-BTD1-gUd.js +0 -30
- package/dist/runner-BTF0HIGj.js +0 -1
- package/dist/schema-extractor-Du9ipDD4.js +0 -1
package/README.md
CHANGED
|
@@ -148,11 +148,11 @@ Arguments:
|
|
|
148
148
|
<name> Name of the person to greet
|
|
149
149
|
|
|
150
150
|
Options:
|
|
151
|
+
-g, --greeting <GREETING> Greeting phrase (default: "Hello")
|
|
152
|
+
-l, --loud Output in uppercase (default: false)
|
|
151
153
|
-h, --help Show help
|
|
152
154
|
-H, --help-all Show help with all subcommand options
|
|
153
155
|
--help-json Show help as JSON
|
|
154
|
-
-g, --greeting <GREETING> Greeting phrase (default: "Hello")
|
|
155
|
-
-l, --loud Output in uppercase (default: false)
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Every command also accepts `--help-json`, which prints the same information as a single JSON object instead of formatted text — useful for tools that consume a CLI's help programmatically (e.g. generating docs or another UI) rather than parsing `--help`'s output:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,n as t}from"./field-meta-D9ySul7J.js";const n=/* @__PURE__ */ new Set([`1`,`t`,`T`,`TRUE`,`true`,`True`]),r=/* @__PURE__ */ new Set([`0`,`f`,`F`,`FALSE`,`false`,`False`]);function i(e){return n.has(e)?!0:!r.has(e)&&e}function a(e,t){return t===`boolean`?i(e):e}function o(e){let t=e.indexOf(`=`);return t>=0?e.slice(2,t):e.slice(2)}function s(e,t){let n=o(e);if(!e.includes(`=`)){let e=t.negationMap.get(n);if(e&&t.booleanFlags.has(e))return{resolvedName:e,withoutDashes:n,isNegated:!0,isCustomNegation:!0,isSuppressedNegation:!1}}let r=e.includes(`=`);if(!r&&n.startsWith(`no-`)){let e=n.slice(3);if(e===e.toLowerCase()){let r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}}if(!r&&n.length>2&&n.startsWith(`no`)&&/[A-Z]/.test(n[2])){let e=n[2].toLowerCase()+n.slice(3),r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}return{resolvedName:t.aliasMap.get(n)??n,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!1}}const c=/^-\.?\d/;function l(e){return c.test(e)}function u(e,t={}){let{aliasMap:n=/* @__PURE__ */ new Map,booleanFlags:r=/* @__PURE__ */ new Set,arrayFlags:a=/* @__PURE__ */ new Set,definedNames:o=/* @__PURE__ */ new Set,negationMap:c=/* @__PURE__ */ new Map,defaultNegationDisabledFields:u}=t,d={aliasMap:n,booleanFlags:r,definedNames:o,negationMap:c,defaultNegationDisabledFields:u??new Set(r)},f={options:{},positionals:[],rest:[]},p=0,m=!1,h=(e,t)=>{let r=n.get(e)??e;if(a.has(r)){let e=f.options[r];Array.isArray(e)?e.push(t):e===void 0?f.options[r]=[t]:f.options[r]=[e,t]}else f.options[r]=t};for(;p<e.length;){let t=e[p];if(m){f.rest.push(t),p++;continue}if(t===`--`){m=!0,p++;continue}if(t.startsWith(`--`)){let a=t.slice(2),o=s(t,d);if(o.isSuppressedNegation){h(o.withoutDashes,!0),p++;continue}if(o.isNegated){h(o.resolvedName,!1),p++;continue}let c=a.indexOf(`=`);if(c!==-1){let e=a.slice(0,c),t=a.slice(c+1),o=n.get(e)??e;h(e,r.has(o)?i(t):t),p++}else{let t=a,i=n.get(t)??t;if(r.has(i))h(t,!0),p++;else{let n=e[p+1];n!==void 0&&(!n.startsWith(`-`)||l(n))?(h(t,n),p+=2):(h(t,!0),p++)}}continue}if(t.startsWith(`-`)&&t.length>1&&!t.startsWith(`--`)){let a=t.slice(1),o=a.indexOf(`=`);if(o!==-1){let e=a.slice(0,o),t=a.slice(o+1),s=n.get(e)??e;h(e,r.has(s)?i(t):t),p++}else if(a.length===1){let t=a,i=n.get(t)??t;if(r.has(i))h(t,!0),p++;else{let n=e[p+1];n!==void 0&&(!n.startsWith(`-`)||l(n))?(h(t,n),p+=2):(h(t,!0),p++)}}else{for(let e of a)h(e,!0);p++}continue}f.positionals.push(t),p++}return f}function d(n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set;for(let e of n.fields)o.add(e.name);for(let l of n.fields){if(!l.named)continue;l.cliName!==l.name&&r.set(l.cliName,l.name);for(let n of t(l))if(r.set(n,l.name),n.length>1&&n.includes(`-`)){let t=e(n);t!==n&&!o.has(t)&&!r.has(t)&&r.set(t,l.name)}let n=e(l.name);if(n!==l.name&&!o.has(n)&&!r.has(n)&&r.set(n,l.name),l.type===`boolean`&&i.add(l.name),l.type===`array`&&a.add(l.name),l.type===`boolean`&&l.negation!==!0&&(c.add(l.name),typeof l.negation==`string`&&(s.set(l.negation,l.name),l.negation.includes(`-`)))){let t=e(l.negation);t!==l.negation&&s.set(t,l.name)}}return{aliasMap:r,booleanFlags:i,arrayFlags:a,definedNames:o,negationMap:s,defaultNegationDisabledFields:c}}function f(e,t){return e.fields.filter(e=>e.positional&&!(e.named&&Object.hasOwn(t,e.name)))}function p(e,t){let n={...e.options},r=t.fields.filter(e=>e.positional),i=e.rest.length>0?[...e.positionals,...e.rest]:e.positionals;for(let e of r)e.named||delete n[e.name];let a=0;for(let r of f(t,e.options)){if(a>=i.length)break;if(r.type===`array`){n[r.name]=i.slice(a);break}n[r.name]=i[a],a++}return n}export{o as a,f as i,p as n,s as o,u as r,a as s,d as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as e,u as t}from"./schema-extractor-fZZ2_WAZ.js";import{n}from"./command-tLHaJHe6.js";import{n as r}from"./runner-CBG2DbVY.js";import{chmodSync as i,existsSync as a,mkdirSync as o,readFileSync as s,writeFileSync as c}from"node:fs";import{basename as l,dirname as u,extname as d,isAbsolute as f,join as p,relative as m,resolve as h}from"node:path";import{fileURLToPath as g}from"node:url";const _=`Generated by politty: compile-cache bin shim`,v=[`./cli.js`,`./cli.mjs`,`./index.js`,`./index.mjs`];function y(e){let t=h(e);for(;;){let e=p(t,`package.json`);if(a(e))return{pkg:JSON.parse(s(e,`utf8`)),dir:t};let n=u(t);if(n===t)return;t=n}}function b(e){if(!e)return[];if(typeof e.bin==`string`&&e.bin){let t=x(e);return t?[[t,e.bin]]:[]}return typeof e.bin==`object`&&e.bin!==null?Object.entries(e.bin).filter(e=>typeof e[1]==`string`&&e[1]!==``):[]}function x(e){if(e){if(typeof e.bin==`object`&&e.bin!==null){let[t]=Object.keys(e.bin);if(t)return t}if(typeof e.name==`string`&&e.name){let t=e.name;return t.startsWith(`@`)?t.split(`/`)[1]??t:t}}}function S(e){let t=u(e),n=l(e);for(let e of v)if(l(e)!==n&&a(p(t,e)))return e}function C(e,t,n){return[`#!/usr/bin/env node`,``,`// ${_}.`,`// Enables the Node.js on-disk compile cache (V8 code cache) before the`,`// CLI module graph is compiled, so warm starts skip recompilation`,`// (Node >= 22.8.0; silent no-op otherwise).`,`try {`,` const { enableCompileCache } = await import(${JSON.stringify(n)});`,` enableCompileCache(${JSON.stringify(e)});`,`} catch {`,` // ${n} is not resolvable from here (e.g. a fully`,` // bundled CLI) — start without the compile cache rather than failing`,` // the CLI.`,`}`,`await import(${JSON.stringify(t)});`,``].join(`
|
|
2
|
+
`)}function w(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function T(e){return(t={})=>E(`${e}/compile-cache`,t)}function E(e,t){let n=t.cwd??process.cwd(),r=y(n),l=r?.pkg,p=w(t.entry),m=w(t.out),T=b(l),E;if(m.length>0){if(p.length>0&&p.length!==m.length)throw Error(`--entry count (${p.length}) does not match --out count (${m.length}); pass one --out per --entry or omit --out entirely.`);E=m.map(e=>f(e)?e:h(n,e))}else{if(T.length===0||r===void 0)throw Error(`Cannot derive the output path: no bin entry in package.json. Pass --out explicitly.`);if(p.length>0&&p.length!==T.length)throw Error(`--entry count (${p.length}) does not match the package's bin entries (${T.length}); pass one --entry per bin (in declaration order) or matching --out paths.`);E=T.map(([,e])=>h(r.dir,e))}if(new Set(E).size!==E.length)throw Error(`Duplicate output paths; each shim needs a distinct output file. Check the --out values (or the bin paths in package.json when --out is omitted).`);let O=/* @__PURE__ */ new Map;if(r)for(let[e,t]of T)O.set(h(r.dir,t),e);let k=[],A=t.compileCacheSpecifier??e;if(/[\r\n\u2028\u2029]/.test(A))throw Error(`Invalid compile-cache specifier ${JSON.stringify(A)}: a module specifier cannot contain a line terminator.`);let j=E.map((e,r)=>{let i=O.get(e),o=t.program??i??x(l);if(!o)throw Error(`Cannot derive a program name: no bin or name in package.json. Pass --program explicitly.`);if(t.program===void 0&&i===void 0&&m.length>0&&k.push(`Warning: ${D(e,n)} does not match any bin path in package.json, so its cache directory uses the program name ${JSON.stringify(o)}. Pass --program to override.`),e.endsWith(`.cjs`))throw Error(`The generated shim is an ES module and cannot be written to a .cjs file. Use a .mjs (or .js in a "type": "module" package) output path.`);if(d(e)===``)throw Error(`The generated shim is an ES module and cannot be written to an extensionless file (it would not load on every supported Node.js version). Use a .mjs (or .js in a "type": "module" package) output path.`);if(e.endsWith(`.js`)&&l?.type!==`module`)throw Error(l===void 0?`The generated shim is an ES module, and no package.json was found to confirm .js files are treated as ESM. Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`:`The generated shim is an ES module, but the package is not "type": "module". Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`);let c=p[r]??S(e);if(c===void 0)throw Error(`Cannot derive an entry: none of ${v.join(`, `)} exist next to ${e}. Pass --entry explicitly.`);if(!c.startsWith(`./`)&&!c.startsWith(`../`)&&!c.startsWith(`file:`))throw Error(`Invalid entry ${c}: pass a specifier relative to the shim file ("./..." or "../...") or a file: URL.`);let f;if(c.startsWith(`file:`))try{f=g(c)}catch{f=void 0}else f=h(u(e),c);if(f===e)throw Error(`The shim at ${e} would import itself (entry ${c}). Point bin at a separate shim path (e.g. dist/bin.js) or pass a different --entry.`);if(a(e)&&!s(e,`utf8`).includes(_))throw Error(`Refusing to overwrite ${e}: it exists and was not generated by politty. If bin currently points at your real CLI entry, point it at a separate shim path (e.g. dist/bin.js) or pass --out explicitly.`);return{outputPath:e,program:o,entry:c,compileCacheSpecifier:A}});for(let e of k)console.warn(e);for(let{outputPath:e,program:t,entry:n}of j)o(u(e),{recursive:!0}),c(e,C(t,n,A)),i(e,493);return j}function D(e,t){let n=m(t,e);return n&&!n.startsWith(`..`)?n:e}const O=t({bin:e.string({description:`CLI binary or built JS entry file to invoke`,placeholder:`PATH`}),program:e.string({description:`Program name embedded in worker metadata`,placeholder:`NAME`}),shell:e.enum([`bash`,`zsh`,`fish`],{description:`Shell worker to generate`,placeholder:`SHELL`}),out:e.optionalString({description:`Output worker path (defaults to dist/completion/<shell>-worker.<ext>)`,placeholder:`PATH`}),verify:e.boolean({description:`Verify __completion-worker-path resolves to the generated worker`})}),k=n({name:`generate-worker`,description:`Generate and verify a bundled shell completion worker`,args:O,async run(e){let{generateBundledCompletionWorker:t}=await import(`./completion-CizQSJgq.js`);await t({bin:e.bin,programName:e.program,shell:e.shell,...e.out!==void 0&&{outputPath:e.out},verify:e.verify})}}),A=t({entry:e.optionalStringArray({description:`Module specifier the shim imports, relative to the shim file; repeatable, one per bin/--out (defaults to ./cli.js, ./cli.mjs, ./index.js, or ./index.mjs next to each shim)`,placeholder:`SPECIFIER`}),out:e.optionalStringArray({description:`Output path for the generated shim; repeatable, one per --entry (defaults to the bin paths in package.json)`,placeholder:`PATH`}),program:e.optionalString({description:`Program name for the cache directory, applied to all shims (defaults per shim to its bin name)`,placeholder:`NAME`}),compileCacheSpecifier:e.optionalString({description:`Module specifier the shim imports enableCompileCache from (defaults to the compile-cache subpath of the politty package running this command)`,placeholder:`SPECIFIER`})});function j(e){let t=T(e),i=n({name:`generate-shim`,description:`Generate a compile-cache bin shim that loads the real CLI via dynamic import`,args:A,run(e){let n=process.cwd(),r=t({...e.entry!==void 0&&{entry:e.entry},...e.out!==void 0&&{out:e.out},...e.program!==void 0&&{program:e.program},...e.compileCacheSpecifier!==void 0&&{compileCacheSpecifier:e.compileCacheSpecifier},cwd:n});for(let e of r)console.log(`Generated compile-cache shim: ${D(e.outputPath,n)} (program: ${e.program}, entry: ${e.entry}, compile-cache: ${e.compileCacheSpecifier})`)}}),a=n({name:`politty`,description:`politty development utilities`,subCommands:{"generate-shim":i,"generate-worker":k}});return r(a).catch(e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)})}export{T as n,j as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./cli-main-C7vClSAF.js";export{e as runPolittyCli};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./register-TbOCQNeI.js";const{runPolittyCli:e}=await import(`./cli-main-dbj7bXjm.js`);await e(`@politty/zod`);export{};
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as e}from"./compile-cache-6u9hgeWu.js";e(`politty`),await import(`./cli-run-
|
|
2
|
+
import{n as e}from"./compile-cache-6u9hgeWu.js";e(`politty`),await import(`./cli-run-CitZgzLl.js`);export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./with-completion-command-DG-C9_0Z.js";import"./dynamic-DbvYJg3o.js";import{c as e,n as t,r as n,t as r}from"./completion-nNzHfI1i.js";export{r as createCompletionCommand,t as createCompletionWorkerPathCommand,n as createRefreshCompletionCommand,e as generateBundledCompletionWorker};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,c as t,n}from"./schema-extractor-Du9ipDD4.js";import{n as r}from"./command-tLHaJHe6.js";import{c as i}from"./subcommand-router-D8GTMXYL.js";import{a,i as o,n as s,o as c,r as l,s as u}from"./with-completion-command-CQcqFHq8.js";import{_ as d,c as f,d as p,f as m,g as h,h as g,i as _,l as v,m as y,p as b,s as ee,t as te,u as ne,v as x,y as S}from"./dynamic-4uRohypH.js";import{existsSync as C,mkdirSync as re,readFileSync as w,realpathSync as T,renameSync as ie,rmSync as ae,statSync as E,writeFileSync as oe}from"node:fs";import{dirname as D,extname as se,isAbsolute as O,join as k,relative as ce,resolve as le}from"node:path";import{promisify as ue}from"node:util";import{execFile as de}from"node:child_process";function fe(e,t,n=[],r=!1){if(t.length===0)return;let i=pe(e,n);for(let e of t)e.set(me(e,i,r))}function pe(e,t){let n=new Map,r=new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function me(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ge(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=he(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function he(e){let t=[],n=new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ge(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function _e(e,t,n,r){let i=ee(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function A(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function j(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function M(e,t,n){return`__${e}_expand_${t}__${A(n)}`}function ve(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${j(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function N(e){return e.filter(e=>!e.name.startsWith(`__`))}function P(e){let t=[];for(let n of N(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function ye(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return _e(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function be(e){return e.args?t(n(e.args)):[]}function xe(e,t){return e.filter(e=>e.named).map(e=>ye(e,t))}function Se(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return _e(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ce(r,a,o=[],s=!1){let c=[];if(a.subCommands)for(let[e,t]of Object.entries(a.subCommands)){let n=i(t);n?c.push(Ce(e,n,o,s)):c.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let l=[],u=a.args?n(a.args):void 0,d={name:r,description:a.description,aliases:a.aliases,subcommands:c,options:xe(u?e(u):[],l),positionals:Se(u?t(u):[],l)};return fe(d,l,o,s),d}function F(e,t,n){return e?`${e}${n}${t}`:t}function we(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>F(e,t,`:`)))}function Te(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function I(e,t){let n=[],r=N(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?v(i.cliName,i.alias):R(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of N(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...I(r,F(t,e,`:`)));return n}function Ee(e,t){return I(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function L(e,t=``,n=``){let r=[];for(let i of N(e.subcommands)){let e=F(n,A(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=F(t,n,`:`);r.push(...L(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function De(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Oe(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function ke(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${A(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ae(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function je(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function Me(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=A(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function R(e,t){let n=v(e.cliName,e.alias);if(e.isGlobal===!0){let e=new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of p(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ne(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function z(e){let t=[];return Ne(e,[],[``],[],`root`,t),t}function Ne(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?R(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of N(e.subcommands))Ne(o,[...t,o.name],we(n,o),[...r,...n],i===`root`?A(o.name):`${i}_${A(o.name)}`,a)}function B(e,t,n=[]){let r=Pe(e),i=new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of p(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=v(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:R(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function V(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(V(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function H(e,t,r,i=!1){let a=[];if(r){let e=[];a=xe(n(r).fields,e).map(e=>(e.isGlobal=!0,e)),fe({name:t,subcommands:[],options:a,positionals:[]},e,[],i)}let o=Ce(t,e,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:t,globalOptions:a}}function U(e){try{return Math.floor(E(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=k(n,e);try{if(E(t).isFile())return t}catch{}}return null}function W(e,t){return t||process.env[j(A(e))]||(Le(e)??process.argv[1]??``)}function G(e){let t=W(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${U(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=W(t,n),o=U(a),s=x(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=`_${t}`,o=W(t,n),s=U(o),c=x(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=M(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=A(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${A(r.fieldName)}:-}`:`\${_used_field_keys_${A(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function K(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...b(o,e,t)});if(s.length===0)continue;let c=R(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function q(e,t,n,r=[]){if(e.length===0)return[];let i=g(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of He(o.valueCompletion,!1,t,{funcSuffix:n,...y(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...q(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _avail+=(--help --help-all --help-json)`),n.push(` fi`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(A).join(`_`),a=`__${t}_complete_${i}`,o=N(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...q(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=P(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...q(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=[];d.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),d.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&d.push(`# politty-completion-worker: true`),d.push(`# Generated by politty`),d.push(``),o||d.push(...Re({programName:n,binPath:t.binPath}));let p=l.length>0,m=l.filter(e=>e.isArrayOption),g=m.length>0;p&&(d.push(`__${a}_enc() {`),d.push(` local LC_ALL=C`),d.push(` local _s=$1 _r='' _c _i`),d.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),d.push(" _c=${_s:_i:1}"),d.push(` case "$_c" in`),d.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),d.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),d.push(` esac`),d.push(` done`),d.push(` printf '%s' "$_r"`),d.push(`}`),d.push(``));for(let e of l){let t=M(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
1
|
+
import{a as e,c as t,n}from"./schema-extractor-fZZ2_WAZ.js";import{n as r}from"./command-tLHaJHe6.js";import{c as i}from"./subcommand-router-DR2KBQAt.js";import{a,i as o,n as s,o as c,r as l,s as u}from"./with-completion-command-DG-C9_0Z.js";import{_ as d,c as f,d as p,f as m,g as h,h as g,i as _,l as v,m as y,p as b,s as ee,t as te,u as ne,v as x,y as S}from"./dynamic-DbvYJg3o.js";import{existsSync as C,mkdirSync as re,readFileSync as w,realpathSync as T,renameSync as ie,rmSync as ae,statSync as E,writeFileSync as oe}from"node:fs";import{dirname as D,extname as se,isAbsolute as O,join as k,relative as ce,resolve as le}from"node:path";import{promisify as ue}from"node:util";import{execFile as de}from"node:child_process";function fe(e,t,n=[],r=!1){if(t.length===0)return;let i=pe(e,n);for(let e of t)e.set(me(e,i,r))}function pe(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function me(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ge(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=he(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function he(e){let t=[],n=/* @__PURE__ */ new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ge(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function _e(e,t,n,r){let i=ee(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function A(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function j(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function M(e,t,n){return`__${e}_expand_${t}__${A(n)}`}function ve(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${j(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function N(e){return e.filter(e=>!e.name.startsWith(`__`))}function P(e){let t=[];for(let n of N(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function ye(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return _e(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function be(e){return e.args?t(n(e.args)):[]}function xe(e,t){return e.filter(e=>e.named).map(e=>ye(e,t))}function Se(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return _e(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ce(r,a,o=[],s=!1){let c=[];if(a.subCommands)for(let[e,t]of Object.entries(a.subCommands)){let n=i(t);n?c.push(Ce(e,n,o,s)):c.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let l=[],u=a.args?n(a.args):void 0,d={name:r,description:a.description,aliases:a.aliases,subcommands:c,options:xe(u?e(u):[],l),positionals:Se(u?t(u):[],l)};return fe(d,l,o,s),d}function F(e,t,n){return e?`${e}${n}${t}`:t}function we(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>F(e,t,`:`)))}function Te(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function I(e,t){let n=[],r=N(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?v(i.cliName,i.alias):R(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of N(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...I(r,F(t,e,`:`)));return n}function Ee(e,t){return I(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function L(e,t=``,n=``){let r=[];for(let i of N(e.subcommands)){let e=F(n,A(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=F(t,n,`:`);r.push(...L(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function De(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Oe(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function ke(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${A(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ae(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function je(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function Me(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=A(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function R(e,t){let n=v(e.cliName,e.alias);if(e.isGlobal===!0){let e=/* @__PURE__ */ new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of p(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ne(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function z(e){let t=[];return Ne(e,[],[``],[],`root`,t),t}function Ne(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?R(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of N(e.subcommands))Ne(o,[...t,o.name],we(n,o),[...r,...n],i===`root`?A(o.name):`${i}_${A(o.name)}`,a)}function B(e,t,n=[]){let r=Pe(e),i=/* @__PURE__ */ new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:/* @__PURE__ */ new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=/* @__PURE__ */ new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=/* @__PURE__ */ new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of p(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=v(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:R(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=/* @__PURE__ */ new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function V(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(V(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function H(e,t,r,i=!1){let a=[];if(r){let e=[];a=xe(n(r).fields,e).map(e=>(e.isGlobal=!0,e)),fe({name:t,subcommands:[],options:a,positionals:[]},e,[],i)}let o=Ce(t,e,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:t,globalOptions:a}}function U(e){try{return Math.floor(E(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=k(n,e);try{if(E(t).isFile())return t}catch{}}return null}function W(e,t){return t||process.env[j(A(e))]||(Le(e)??process.argv[1]??``)}function G(e){let t=W(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${U(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=W(t,n),o=U(a),s=x(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=`_${t}`,o=W(t,n),s=U(o),c=x(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=M(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=A(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${A(r.fieldName)}:-}`:`\${_used_field_keys_${A(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function K(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...b(o,e,t)});if(s.length===0)continue;let c=R(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function q(e,t,n,r=[]){if(e.length===0)return[];let i=g(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of He(o.valueCompletion,!1,t,{funcSuffix:n,...y(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...q(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _avail+=(--help --help-all --help-json)`),n.push(` fi`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(A).join(`_`),a=`__${t}_complete_${i}`,o=N(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...q(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=P(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...q(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=[];d.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),d.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&d.push(`# politty-completion-worker: true`),d.push(`# Generated by politty`),d.push(``),o||d.push(...Re({programName:n,binPath:t.binPath}));let p=l.length>0,m=l.filter(e=>e.isArrayOption),g=m.length>0;p&&(d.push(`__${a}_enc() {`),d.push(` local LC_ALL=C`),d.push(` local _s=$1 _r='' _c _i`),d.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),d.push(" _c=${_s:_i:1}"),d.push(` case "$_c" in`),d.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),d.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),d.push(` esac`),d.push(` done`),d.push(` printf '%s' "$_r"`),d.push(`}`),d.push(``));for(let e of l){let t=M(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
2
2
|
`);d.push(`${t}__${e}=${f(r)}`)}d.push(``)}V(s)&&(d.push(...ve(a,n)),d.push(``),d.push(`__${a}_apply_dynamic_output() {`),d.push(` local _raw="$1"`),d.push(` COMPREPLY=()`),d.push(` local _directive=0`),d.push(` local -a _lines=()`),d.push(` local _line`),d.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),d.push(" local _last=$((${#_lines[@]} - 1))"),d.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),d.push(' _directive="${_lines[$_last]#:}"'),d.push(` unset '_lines[_last]'`),d.push(` fi`),d.push(' for _line in "${_lines[@]}"; do'),d.push(` [[ -z "$_line" ]] && continue`),d.push(` COMPREPLY+=("$_line")`),d.push(` done`),d.push(' local _ip="${_inline_prefix:-}"'),d.push(` if (( _directive & ${_.DirectoryCompletion} )); then`),d.push(` compopt +o default 2>/dev/null`),d.push(` compopt -o filenames 2>/dev/null`),d.push(` local _d`),d.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),d.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),d.push(` elif (( _directive & ${_.FileCompletion} )); then`),d.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),d.push(` compopt -o filenames 2>/dev/null`),d.push(` local _f`),d.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),d.push(` else`),d.push(` compopt -o default 2>/dev/null`),d.push(` fi`),d.push(` else`),d.push(` if (( _directive & ${_.NoFileCompletion} )); then`),d.push(` compopt +o default 2>/dev/null`),d.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),d.push(` fi`),d.push(` fi`),d.push(` if (( _directive & ${_.NoSpace} )); then`),d.push(` compopt -o nospace 2>/dev/null`),d.push(` fi`),d.push(`}`),d.push(``)),d.push(`__${a}_not_used() {`),d.push(' for _u in "${_used_opts[@]}"; do'),d.push(` for _chk in "$@"; do`),d.push(` [[ "$_u" == "$_chk" ]] && return 1`),d.push(` done`),d.push(` done`),d.push(` return 0`),d.push(`}`),d.push(``),d.push(`__${a}_opt_takes_value() {`),d.push(` case "$1:$2" in`),d.push(...Ee(s,``)),d.push(` esac`),d.push(` return 1`),d.push(`}`),d.push(``),p&&(d.push(`__${a}_track_opt() {`),d.push(` case "$1:$2" in`),d.push(...Ae(u,`bash`)),d.push(` esac`),d.push(`}`),d.push(``),d.push(`__${a}_track_pos() {`),d.push(` case "$1:$2" in`),d.push(...je(u,`bash`)),d.push(` esac`),d.push(`}`),d.push(``),d.push(...h(a,Te(s)))),g&&(d.push(`__${a}_track_array_expand() {`),d.push(` case "$1:$2" in`),d.push(...Me(m,`bash`)),d.push(` esac`),d.push(`}`),d.push(``));let v=L(s);v.length>0&&(d.push(`__${a}_is_subcmd() {`),d.push(` case "$1:$2" in`),d.push(...De(v)),d.push(` esac`),d.push(` return 1`),d.push(`}`),d.push(``));for(let e of c)d.push(...Je(e,a,[]));if(d.push(`__${a}_complete_root() {`),d.push(...Ke(s.options,s.positionals,a,`root`)),d.push(` if [[ -z "$_inline_prefix" ]] && __${a}_opt_takes_value "" "$_prev"; then return; fi`),d.push(` if [[ -n "$_inline_prefix" ]] && __${a}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),s.positionals.length>0?(d.push(` if (( _after_dd )); then`),d.push(...q(s.positionals,a,`root`,s.options).map(e=>` ${e}`)),d.push(` return`),d.push(` fi`)):d.push(` if (( _after_dd )); then return; fi`),d.push(` if [[ "$_cur" == -* ]]; then`),d.push(` local -a _avail=()`),d.push(...qe(s.options,a)),d.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),d.push(` compopt +o default 2>/dev/null`),c.length>0){d.push(` else`);let e=P(s.subcommands).map(e=>e.name).join(` `);d.push(...Ge(e,s.positionals,a,`root`,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(d.push(` else`),d.push(...q(s.positionals,a,`root`,s.options).map(e=>` ${e}`)));d.push(` fi`),d.push(`}`),d.push(``);let y=Oe(v,a).join(`
|
|
3
3
|
`);d.push(`_${a}_completions() {`),d.push(` COMPREPLY=()`),d.push(``),d.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),d.push(` local -a _words=()`),d.push(` local _i=1`),d.push(` while (( _i <= COMP_CWORD )); do`),d.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),d.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),d.push(` (( _i += 2 ))`),d.push(` else`),d.push(' _words+=("${COMP_WORDS[_i]}")'),d.push(` (( _i++ ))`),d.push(` fi`),d.push(` done`),d.push(``),d.push(` local _cur=""`),d.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),d.push(` local _inline_prefix=""`),d.push(``),d.push(` local _prev=""`),d.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),d.push(``),d.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),d.push(` local -a _used_opts=()`),p&&d.push(` local -a _pos_words=()`),d.push(` local _any_opt_used=0`),p&&(d.push(` ${K(`_arg_values_`)}`),d.push(` ${K(`_global_arg_values_`)}`)),g&&(d.push(` ${K(`_used_field_keys_`)}`),d.push(` ${K(`_global_used_field_keys_`)}`),d.push(` ${K(`_global_arr_seen_`)}`)),d.push(``),d.push(` local _j=0`),d.push(" while (( _j < ${#_words[@]} - 1 )); do"),d.push(' local _w="${_words[_j]}"'),d.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),d.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=p?`_pos_words+=("$_w"); `:``;d.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),d.push(` if [[ "$_w" == -*=* ]]; then`),d.push(' _used_opts+=("${_w%%=*}")'),d.push(` _any_opt_used=1`),p&&(d.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),g&&d.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),d.push(` (( _j++ )); continue`),d.push(` fi`),d.push(` if [[ "$_w" == -* ]]; then`),d.push(` _used_opts+=("$_w")`),d.push(` _any_opt_used=1`),d.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),d.push(' local _next="${_words[_j+1]:-}"'),d.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),p&&(d.push(` if (( _skip_next )); then`),d.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),g&&(d.push(" if (( _j + 2 < ${#_words[@]} )); then"),d.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),d.push(` fi`)),d.push(` fi`)),d.push(` fi`),d.push(` (( _j++ )); continue`),d.push(` fi`);let ee=g?`; ${K(`_arg_values_`)}; ${K(`_used_field_keys_`)}; ${K(`_global_arr_seen_`)}`:p?`; ${K(`_arg_values_`)}`:``,te=p?`_pos_words+=("$_w"); `:``;return v.length>0?d.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${p?`; _pos_words=()`:``}${ee}; else ${te}(( _pos_count++ )); fi`):(p&&d.push(` _pos_words+=("$_w")`),d.push(` (( _pos_count++ ))`)),d.push(` (( _j++ ))`),d.push(` done`),p&&d.push(` __${a}_track_positionals`),d.push(``),d.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),d.push(' _inline_prefix="${_cur%%=*}="'),d.push(' _cur="${_cur#*=}"'),d.push(` fi`),d.push(``),d.push(` case "$_subcmd" in`),d.push(y),d.push(` *) __${a}_complete_root ;;`),d.push(` esac`),d.push(`}`),d.push(``),o||d.push(`complete -o default -F _${a}_completions ${n}`),d.push(``),{script:d.join(`
|
|
4
4
|
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
@@ -13,7 +13,7 @@ source ~/.bashrc`}}const Xe=ue(de),Ze={bash:`bash`,zsh:`zsh`,fish:`fish`},Qe=[`#
|
|
|
13
13
|
`)){let t=e.match(/^# cmd-shim-target=(.+)$/);t&&(n=t[1])}return n}catch{return null}}function J(e,t){if(!t)return;e.add(D(le(t)));try{e.add(D(T(t)))}catch{}let n=rt(t);n&&J(e,n)}function it(e){return w(e,`utf8`).split(`
|
|
14
14
|
`,24).join(`
|
|
15
15
|
`)}function at(e,t){return[...Qe,`# program: ${e}`,`# shell: ${t}`]}function ot(e,t,n){let r=e.split(`
|
|
16
|
-
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function st(e,t,n){if(!C(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function ct(e,t,n){try{return st(e,t,n),!0}catch{return!1}}function lt(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n
|
|
16
|
+
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function st(e,t,n){if(!C(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function ct(e,t,n){try{return st(e,t,n),!0}catch{return!1}}function lt(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n=/* @__PURE__ */ new Set;e.binPath!==void 0&&J(n,e.binPath),process.argv[1]&&J(n,process.argv[1]),J(n,W(e.programName,e.binPath));for(let n of t)if(O(n)&&ct(n,e.programName,e.shell))return n;for(let r of n)for(let n of t){if(O(n))continue;let t=k(r,n);if(ct(t,e.programName,e.shell))return t}return null}function ut(e,t){return O(e)?e:le(t,e)}function dt(e,t,n){let r=e.startsWith(`.`)||e.includes(`/`)||e.includes(`\\`)?ut(e,n):e,i=se(r).toLowerCase();return i===`.js`||i===`.mjs`||i===`.cjs`?{command:process.execPath,args:[r,...t]}:{command:r,args:[...t]}}async function ft(e,t,n){let r=dt(e,t,n.cwd);try{let{stdout:e,stderr:t}=await Xe(r.command,r.args,{cwd:n.cwd,env:{...process.env,...n.env},encoding:`utf8`,maxBuffer:10485760});return{stdout:e,stderr:t}}catch(e){let t=typeof e==`object`&&e&&`stderr`in e?String(e.stderr??``).trim():``,n=t?`\n${t}`:``;throw Error(`Command failed: ${r.command} ${r.args.join(` `)}${n}`,e instanceof Error?{cause:e}:void 0)}}function pt(e){let t=E(e);if(!t.isFile()||t.size===0)throw Error(`Generated bundled completion worker is empty: ${e}`);return t.size}function mt(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KiB`}function ht(e,t,n){let r=ce(n,e);console.log(`Generated bundled completion worker: ${r&&!r.startsWith(`..`)?r:e} (${mt(t)})`)}async function gt(e){let t=e.cwd??process.cwd(),n=ut(e.outputPath??et(e.shell),t);re(D(n),{recursive:!0}),ae(n,{force:!0}),await ft(e.bin,[`__refresh-completion`,e.shell,n,`--static`,`--worker`],{cwd:t,env:e.env});let r=pt(n);st(n,e.programName,e.shell);let i;if(e.verify){let r=(await ft(e.bin,[`__completion-worker-path`,e.shell],{cwd:t,env:e.env})).stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);if(r.length!==1)throw Error(`Expected __completion-worker-path ${e.shell} to print exactly one path, got ${r.length}.`);i=ut(r[0],t);let a=T(n),o=T(i);if(o!==a)throw Error(`Bundled completion worker path mismatch: generated ${a}, reported ${o}`)}return e.quiet||ht(n,r,t),{outputPath:n,size:r,...i!==void 0&&{reportedPath:i}}}function _t(e){return x(`/${e}/node-compile-cache`)}function vt(e){return e?x(`${e}/node-compile-cache`):void 0}function yt(e,t){return e?x(`${e}/completion-worker.${t}`):void 0}function bt(e,t){return x(`/${e}/completion-worker.${t}`)}function Y(e,t,n){return t?` ${e} ${t}`:` ${e} "\${XDG_CACHE_HOME:-$HOME/.cache}"${n}`}function xt(e,t){return e?` printf '%s\\n' ${e}`:[` set -l _cache_root "$XDG_CACHE_HOME"`,` test -n "$_cache_root"; or set _cache_root "$HOME/.cache"`,` printf '%s\\n' "$_cache_root"${t}`].join(`
|
|
17
17
|
`)}function St(e,t){return nt(e.programName,t,e.bundledWorker).map(x).join(` `)}function Ct(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}"`}function wt(e){return nt(e.programName,`fish`,e.bundledWorker).map(Ct).join(` `)}function Tt(e){return e.bundledWorker?.queryCommand===!0&&!e.bundledWorker.disabled}function Et(e,t){let{programName:n}=t,r=A(n),i=`${r}_worker`,a=j(i),o=j(r),s=x(n),c=Y(`printf '%s\\n'`,vt(t.cacheDir),_t(n)),l=Y(`printf '%s\\n'`,yt(t.cacheDir,`bash`),bt(n,`bash`)),u=St(t,`bash`),d=Tt(t),f=[];return f.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),f.push(`# Generated by politty`),f.push(`# politty-completion-mode: dispatcher`),f.push(``),f.push(`__${r}_resolve_bin() {`),f.push(` if [[ -n "\${${o}:-}" ]]; then`),f.push(` printf '%s\\n' "\${${o}}"`),f.push(` return 0`),f.push(` fi`),f.push(` type -P ${s} 2>/dev/null`),f.push(`}`),f.push(``),f.push(`__${r}_node_compile_cache_dir() {`),f.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),f.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),f.push(` return 0`),f.push(` fi`),f.push(c),f.push(`}`),f.push(``),f.push(`__${r}_static_worker_path() {`),f.push(l),f.push(`}`),f.push(``),f.push(`__${r}_worker_file_sig() {`),f.push(` local _worker="$1" _sig`),f.push(` _sig=${S(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),f.push(` printf '%s\\n' "$_sig"`),f.push(`}`),f.push(``),f.push(`__${r}_is_worker_file() {`),f.push(` local _worker="$1" _head`),f.push(` [[ -f "$_worker" ]] || return 1`),f.push(` _head="$(head -n 24 "$_worker" 2>/dev/null)" || return 1`),f.push(` _head=$'\\n'"$_head"$'\\n'`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# shell: bash"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),f.push(`}`),f.push(``),f.push(`__${r}_load_worker() {`),f.push(` local _worker="$1" _sig _key`),f.push(` __${r}_is_worker_file "$_worker" || return 1`),f.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),f.push(` _key="$_worker:$_sig"`),f.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),f.push(` source "$_worker" 2>/dev/null || return 1`),f.push(` __${r}_loaded_worker_key="$_key"`),f.push(` fi`),f.push(` declare -F _${i}_completions >/dev/null 2>&1`),f.push(`}`),f.push(``),f.push(`__${r}_realpath() {`),f.push(` local _path="$1" _dir _target _limit=0`),f.push(` while [[ -L "$_path" && $_limit -lt 40 ]]; do`),f.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),f.push(` _target="$(readlink "$_path")" || return 1`),f.push(` if [[ "$_target" == /* ]]; then _path="$_target"; else _path="$_dir/$_target"; fi`),f.push(` (( _limit++ ))`),f.push(` done`),f.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),f.push(` printf '%s\\n' "$_dir/$(basename "$_path")"`),f.push(`}`),f.push(``),f.push(`__${r}_worker_from_dir() {`),f.push(` local _dir="$1" _rel _candidate`),u.length>0&&(f.push(` for _rel in ${u}; do`),f.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),f.push(` if __${r}_is_worker_file "$_candidate"; then`),f.push(` printf '%s\\n' "$_candidate"`),f.push(` return 0`),f.push(` fi`),f.push(` done`)),f.push(` return 1`),f.push(`}`),f.push(``),f.push(`__${r}_cmd_shim_target() {`),f.push(` sed -n 's/^# cmd-shim-target=//p' "$1" 2>/dev/null | tail -n 1`),f.push(`}`),f.push(``),f.push(`__${r}_bundled_worker_path() {`),f.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),f.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),f.push(` if [[ -n "$_real" ]]; then`),f.push(` _dir="$(dirname "$_real")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` fi`),f.push(` _dir="$(dirname "$_bin")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),f.push(` if [[ -n "$_target" ]]; then`),f.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),f.push(` _dir="$(dirname "$_real")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` fi`),d&&(f.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),f.push(` printf '%s\\n' "\${__${r}_queried_worker}"`),f.push(` return 0`),f.push(` fi`),f.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path bash 2>/dev/null)" || _reported=""`),f.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),f.push(` __${r}_queried_bin="$_bin"`),f.push(` __${r}_queried_worker="$_reported"`),f.push(` printf '%s\\n' "$_reported"`),f.push(` return 0`),f.push(` fi`)),f.push(` return 1`),f.push(`}`),f.push(``),f.push(`__${r}_bin_sig() {`),f.push(` local _bin="$1" _sig`),f.push(` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`),f.push(` printf '%s\\n' "$_sig"`),f.push(`}`),f.push(``),f.push(`__${r}_worker_matches_bin() {`),f.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),f.push(` [[ -f "$_worker" ]] || return 1`),f.push(` _head="$(head -n 12 "$_worker" 2>/dev/null)" || return 1`),f.push(` grep -qxF "# politty-bin-sig: $_sig" <<< "$_head" || return 1`),f.push(` grep -qxF "# politty-bin-path: $_bin" <<< "$_head" || return 1`),f.push(`}`),f.push(``),f.push(`__${r}_apply_dynamic_output() {`),f.push(` local _raw="$1" _cur="$2" _inline_prefix="$3"`),f.push(` COMPREPLY=()`),f.push(` local _directive=0`),f.push(` local -a _lines=() _exts=() _matchers=()`),f.push(` local _line`),f.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),f.push(" local _last=$((${#_lines[@]} - 1))"),f.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" == :[0-9]* ]]; then'),f.push(` local -a _meta=()`),f.push(` IFS=$'\\t' read -r -a _meta <<< "\${_lines[$_last]}"`),f.push(` unset '_lines[_last]'`),f.push(' _directive="${_meta[0]#:}"'),f.push(` local _m`),f.push(' for _m in "${_meta[@]:1}"; do'),f.push(` if [[ "$_m" == @ext:* ]]; then`),f.push(` IFS=',' read -r -a _exts <<< "\${_m#@ext:}"`),f.push(` elif [[ "$_m" == @matcher:* ]]; then`),f.push(` IFS=',' read -r -a _matchers <<< "\${_m#@matcher:}"`),f.push(` fi`),f.push(` done`),f.push(` fi`),f.push(' for _line in "${_lines[@]}"; do'),f.push(` [[ -z "$_line" ]] && continue`),f.push(` COMPREPLY+=("$_line")`),f.push(` done`),f.push(' local _ip="${_inline_prefix:-}"'),f.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _f _ext _pat _base _ok`),f.push(` while IFS= read -r _f; do`),f.push(` if [[ -d "$_f" ]]; then`),f.push(' COMPREPLY+=("${_ip}${_f}")'),f.push(` continue`),f.push(` fi`),f.push(` _ok=0`),f.push(" if (( ${#_exts[@]} > 0 )); then"),f.push(' for _ext in "${_exts[@]}"; do'),f.push(` [[ -n "$_ext" && "$_f" == *."$_ext" ]] && _ok=1`),f.push(` done`),f.push(` fi`),f.push(" if (( ${#_matchers[@]} > 0 )); then"),f.push(' _base="${_f##*/}"'),f.push(' for _pat in "${_matchers[@]}"; do'),f.push(` [[ -n "$_pat" && "$_base" == $_pat ]] && _ok=1`),f.push(` done`),f.push(` fi`),f.push(' (( _ok )) && COMPREPLY+=("${_ip}${_f}")'),f.push(` done < <(compgen -f -- "$_cur")`),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${_.DirectoryCompletion} )); then`),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _d`),f.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${_.FileCompletion} )); then`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _p`),f.push(' while IFS= read -r _p; do COMPREPLY+=("${_ip}${_p}"); done < <(compgen -f -- "$_cur")'),f.push(` elif (( _directive & ${_.NoFileCompletion} )); then`),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` fi`),f.push(` if (( _directive & ${_.NoSpace} )); then`),f.push(` compopt -o nospace 2>/dev/null`),f.push(` fi`),f.push(`}`),f.push(``),f.push(`_${r}_completions() {`),f.push(` COMPREPLY=()`),f.push(` local -a _words=()`),f.push(` local _i=1`),f.push(` while (( _i <= COMP_CWORD )); do`),f.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),f.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),f.push(` (( _i += 2 ))`),f.push(` else`),f.push(' _words+=("${COMP_WORDS[_i]}")'),f.push(` (( _i++ ))`),f.push(` fi`),f.push(` done`),f.push(` local _cur="" _inline_prefix=""`),f.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),f.push(` local _after_dd=0 _di=0`),f.push(" while (( _di < ${#_words[@]} - 1 )); do"),f.push(' [[ "${_words[_di]}" == "--" ]] && { _after_dd=1; break; }'),f.push(` (( _di++ ))`),f.push(` done`),f.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),f.push(' _inline_prefix="${_cur%%=*}="'),f.push(' _cur="${_cur#*=}"'),f.push(` fi`),f.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),f.push(` _bin="$(__${r}_resolve_bin)" || _bin=""`),f.push(` [[ -n "$_bin" ]] || return 0`),f.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)" || _node_compile_cache=""`),f.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")" || _bundled_worker=""`),f.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),f.push(` return 0`),f.push(` fi`),f.push(` _worker="$(__${r}_static_worker_path)" || _worker=""`),f.push(` _sig="$(__${r}_bin_sig "$_bin")" || _sig=""`),f.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),f.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),f.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion bash "$_worker" --static --worker 2>/dev/null`),f.push(` fi`),f.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),f.push(` return 0`),f.push(` fi`),f.push(` fi`),f.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell bash -- "${_words[@]}" 2>/dev/null) || return 0'),f.push(` __${r}_apply_dynamic_output "$_out" "$_cur" "$_inline_prefix"`),f.push(`}`),f.push(``),f.push(`complete -o default -F _${r}_completions ${n}`),f.push(``),{script:f.join(`
|
|
18
18
|
`),shell:`bash`,installInstructions:`# To enable dispatcher bash completions, add this to your ~/.bashrc:
|
|
19
19
|
eval "$(${n} completion bash)"
|
|
@@ -41,7 +41,7 @@ ${n} completion zsh --static`}}function Ot(e,t){let{programName:n}=t,r=A(n),i=`$
|
|
|
41
41
|
${n} completion fish --install
|
|
42
42
|
|
|
43
43
|
# To generate the older static script:
|
|
44
|
-
${n} completion fish --static`}}function kt(e,t){switch(H(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return Et(e,t);case`zsh`:return Dt(e,t);case`fish`:return Ot(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function At(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function jt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=A(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=A(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${At(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Mt(e.matcher):e.extensions?.length?Nt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Mt(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Nt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Pt(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=jt(i.valueCompletion,n,b(i,e,t));if(a.length===0)continue;let o=R(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Ft(e,t,n,r=`$_pos_count`){let i=m(e,t);if(i.every(e=>e===void 0))return;let a=[` set _slot -1; set _left ${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?`; and __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`set _slot ${e.position}`:`if test $_left -eq 0; set _slot ${e.position}; else; set _left (math $_left - 1); end`;a.push(` if test $_slot -lt 0${o}; ${s}; end`)}),a}function Z(e,t,n=[]){if(e.length===0)return[];let r=Ft(e,n,t),i=r!==void 0,a=i?[` set -l _slot; set -l _left`,...r]:[];for(let r of e){let o=jt(r.valueCompletion,t,y(r,n,e));if(o.length!==0){i?a.push(` if test $_slot -eq ${r.position}`):r.variadic?a.push(` if test $_pos_count -ge ${r.position}`):a.push(` if test $_pos_count -eq ${r.position}`);for(let e of o)a.push(` ${e}`);a.push(` return`),a.push(` end`)}}return a}function It(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function Lt(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` if test $_any_opt_used -eq 0`),n.push(` echo "--help Show help"`),n.push(` echo "--help-all Show help with all subcommand options"`),n.push(` echo "--help-json Show help as JSON"`),n.push(` end`),n}function Rt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(A).join(`_`)}`,a=N(e.subcommands),o=[];for(let e of a)o.push(...Rt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Pt(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...Lt(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=P(e.subcommands);o.push(...It(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function zt(e,t){let n=[];for(let r of I(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Bt(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=l.length>0,f=l.filter(e=>e.isArrayOption),p=f.length>0,m=[];if(m.push(...G({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),!o){let e=W(n,t.binPath),r=U(e),o=j(i),s=`__${a}_refresh_completion`;m.push(`function ${s} --no-scope-shadowing`),m.push(` set -l _bin $${o}`),m.push(` test -z "$_bin"; and set _bin (command -v ${n})`),m.push(` test -z "$_bin"; and return 1`),m.push(` set -l _sig ${S(`$_bin`,{shell:`fish`})}`),m.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),m.push(` set -l _target (status current-filename)`),m.push(` test -n "$_target"; and test -f "$_target"; or return 1`),m.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),m.push(` and source "$_target" 2>/dev/null`),m.push(` and return 0`),m.push(` return 1`),m.push(`end`),m.push(`${s}`),m.push(`set -l _politty_refreshed $status`),m.push(`functions -e ${s}`),m.push(`test $_politty_refreshed -eq 0; and return`),m.push(``)}if(V(s)&&(m.push(`function __${a}_invoke_complete`),m.push(` set -l _shell $argv[1]`),m.push(` set -l _argv $argv[2..]`),m.push(` set -l _bin ${n}`),m.push(` if set -q ${j(a)}`),m.push(` set _bin $${j(a)}`),m.push(` end`),m.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),m.push(`end`),m.push(``),m.push(`function __${a}_apply_dynamic_output`),m.push(` set -l _cur $argv[1]`),m.push(` set -l _directive 0`),m.push(` set -l _emitted 0`),m.push(` set -l _prev ""`),m.push(` set -l _has_prev 0`),m.push(` while read -l _l`),m.push(` if test $_has_prev -eq 1`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` set _prev $_l`),m.push(` set _has_prev 1`),m.push(` end`),m.push(` if test $_has_prev -eq 1`),m.push(` if string match -qr '^:[0-9]+$' -- $_prev`),m.push(` set _directive (string sub -s 2 -- $_prev)`),m.push(` else`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` end`),m.push(` if test (math "bitand($_directive, ${_.DirectoryCompletion})") -ne 0`),m.push(` __fish_complete_directories "$_cur"`),m.push(` else if test (math "bitand($_directive, ${_.FileCompletion})") -ne 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${_.NoFileCompletion})") -eq 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` end`),m.push(`end`),m.push(``)),m.push(`function __${a}_not_used --no-scope-shadowing`),m.push(` for _chk in $argv`),m.push(` if contains -- "$_chk" $_used_opts`),m.push(` return 1`),m.push(` end`),m.push(` end`),m.push(` return 0`),m.push(`end`),m.push(``),m.push(`function __${a}_opt_takes_value`),m.push(` switch "$argv[1]:$argv[2]"`),m.push(...zt(s,``)),m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${A(e.fieldName)}`;m.push(`function __${a}_track_opt --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_pos --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_positionals --no-scope-shadowing`),m.push(` set -l _k 0`),m.push(` for _w in $_pos_words`),m.push(` set -l _slot $_k; set -l _left`),m.push(` switch "$_subcmd"`);for(let e of Te(s)){m.push(` case ${e.pathStrs.map(e=>`"${e}"`).join(` `)}`);for(let t of Ft(e.positionals,e.options,a,`$_k`)??[])m.push(` ${t}`)}m.push(` end`),m.push(` __${a}_track_pos "$_subcmd" "$_slot" "$_w"`),m.push(` set _k (math $_k + 1)`),m.push(` end`),m.push(`end`),m.push(``)}if(p){m.push(`function __${a}_track_array_expand --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of f){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=A(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;m.push(` case ${t}`),m.push(` if string match -q '*=*' -- "$argv[3]"`),m.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),m.push(` if test -n "$_k"`),e.isGlobal?(m.push(` if not set -q _global_arr_seen_${n}`),m.push(` set -g ${r}${n} "$_k"`),m.push(` set -g _global_arr_seen_${n} 1`),m.push(` else if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)):(m.push(` if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)),m.push(` end`),m.push(` end`)}m.push(` end`),m.push(`end`),m.push(``)}let h=L(s);if(h.length>0){m.push(`function __${a}_is_subcmd`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of h)m.push(` case "${e.lookupPattern}"`),m.push(` return 0`);m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``)}for(let e of c)m.push(...Rt(e,a,[]));if(m.push(`function __${a}_complete_root --no-scope-shadowing`),m.push(...Pt(s.options,s.positionals,a)),m.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(m.push(` if test $_after_dd -eq 1`),m.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),m.push(` return`),m.push(` end`)):m.push(` if test $_after_dd -eq 1; return; end`),m.push(` if string match -q -- '-*' "$_cur"`),m.push(...Lt(s.options,a)),c.length>0){m.push(` else`);let e=P(s.subcommands);m.push(...It(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(m.push(` else`),m.push(...Z(s.positionals,a,s.options)));if(m.push(` end`),m.push(`end`),m.push(``),m.push(`function __fish_${a}_complete`),m.push(` set -l _args (commandline -opc)`),m.push(` set -e _args[1]`),m.push(``),m.push(` set -l _ct (commandline -ct)`),m.push(` if test (count $_ct) -eq 0`),m.push(` set -a _args ""`),m.push(` else`),m.push(` set -a _args $_ct`),m.push(` end`),m.push(``),m.push(` set -l _cur ""`),m.push(` if test (count $_args) -gt 0`),m.push(` set _cur "$_args[-1]"`),m.push(` end`),m.push(``),m.push(` set -l _prev ""`),m.push(` if test (count $_args) -gt 1`),m.push(` set _prev "$_args[-2]"`),m.push(` end`),m.push(``),m.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),m.push(` set -l _used_opts`),d&&m.push(` set -l _pos_words`),m.push(` set -l _any_opt_used 0`),m.push(``),d)for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`),m.push(` set -e _global_arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`);m.push(` set -l _j 1`),m.push(` set -l _limit (math (count $_args) - 1)`),m.push(` while test $_j -le $_limit`),m.push(` set -l _w "$_args[$_j]"`),m.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),m.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let g=d?`set -a _pos_words "$_w"; `:``;if(m.push(` if test $_after_dd -eq 1; ${g}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),m.push(` if string match -q -- '-*=*' "$_w"`),m.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),m.push(` set -a _used_opts "$_opt"`),m.push(` set _any_opt_used 1`),d&&(m.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),m.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),p&&m.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),m.push(` if string match -q -- '-*' "$_w"`),m.push(` set -a _used_opts "$_w"`),m.push(` set _any_opt_used 1`),m.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),m.push(` set -l _next ""`),m.push(` set -l _next_idx (math $_j + 1)`),m.push(` if test $_next_idx -le (count $_args)`),m.push(` set _next "$_args[$_next_idx]"`),m.push(` end`),m.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),m.push(` set _skip_next 1`),d&&(m.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),p&&(m.push(` if test $_j -lt $_limit`),m.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` end`))),m.push(` end`),m.push(` end`),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),h.length>0){if(m.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),m.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),m.push(` set _used_opts; set _pos_count 0`),d){m.push(` set _pos_words`);for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`)}m.push(` else`),d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`),m.push(` end`)}else d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`);m.push(` set _j (math $_j + 1)`),m.push(` end`),d&&m.push(` __${a}_track_positionals`),m.push(``),m.push(` switch "$_subcmd"`);for(let e of h)m.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return m.push(` case '*'; __${a}_complete_root`),m.push(` end`),m.push(`end`),m.push(``),o||(m.push(`# Clear existing completions`),m.push(`complete -e -c ${n}`),m.push(``),m.push(`# Register completion`),m.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),m.push(``),{script:m.join(`
|
|
44
|
+
${n} completion fish --static`}}function kt(e,t){switch(H(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return Et(e,t);case`zsh`:return Dt(e,t);case`fish`:return Ot(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function At(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function jt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=A(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=A(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${At(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=/* @__PURE__ */ new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Mt(e.matcher):e.extensions?.length?Nt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Mt(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Nt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Pt(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=jt(i.valueCompletion,n,b(i,e,t));if(a.length===0)continue;let o=R(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Ft(e,t,n,r=`$_pos_count`){let i=m(e,t);if(i.every(e=>e===void 0))return;let a=[` set _slot -1; set _left ${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?`; and __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`set _slot ${e.position}`:`if test $_left -eq 0; set _slot ${e.position}; else; set _left (math $_left - 1); end`;a.push(` if test $_slot -lt 0${o}; ${s}; end`)}),a}function Z(e,t,n=[]){if(e.length===0)return[];let r=Ft(e,n,t),i=r!==void 0,a=i?[` set -l _slot; set -l _left`,...r]:[];for(let r of e){let o=jt(r.valueCompletion,t,y(r,n,e));if(o.length!==0){i?a.push(` if test $_slot -eq ${r.position}`):r.variadic?a.push(` if test $_pos_count -ge ${r.position}`):a.push(` if test $_pos_count -eq ${r.position}`);for(let e of o)a.push(` ${e}`);a.push(` return`),a.push(` end`)}}return a}function It(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function Lt(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` if test $_any_opt_used -eq 0`),n.push(` echo "--help Show help"`),n.push(` echo "--help-all Show help with all subcommand options"`),n.push(` echo "--help-json Show help as JSON"`),n.push(` end`),n}function Rt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(A).join(`_`)}`,a=N(e.subcommands),o=[];for(let e of a)o.push(...Rt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Pt(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...Lt(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=P(e.subcommands);o.push(...It(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function zt(e,t){let n=[];for(let r of I(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Bt(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=l.length>0,f=l.filter(e=>e.isArrayOption),p=f.length>0,m=[];if(m.push(...G({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),!o){let e=W(n,t.binPath),r=U(e),o=j(i),s=`__${a}_refresh_completion`;m.push(`function ${s} --no-scope-shadowing`),m.push(` set -l _bin $${o}`),m.push(` test -z "$_bin"; and set _bin (command -v ${n})`),m.push(` test -z "$_bin"; and return 1`),m.push(` set -l _sig ${S(`$_bin`,{shell:`fish`})}`),m.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),m.push(` set -l _target (status current-filename)`),m.push(` test -n "$_target"; and test -f "$_target"; or return 1`),m.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),m.push(` and source "$_target" 2>/dev/null`),m.push(` and return 0`),m.push(` return 1`),m.push(`end`),m.push(`${s}`),m.push(`set -l _politty_refreshed $status`),m.push(`functions -e ${s}`),m.push(`test $_politty_refreshed -eq 0; and return`),m.push(``)}if(V(s)&&(m.push(`function __${a}_invoke_complete`),m.push(` set -l _shell $argv[1]`),m.push(` set -l _argv $argv[2..]`),m.push(` set -l _bin ${n}`),m.push(` if set -q ${j(a)}`),m.push(` set _bin $${j(a)}`),m.push(` end`),m.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),m.push(`end`),m.push(``),m.push(`function __${a}_apply_dynamic_output`),m.push(` set -l _cur $argv[1]`),m.push(` set -l _directive 0`),m.push(` set -l _emitted 0`),m.push(` set -l _prev ""`),m.push(` set -l _has_prev 0`),m.push(` while read -l _l`),m.push(` if test $_has_prev -eq 1`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` set _prev $_l`),m.push(` set _has_prev 1`),m.push(` end`),m.push(` if test $_has_prev -eq 1`),m.push(` if string match -qr '^:[0-9]+$' -- $_prev`),m.push(` set _directive (string sub -s 2 -- $_prev)`),m.push(` else`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` end`),m.push(` if test (math "bitand($_directive, ${_.DirectoryCompletion})") -ne 0`),m.push(` __fish_complete_directories "$_cur"`),m.push(` else if test (math "bitand($_directive, ${_.FileCompletion})") -ne 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${_.NoFileCompletion})") -eq 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` end`),m.push(`end`),m.push(``)),m.push(`function __${a}_not_used --no-scope-shadowing`),m.push(` for _chk in $argv`),m.push(` if contains -- "$_chk" $_used_opts`),m.push(` return 1`),m.push(` end`),m.push(` end`),m.push(` return 0`),m.push(`end`),m.push(``),m.push(`function __${a}_opt_takes_value`),m.push(` switch "$argv[1]:$argv[2]"`),m.push(...zt(s,``)),m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${A(e.fieldName)}`;m.push(`function __${a}_track_opt --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_pos --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_positionals --no-scope-shadowing`),m.push(` set -l _k 0`),m.push(` for _w in $_pos_words`),m.push(` set -l _slot $_k; set -l _left`),m.push(` switch "$_subcmd"`);for(let e of Te(s)){m.push(` case ${e.pathStrs.map(e=>`"${e}"`).join(` `)}`);for(let t of Ft(e.positionals,e.options,a,`$_k`)??[])m.push(` ${t}`)}m.push(` end`),m.push(` __${a}_track_pos "$_subcmd" "$_slot" "$_w"`),m.push(` set _k (math $_k + 1)`),m.push(` end`),m.push(`end`),m.push(``)}if(p){m.push(`function __${a}_track_array_expand --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of f){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=A(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;m.push(` case ${t}`),m.push(` if string match -q '*=*' -- "$argv[3]"`),m.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),m.push(` if test -n "$_k"`),e.isGlobal?(m.push(` if not set -q _global_arr_seen_${n}`),m.push(` set -g ${r}${n} "$_k"`),m.push(` set -g _global_arr_seen_${n} 1`),m.push(` else if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)):(m.push(` if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)),m.push(` end`),m.push(` end`)}m.push(` end`),m.push(`end`),m.push(``)}let h=L(s);if(h.length>0){m.push(`function __${a}_is_subcmd`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of h)m.push(` case "${e.lookupPattern}"`),m.push(` return 0`);m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``)}for(let e of c)m.push(...Rt(e,a,[]));if(m.push(`function __${a}_complete_root --no-scope-shadowing`),m.push(...Pt(s.options,s.positionals,a)),m.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(m.push(` if test $_after_dd -eq 1`),m.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),m.push(` return`),m.push(` end`)):m.push(` if test $_after_dd -eq 1; return; end`),m.push(` if string match -q -- '-*' "$_cur"`),m.push(...Lt(s.options,a)),c.length>0){m.push(` else`);let e=P(s.subcommands);m.push(...It(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(m.push(` else`),m.push(...Z(s.positionals,a,s.options)));if(m.push(` end`),m.push(`end`),m.push(``),m.push(`function __fish_${a}_complete`),m.push(` set -l _args (commandline -opc)`),m.push(` set -e _args[1]`),m.push(``),m.push(` set -l _ct (commandline -ct)`),m.push(` if test (count $_ct) -eq 0`),m.push(` set -a _args ""`),m.push(` else`),m.push(` set -a _args $_ct`),m.push(` end`),m.push(``),m.push(` set -l _cur ""`),m.push(` if test (count $_args) -gt 0`),m.push(` set _cur "$_args[-1]"`),m.push(` end`),m.push(``),m.push(` set -l _prev ""`),m.push(` if test (count $_args) -gt 1`),m.push(` set _prev "$_args[-2]"`),m.push(` end`),m.push(``),m.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),m.push(` set -l _used_opts`),d&&m.push(` set -l _pos_words`),m.push(` set -l _any_opt_used 0`),m.push(``),d)for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`),m.push(` set -e _global_arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`);m.push(` set -l _j 1`),m.push(` set -l _limit (math (count $_args) - 1)`),m.push(` while test $_j -le $_limit`),m.push(` set -l _w "$_args[$_j]"`),m.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),m.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let g=d?`set -a _pos_words "$_w"; `:``;if(m.push(` if test $_after_dd -eq 1; ${g}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),m.push(` if string match -q -- '-*=*' "$_w"`),m.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),m.push(` set -a _used_opts "$_opt"`),m.push(` set _any_opt_used 1`),d&&(m.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),m.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),p&&m.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),m.push(` if string match -q -- '-*' "$_w"`),m.push(` set -a _used_opts "$_w"`),m.push(` set _any_opt_used 1`),m.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),m.push(` set -l _next ""`),m.push(` set -l _next_idx (math $_j + 1)`),m.push(` if test $_next_idx -le (count $_args)`),m.push(` set _next "$_args[$_next_idx]"`),m.push(` end`),m.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),m.push(` set _skip_next 1`),d&&(m.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),p&&(m.push(` if test $_j -lt $_limit`),m.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` end`))),m.push(` end`),m.push(` end`),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),h.length>0){if(m.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),m.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),m.push(` set _used_opts; set _pos_count 0`),d){m.push(` set _pos_words`);for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`)}m.push(` else`),d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`),m.push(` end`)}else d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`);m.push(` set _j (math $_j + 1)`),m.push(` end`),d&&m.push(` __${a}_track_positionals`),m.push(``),m.push(` switch "$_subcmd"`);for(let e of h)m.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return m.push(` case '*'; __${a}_complete_root`),m.push(` end`),m.push(`end`),m.push(``),o||(m.push(`# Clear existing completions`),m.push(`complete -e -c ${n}`),m.push(``),m.push(`# Register completion`),m.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),m.push(``),{script:m.join(`
|
|
45
45
|
`),shell:`fish`,installInstructions:`# To enable auto-refreshing fish completions, run:
|
|
46
46
|
${n} completion fish --install --static`}}function Vt(e,t){re(D(e),{recursive:!0});let n=`${e}.tmp.${process.pid}`;oe(n,t),ie(n,e)}function Ht(e,t){return un(e.rootCommand,{shell:t,programName:e.programName,mode:e.completionMode??`dispatcher`,includeDescriptions:!0,...e.programVersion!==void 0&&{programVersion:e.programVersion},...e.binPath!==void 0&&{binPath:e.binPath},...e.cacheDir!==void 0&&{cacheDir:e.cacheDir},...e.globalArgsSchema!==void 0&&{globalArgsSchema:e.globalArgsSchema},...e.bundledWorker!==void 0&&{bundledWorker:e.bundledWorker},...e.staticWorker!==void 0&&{staticWorker:e.staticWorker}}).script}function Ut(e,t){let n=a(e.programName,t,e.cacheDir);return Vt(n,Ht(e,t)),n}function Wt(e){try{if(!C(e))return;let t=w(e,`utf8`).split(`
|
|
47
47
|
`,10).join(`
|
package/dist/completion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-TbOCQNeI.js";import{s as e,t}from"./with-completion-command-DG-C9_0Z.js";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./dynamic-DbvYJg3o.js";import{a as l,c as u,d,i as f,l as p,n as m,o as h,r as g,s as _,t as v,u as y}from"./completion-nNzHfI1i.js";export{r as CompletionDirective,h as bundledWorkerShellExtension,v as createCompletionCommand,m as createCompletionWorkerPathCommand,c as createDynamicCompleteCommand,g as createRefreshCompletionCommand,_ as defaultBundledWorkerOutputPath,e as detectShell,y as extractCompletionData,d as extractPositionals,o as formatForShell,u as generateBundledCompletionWorker,n as generateCandidates,f as generateCompletion,l as getSupportedShells,i as hasCompleteCommand,a as parseCompletionContext,s as resolveValueCompletion,p as validateBundledWorkerFile,t as withCompletionCommand};
|
package/dist/docs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./field-meta-
|
|
1
|
+
import{o as e}from"./field-meta-D9ySul7J.js";import"./register-TbOCQNeI.js";import{c as t,n,o as r,r as i,s as a,t as o}from"./schema-extractor-fZZ2_WAZ.js";import{t as s}from"./log-collector-uhRWYT-z.js";import{r as c}from"./subcommand-router-DR2KBQAt.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
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
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(`
|
|
4
4
|
|
|
@@ -18,16 +18,16 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
|
|
|
18
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 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
|
|
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=/* @__PURE__ */ 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-BKyUtmoD.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: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
|
|
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=/* @__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=>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
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
26
|
`)}async function K(e,t){if(!t)return e;let n=await t(e);return!e.endsWith(`
|
|
27
27
|
`)&&n.endsWith(`
|
|
28
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
|
|
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
|
|
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=/* @__PURE__ */ 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:/* @__PURE__ */ new Set,commandSections:/* @__PURE__ */ 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=/* @__PURE__ */ 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=/* @__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]===`
|
|
33
33
|
`&&(n+=1);n<e.length;){let t=e.indexOf(`
|
|
@@ -48,7 +48,7 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.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 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
|
|
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=/* @__PURE__ */ 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
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]===`
|
|
@@ -65,9 +65,9 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
|
|
|
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 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
|
|
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=/* @__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 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=/* @__PURE__ */ 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 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
|
|
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=/* @__PURE__ */ 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=/* @__PURE__ */ 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=/* @__PURE__ */ 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
71
|
- `)}`)}function an(e){return[`<a id="global-options"></a>`,ze(e.args,e.options)].join(`
|
|
72
72
|
`)}function on(e){return[I(),an(e),te()].join(`
|
|
73
73
|
`)}async function sn(e,t,n,r){let i=B(n),a=oe(n);return[i,await Ke(t,e,r),a].join(`
|
|
@@ -78,15 +78,15 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
|
|
|
78
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=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
|
|
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=/* @__PURE__ */ 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
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
|
|
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
|
|
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=/* @__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 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=/* @__PURE__ */ 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=/* @__PURE__ */ new Map,ee=/* @__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&&ee.set(t,Nt(tt(e),d))}let E=Object.entries(e.templates??{}),D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Map;if(E.length>0){let e=h?$(h.path):null,t=new Set(Object.keys(f).map($)),n=/* @__PURE__ */ 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=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,f=!1,p=!1,m=ee.get(e)??rt(/* @__PURE__ */ 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=/* @__PURE__ */ 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=/* @__PURE__ */ 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
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 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
|
|
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=/* @__PURE__ */ new Map,O=ee.get(e)??rt(/* @__PURE__ */ 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
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
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(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./dynamic-DbvYJg3o.js";export{e as createDynamicCompleteCommand};
|