@politty/loculus 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cli-main-CdXCj3sh.js → cli-main-Bs2qeKG_.js} +2 -2
- package/dist/cli-main-UNHTFiMG.js +1 -0
- package/dist/cli-run-B4q0nbxz.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/completion-B-O5x0KK.js +1 -0
- package/dist/completion-BlhEgaLs.js +116 -0
- package/dist/completion.js +1 -1
- package/dist/docs.js +6 -6
- package/dist/dynamic-BPH__Tf7.js +1 -0
- package/dist/{dynamic-D2uon-av.js → dynamic-iwEE4Vdk.js} +4 -4
- package/dist/index.d.ts +33 -2
- package/dist/index.js +1 -1
- package/dist/runner-BJCgs-_W.js +33 -0
- package/dist/runner-CPph9QvL.js +1 -0
- package/dist/skill.js +2 -2
- package/dist/with-completion-command-BH--VXVo.js +3 -0
- package/package.json +3 -3
- package/dist/cli-main-CTVeQxs0.js +0 -1
- package/dist/cli-run-x5wuUkuB.js +0 -1
- package/dist/completion-ChgOYSFp.js +0 -116
- package/dist/completion-Df9_25sa.js +0 -1
- package/dist/dynamic-plXaUNoz.js +0 -1
- package/dist/runner-BbIyh52c.js +0 -33
- package/dist/runner-fgBRxl0e.js +0 -1
- package/dist/with-completion-command-DOtEG943.js +0 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as e,h as t}from"./schema-extractor-BI5ypJ21.js";import{n}from"./command-BXsTrIgI.js";import{n as r}from"./runner-
|
|
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-
|
|
1
|
+
import{g as e,h as t}from"./schema-extractor-BI5ypJ21.js";import{n}from"./command-BXsTrIgI.js";import{n as r}from"./runner-BJCgs-_W.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-B-O5x0KK.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
|
+
export{t as runPolittyCli}from"./cli-main-Bs2qeKG_.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./register-D-aEK58y.js";const{runPolittyCli:e}=await import(`./cli-main-UNHTFiMG.js`);await e(`@politty/loculus`);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-B4q0nbxz.js`);export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./with-completion-command-BH--VXVo.js";import"./dynamic-iwEE4Vdk.js";export{t as createCompletionCommand,n as createCompletionWorkerPathCommand,r as createRefreshCompletionCommand,c as generateBundledCompletionWorker}from"./completion-BlhEgaLs.js";
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import{n as e}from"./command-BXsTrIgI.js";import{_ as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,p as u,s as d,t as f,u as p,v as m,y as h}from"./dynamic-iwEE4Vdk.js";import{a as g,c as _,n as v}from"./schema-extractor-BI5ypJ21.js";import{c as y}from"./subcommand-router-40vA6Mka.js";import{a as b,i as ee,n as x,o as te,r as ne,s as re}from"./with-completion-command-BH--VXVo.js";import{existsSync as S,mkdirSync as ie,readFileSync as C,realpathSync as w,renameSync as ae,rmSync as oe,statSync as T,writeFileSync as se}from"node:fs";import{dirname as E,extname as ce,isAbsolute as le,join as ue,relative as de,resolve as fe}from"node:path";import{promisify as pe}from"node:util";import{execFile as me}from"node:child_process";function he(e,t,n=[],r=!1){if(t.length===0)return;let i=ge(e,n);for(let e of t)e.set(_e(e,i,r))}function ge(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 _e(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 ye(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=ve(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function ve(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*ye(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 be(e,t,n,r){let i=d(e);i?.type===`pending-expand`?t.push({name:e.name,describe:n,set:r,spec:i.spec}):i!==void 0&&r(i)}function D(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function O(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function k(e,t,n){return`__${e}_expand_${t}__${D(n)}`}function xe(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${O(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function A(e){return e.filter(e=>!e.name.startsWith(`__`))}function j(e){let t=[];for(let n of A(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 Se(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 be(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function Ce(e){return e.args?_(v(e.args)):[]}function we(e,t){return e.filter(e=>e.named).map(e=>Se(e,t))}function Te(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 be(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ee(e,t,n=[],r=!1){let i=[];if(t.subCommands)for(let[e,a]of Object.entries(t.subCommands)){let t=y(a);t?i.push(Ee(e,t,n,r)):i.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let a=[],o=t.args?v(t.args):void 0,s={name:e,description:t.description,aliases:t.aliases,subcommands:i,options:we(o?g(o):[],a),positionals:Te(o?_(o):[],a)};return he(s,a,n,r),s}function M(e,t,n){return e?`${e}${n}${t}`:t}function De(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>M(e,t,`:`)))}function Oe(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 A(e.subcommands))n(t,De(r,t))};return n(e,[``]),t}function N(e,t){let n=[],r=A(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?c(i.cliName,i.alias):F(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of A(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...N(r,M(t,e,`:`)));return n}function ke(e,t){return N(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function P(e,t=``,n=``){let r=[];for(let i of A(e.subcommands)){let e=M(n,D(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=M(t,n,`:`);r.push(...P(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function Ae(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function je(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function Me(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${D(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ne(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}) ${Me(r,t)} ;;`)}return n}function Pe(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}) ${Me(r,t)} ;;`)}return n}function Fe(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=D(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 F(e,t){let n=c(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 r(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let i=p(t);return i.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!i.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function Ie(e){let t=[];return Le(e,[],[``],[],`root`,t),t}function Le(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?F(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 A(e.subcommands))Le(o,[...t,o.name],De(n,o),[...r,...n],i===`root`?D(o.name):`${i}_${D(o.name)}`,a)}function Re(e,t,n=[]){let i=ze(e),a=/* @__PURE__ */ new Map,o=(e,t,n)=>{let r=a.get(e);r||(r={ref:t,pathStrs:[],seen:/* @__PURE__ */ new Set},a.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},s=(e,t,n)=>{let a=/* @__PURE__ */ new Map,o=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=a.get(n);r||(r={tokens:t,paths:[]},a.set(n,r)),r.paths.push(e)};for(let n of t){let t=i.get(n);if(!t)continue;let a=/* @__PURE__ */ new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of r(e.cliName,e.alias))a.add(t);o(n,e.filter(e=>!a.has(e)))}for(let t of n)o(t,e);return a},l=(e,t,n)=>{let r=c(t.cliName,t.alias),i=s(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)o(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=i.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;l(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&o(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let a=t.options.find(e=>e.name===r);a&&(a.isGlobal===!0?l(r,a,e):o(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:F(a,t.options)},e.pathStrs))}}let u=[];for(let e of a.values())e.pathStrs.length!==0&&u.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return u}function ze(e){let t=/* @__PURE__ */ new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of A(e.subcommands))n(t,De(r,t))};return n(e,[``]),t}function I(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(I(t))return!0;return!1}function Be(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)Be(n,t)}function L(e,t,n,r=!1){let i=[];if(n){let e=[];i=we(v(n).fields,e).map(e=>(e.isGlobal=!0,e)),he({name:t,subcommands:[],options:i,positionals:[]},e,[],r)}let a=Ee(t,e,i,r);return n?Be(a,i):i=a.options,{command:a,programName:t,globalOptions:i}}function R(e){try{return Math.floor(T(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ve(e){return e.replace(/\r?\n/g,` `)}function He(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=ue(n,e);try{if(T(t).isFile())return t}catch{}}return null}function z(e,t){return t||process.env[O(D(e))]||(He(e)??process.argv[1]??``)}function B(e){let t=z(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${R(t)}`,`# politty-bin-path: ${Ve(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Ue(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=z(t,n),o=R(a),s=m(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=${h(`$_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 We(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=`_${t}`,o=z(t,n),s=R(o),c=m(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=${h(`$_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 Ge(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ke(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 qe(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=k(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=D(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_${D(r.fieldName)}:-}`:`\${_used_field_keys_${D(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=>`"${Ge(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?Je(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Je(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 V(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Je(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 Ye(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=qe(o.valueCompletion,n,r,{funcSuffix:i,...u(o,e,t)});if(s.length===0)continue;let c=F(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function H(e,t,n,r=[]){if(e.length===0)return[];let i=o(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 qe(o.valueCompletion,!1,t,{funcSuffix:n,...l(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Xe(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`,...H(t,n,r,i),`fi`]}function Ze(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=Ye(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=Ye(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,n){let r=[];for(let i of e){if(i.valueType===`array`){r.push(` _avail+=(--${i.cliName})`);continue}let a=t(i.cliName,i.alias,i.negation,{isGlobal:i.isGlobal===!0,frameOptions:e}),o=`__${n}_not_used ${a.join(` `)}`,s=i.negation?[i.cliName,i.negation]:[i.cliName];for(let e of s)a.includes(`"--${e}"`)&&r.push(` ${o} && _avail+=(--${e})`)}return r.push(` if (( ! _any_opt_used )); then`),r.push(` _avail+=(--help --help-all --help-json)`),r.push(` fi`),r}function $e(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...$e(e,t,r));s.push(`${a}() {`),s.push(...Ze(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(...H(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=j(e.subcommands).map(e=>e.name).join(` `);s.push(...Xe(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...H(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function et(e,t){let{programName:r}=t,i=L(e,r,t.globalArgsSchema),o=D(r),c=t.staticWorker?`${o}_${D(t.staticWorker.functionSuffix)}`:o,l=t.staticWorker!==void 0,u=i.command,d=A(u.subcommands),f=Ie(u),p=Re(u,f,i.globalOptions),m=[];m.push(...B({programName:r,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${l?`worker`:`static`}`),l&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),l||m.push(...Ue({programName:r,binPath:t.binPath}));let h=f.length>0,g=f.filter(e=>e.isArrayOption),_=g.length>0;h&&(m.push(`__${c}_enc() {`),m.push(` local LC_ALL=C`),m.push(` local _s=$1 _r='' _c _i`),m.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),m.push(" _c=${_s:_i:1}"),m.push(` case "$_c" in`),m.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),m.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),m.push(` esac`),m.push(` done`),m.push(` printf '%s' "$_r"`),m.push(`}`),m.push(``));for(let e of f){let t=k(c,e.funcSuffix,e.fieldName);for(let r of e.vc.table){let e=r.key.map(Ke).join(`_`),i=r.candidates.map(e=>e.value).join(`
|
|
2
|
+
`);m.push(`${t}__${e}=${n(i)}`)}m.push(``)}I(u)&&(m.push(...xe(c,r)),m.push(``),m.push(`__${c}_apply_dynamic_output() {`),m.push(` local _raw="$1"`),m.push(` COMPREPLY=()`),m.push(` local _directive=0`),m.push(` local -a _lines=()`),m.push(` local _line`),m.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),m.push(" local _last=$((${#_lines[@]} - 1))"),m.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),m.push(' _directive="${_lines[$_last]#:}"'),m.push(` unset '_lines[_last]'`),m.push(` fi`),m.push(' for _line in "${_lines[@]}"; do'),m.push(` [[ -z "$_line" ]] && continue`),m.push(` COMPREPLY+=("$_line")`),m.push(` done`),m.push(' local _ip="${_inline_prefix:-}"'),m.push(` if (( _directive & ${s.DirectoryCompletion} )); then`),m.push(` compopt +o default 2>/dev/null`),m.push(` compopt -o filenames 2>/dev/null`),m.push(` local _d`),m.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),m.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),m.push(` elif (( _directive & ${s.FileCompletion} )); then`),m.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),m.push(` compopt -o filenames 2>/dev/null`),m.push(` local _f`),m.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),m.push(` else`),m.push(` compopt -o default 2>/dev/null`),m.push(` fi`),m.push(` else`),m.push(` if (( _directive & ${s.NoFileCompletion} )); then`),m.push(` compopt +o default 2>/dev/null`),m.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),m.push(` fi`),m.push(` fi`),m.push(` if (( _directive & ${s.NoSpace} )); then`),m.push(` compopt -o nospace 2>/dev/null`),m.push(` fi`),m.push(`}`),m.push(``)),m.push(`__${c}_not_used() {`),m.push(' for _u in "${_used_opts[@]}"; do'),m.push(` for _chk in "$@"; do`),m.push(` [[ "$_u" == "$_chk" ]] && return 1`),m.push(` done`),m.push(` done`),m.push(` return 0`),m.push(`}`),m.push(``),m.push(`__${c}_opt_takes_value() {`),m.push(` case "$1:$2" in`),m.push(...ke(u,``)),m.push(` esac`),m.push(` return 1`),m.push(`}`),m.push(``),h&&(m.push(`__${c}_track_opt() {`),m.push(` case "$1:$2" in`),m.push(...Ne(p,`bash`)),m.push(` esac`),m.push(`}`),m.push(``),m.push(`__${c}_track_pos() {`),m.push(` case "$1:$2" in`),m.push(...Pe(p,`bash`)),m.push(` esac`),m.push(`}`),m.push(``),m.push(...a(c,Oe(u)))),_&&(m.push(`__${c}_track_array_expand() {`),m.push(` case "$1:$2" in`),m.push(...Fe(g,`bash`)),m.push(` esac`),m.push(`}`),m.push(``));let v=P(u);v.length>0&&(m.push(`__${c}_is_subcmd() {`),m.push(` case "$1:$2" in`),m.push(...Ae(v)),m.push(` esac`),m.push(` return 1`),m.push(`}`),m.push(``));for(let e of d)m.push(...$e(e,c,[]));if(m.push(`__${c}_complete_root() {`),m.push(...Ze(u.options,u.positionals,c,`root`)),m.push(` if [[ -z "$_inline_prefix" ]] && __${c}_opt_takes_value "" "$_prev"; then return; fi`),m.push(` if [[ -n "$_inline_prefix" ]] && __${c}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),u.positionals.length>0?(m.push(` if (( _after_dd )); then`),m.push(...H(u.positionals,c,`root`,u.options).map(e=>` ${e}`)),m.push(` return`),m.push(` fi`)):m.push(` if (( _after_dd )); then return; fi`),m.push(` if [[ "$_cur" == -* ]]; then`),m.push(` local -a _avail=()`),m.push(...Qe(u.options,c)),m.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),m.push(` compopt +o default 2>/dev/null`),d.length>0){m.push(` else`);let e=j(u.subcommands).map(e=>e.name).join(` `);m.push(...Xe(e,u.positionals,c,`root`,u.options).map(e=>` ${e}`))}else u.positionals.length>0&&(m.push(` else`),m.push(...H(u.positionals,c,`root`,u.options).map(e=>` ${e}`)));m.push(` fi`),m.push(`}`),m.push(``);let y=je(v,c).join(`
|
|
3
|
+
`);m.push(`_${c}_completions() {`),m.push(` COMPREPLY=()`),m.push(``),m.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),m.push(` local -a _words=()`),m.push(` local _i=1`),m.push(` while (( _i <= COMP_CWORD )); do`),m.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),m.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),m.push(` (( _i += 2 ))`),m.push(` else`),m.push(' _words+=("${COMP_WORDS[_i]}")'),m.push(` (( _i++ ))`),m.push(` fi`),m.push(` done`),m.push(``),m.push(` local _cur=""`),m.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),m.push(` local _inline_prefix=""`),m.push(``),m.push(` local _prev=""`),m.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),m.push(``),m.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),m.push(` local -a _used_opts=()`),h&&m.push(` local -a _pos_words=()`),m.push(` local _any_opt_used=0`),h&&(m.push(` ${V(`_arg_values_`)}`),m.push(` ${V(`_global_arg_values_`)}`)),_&&(m.push(` ${V(`_used_field_keys_`)}`),m.push(` ${V(`_global_used_field_keys_`)}`),m.push(` ${V(`_global_arr_seen_`)}`)),m.push(``),m.push(` local _j=0`),m.push(" while (( _j < ${#_words[@]} - 1 )); do"),m.push(' local _w="${_words[_j]}"'),m.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),m.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=h?`_pos_words+=("$_w"); `:``;m.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),m.push(` if [[ "$_w" == -*=* ]]; then`),m.push(' _used_opts+=("${_w%%=*}")'),m.push(` _any_opt_used=1`),h&&(m.push(` __${c}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),_&&m.push(` __${c}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),m.push(` (( _j++ )); continue`),m.push(` fi`),m.push(` if [[ "$_w" == -* ]]; then`),m.push(` _used_opts+=("$_w")`),m.push(` _any_opt_used=1`),m.push(` if __${c}_opt_takes_value "$_subcmd" "$_w"; then`),m.push(' local _next="${_words[_j+1]:-}"'),m.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),h&&(m.push(` if (( _skip_next )); then`),m.push(` __${c}_track_opt "$_subcmd" "$_w" "$_next"`),_&&(m.push(" if (( _j + 2 < ${#_words[@]} )); then"),m.push(` __${c}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` fi`)),m.push(` fi`)),m.push(` fi`),m.push(` (( _j++ )); continue`),m.push(` fi`);let ee=_?`; ${V(`_arg_values_`)}; ${V(`_used_field_keys_`)}; ${V(`_global_arr_seen_`)}`:h?`; ${V(`_arg_values_`)}`:``,x=h?`_pos_words+=("$_w"); `:``;return v.length>0?m.push(` if __${c}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${h?`; _pos_words=()`:``}${ee}; else ${x}(( _pos_count++ )); fi`):(h&&m.push(` _pos_words+=("$_w")`),m.push(` (( _pos_count++ ))`)),m.push(` (( _j++ ))`),m.push(` done`),h&&m.push(` __${c}_track_positionals`),m.push(``),m.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),m.push(' _inline_prefix="${_cur%%=*}="'),m.push(' _cur="${_cur#*=}"'),m.push(` fi`),m.push(``),m.push(` case "$_subcmd" in`),m.push(y),m.push(` *) __${c}_complete_root ;;`),m.push(` esac`),m.push(`}`),m.push(``),l||m.push(`complete -o default -F _${c}_completions ${r}`),m.push(``),{script:m.join(`
|
|
4
|
+
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
5
|
+
eval "$(${r} completion bash --static)"
|
|
6
|
+
|
|
7
|
+
# For faster shell startup, save the script instead:
|
|
8
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
9
|
+
${r} completion bash --static > ~/.local/share/bash-completion/completions/${r}
|
|
10
|
+
|
|
11
|
+
# Then reload your shell or run:
|
|
12
|
+
source ~/.bashrc`}}const tt=pe(me),U={bash:`bash`,zsh:`zsh`,fish:`fish`},nt=[`# politty-completion-version: 1`,`# politty-completion-mode: worker`,`# politty-completion-worker: true`];function rt(e){return U[e]}function it(e){return ue(`dist`,`completion`,`${e}-worker.${rt(e)}`)}function at(e){let t=U[e];return[`completion/${e}-worker.${t}`,`../completion/${e}-worker.${t}`,`dist/completion/${e}-worker.${t}`,`../dist/completion/${e}-worker.${t}`,`completion-worker.${e}`,`../completion-worker.${e}`]}function W(e,t,n){if(n?.disabled)return[];let r=n?.relativePaths?.[t];return(r&&r.length>0?r:at(t)).map(n=>n.replaceAll(`{shell}`,t).replaceAll(`{ext}`,U[t]).replaceAll(`{program}`,e))}function ot(e){try{let t=C(e,`utf8`),n=null;for(let e of t.split(`
|
|
13
|
+
`)){let t=e.match(/^# cmd-shim-target=(.+)$/);t&&(n=t[1])}return n}catch{return null}}function G(e,t){if(!t)return;e.add(E(fe(t)));try{e.add(E(w(t)))}catch{}let n=ot(t);n&&G(e,n)}function st(e){return C(e,`utf8`).split(`
|
|
14
|
+
`,24).join(`
|
|
15
|
+
`)}function ct(e,t){return[...nt,`# program: ${e}`,`# shell: ${t}`]}function lt(e,t,n){let r=e.split(`
|
|
16
|
+
`).map(e=>e.trimEnd());return ct(t,n).filter(e=>!r.includes(e))}function K(e,t,n){if(!S(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=lt(st(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function ut(e,t,n){try{return K(e,t,n),!0}catch{return!1}}function dt(e){let t=W(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n=/* @__PURE__ */ new Set;e.binPath!==void 0&&G(n,e.binPath),process.argv[1]&&G(n,process.argv[1]),G(n,z(e.programName,e.binPath));for(let n of t)if(le(n)&&ut(n,e.programName,e.shell))return n;for(let r of n)for(let n of t){if(le(n))continue;let t=ue(r,n);if(ut(t,e.programName,e.shell))return t}return null}function q(e,t){return le(e)?e:fe(t,e)}function ft(e,t,n){let r=e.startsWith(`.`)||e.includes(`/`)||e.includes(`\\`)?q(e,n):e,i=ce(r).toLowerCase();return i===`.js`||i===`.mjs`||i===`.cjs`?{command:process.execPath,args:[r,...t]}:{command:r,args:[...t]}}async function pt(e,t,n){let r=ft(e,t,n.cwd);try{let{stdout:e,stderr:t}=await tt(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 mt(e){let t=T(e);if(!t.isFile()||t.size===0)throw Error(`Generated bundled completion worker is empty: ${e}`);return t.size}function ht(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KiB`}function gt(e,t,n){let r=de(n,e);console.log(`Generated bundled completion worker: ${r&&!r.startsWith(`..`)?r:e} (${ht(t)})`)}async function _t(e){let t=e.cwd??process.cwd(),n=q(e.outputPath??it(e.shell),t);ie(E(n),{recursive:!0}),oe(n,{force:!0}),await pt(e.bin,[`__refresh-completion`,e.shell,n,`--static`,`--worker`],{cwd:t,env:e.env});let r=mt(n);K(n,e.programName,e.shell);let i;if(e.verify){let r=(await pt(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=q(r[0],t);let a=w(n),o=w(i);if(o!==a)throw Error(`Bundled completion worker path mismatch: generated ${a}, reported ${o}`)}return e.quiet||gt(n,r,t),{outputPath:n,size:r,...i!==void 0&&{reportedPath:i}}}function vt(e){return m(`/${e}/node-compile-cache`)}function yt(e){return e?m(`${e}/node-compile-cache`):void 0}function J(e,t){return e?m(`${e}/completion-worker.${t}`):void 0}function bt(e,t){return m(`/${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
|
+
`)}function St(e,t){return W(e.programName,t,e.bundledWorker).map(m).join(` `)}function Ct(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}"`}function wt(e){return W(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=D(n),i=`${r}_worker`,a=O(i),o=O(r),c=m(n),l=Y(`printf '%s\\n'`,yt(t.cacheDir),vt(n)),u=Y(`printf '%s\\n'`,J(t.cacheDir,`bash`),bt(n,`bash`)),d=St(t,`bash`),f=Tt(t),p=[];return p.push(...B({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),p.push(`# Generated by politty`),p.push(`# politty-completion-mode: dispatcher`),p.push(``),p.push(`__${r}_resolve_bin() {`),p.push(` if [[ -n "\${${o}:-}" ]]; then`),p.push(` printf '%s\\n' "\${${o}}"`),p.push(` return 0`),p.push(` fi`),p.push(` type -P ${c} 2>/dev/null`),p.push(`}`),p.push(``),p.push(`__${r}_node_compile_cache_dir() {`),p.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),p.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),p.push(` return 0`),p.push(` fi`),p.push(l),p.push(`}`),p.push(``),p.push(`__${r}_static_worker_path() {`),p.push(u),p.push(`}`),p.push(``),p.push(`__${r}_worker_file_sig() {`),p.push(` local _worker="$1" _sig`),p.push(` _sig=${h(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),p.push(` printf '%s\\n' "$_sig"`),p.push(`}`),p.push(``),p.push(`__${r}_is_worker_file() {`),p.push(` local _worker="$1" _head`),p.push(` [[ -f "$_worker" ]] || return 1`),p.push(` _head="$(head -n 24 "$_worker" 2>/dev/null)" || return 1`),p.push(` _head=$'\\n'"$_head"$'\\n'`),p.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),p.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),p.push(` [[ "$_head" == *$'\\n'"# shell: bash"$'\\n'* ]] || return 1`),p.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),p.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),p.push(`}`),p.push(``),p.push(`__${r}_load_worker() {`),p.push(` local _worker="$1" _sig _key`),p.push(` __${r}_is_worker_file "$_worker" || return 1`),p.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),p.push(` _key="$_worker:$_sig"`),p.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),p.push(` source "$_worker" 2>/dev/null || return 1`),p.push(` __${r}_loaded_worker_key="$_key"`),p.push(` fi`),p.push(` declare -F _${i}_completions >/dev/null 2>&1`),p.push(`}`),p.push(``),p.push(`__${r}_realpath() {`),p.push(` local _path="$1" _dir _target _limit=0`),p.push(` while [[ -L "$_path" && $_limit -lt 40 ]]; do`),p.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),p.push(` _target="$(readlink "$_path")" || return 1`),p.push(` if [[ "$_target" == /* ]]; then _path="$_target"; else _path="$_dir/$_target"; fi`),p.push(` (( _limit++ ))`),p.push(` done`),p.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),p.push(` printf '%s\\n' "$_dir/$(basename "$_path")"`),p.push(`}`),p.push(``),p.push(`__${r}_worker_from_dir() {`),p.push(` local _dir="$1" _rel _candidate`),d.length>0&&(p.push(` for _rel in ${d}; do`),p.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),p.push(` if __${r}_is_worker_file "$_candidate"; then`),p.push(` printf '%s\\n' "$_candidate"`),p.push(` return 0`),p.push(` fi`),p.push(` done`)),p.push(` return 1`),p.push(`}`),p.push(``),p.push(`__${r}_cmd_shim_target() {`),p.push(` sed -n 's/^# cmd-shim-target=//p' "$1" 2>/dev/null | tail -n 1`),p.push(`}`),p.push(``),p.push(`__${r}_bundled_worker_path() {`),p.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),p.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),p.push(` if [[ -n "$_real" ]]; then`),p.push(` _dir="$(dirname "$_real")"`),p.push(` __${r}_worker_from_dir "$_dir" && return 0`),p.push(` fi`),p.push(` _dir="$(dirname "$_bin")"`),p.push(` __${r}_worker_from_dir "$_dir" && return 0`),p.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),p.push(` if [[ -n "$_target" ]]; then`),p.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),p.push(` _dir="$(dirname "$_real")"`),p.push(` __${r}_worker_from_dir "$_dir" && return 0`),p.push(` fi`),f&&(p.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),p.push(` printf '%s\\n' "\${__${r}_queried_worker}"`),p.push(` return 0`),p.push(` fi`),p.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path bash 2>/dev/null)" || _reported=""`),p.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),p.push(` __${r}_queried_bin="$_bin"`),p.push(` __${r}_queried_worker="$_reported"`),p.push(` printf '%s\\n' "$_reported"`),p.push(` return 0`),p.push(` fi`)),p.push(` return 1`),p.push(`}`),p.push(``),p.push(`__${r}_bin_sig() {`),p.push(` local _bin="$1" _sig`),p.push(` _sig=${h(`$_bin`,{shell:`posix`})} || return 1`),p.push(` printf '%s\\n' "$_sig"`),p.push(`}`),p.push(``),p.push(`__${r}_worker_matches_bin() {`),p.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),p.push(` [[ -f "$_worker" ]] || return 1`),p.push(` _head="$(head -n 12 "$_worker" 2>/dev/null)" || return 1`),p.push(` grep -qxF "# politty-bin-sig: $_sig" <<< "$_head" || return 1`),p.push(` grep -qxF "# politty-bin-path: $_bin" <<< "$_head" || return 1`),p.push(`}`),p.push(``),p.push(`__${r}_apply_dynamic_output() {`),p.push(` local _raw="$1" _cur="$2" _inline_prefix="$3"`),p.push(` COMPREPLY=()`),p.push(` local _directive=0`),p.push(` local -a _lines=() _exts=() _matchers=()`),p.push(` local _line`),p.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),p.push(" local _last=$((${#_lines[@]} - 1))"),p.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" == :[0-9]* ]]; then'),p.push(` local -a _meta=()`),p.push(` IFS=$'\\t' read -r -a _meta <<< "\${_lines[$_last]}"`),p.push(` unset '_lines[_last]'`),p.push(' _directive="${_meta[0]#:}"'),p.push(` local _m`),p.push(' for _m in "${_meta[@]:1}"; do'),p.push(` if [[ "$_m" == @ext:* ]]; then`),p.push(` IFS=',' read -r -a _exts <<< "\${_m#@ext:}"`),p.push(` elif [[ "$_m" == @matcher:* ]]; then`),p.push(` IFS=',' read -r -a _matchers <<< "\${_m#@matcher:}"`),p.push(` fi`),p.push(` done`),p.push(` fi`),p.push(' for _line in "${_lines[@]}"; do'),p.push(` [[ -z "$_line" ]] && continue`),p.push(` COMPREPLY+=("$_line")`),p.push(` done`),p.push(' local _ip="${_inline_prefix:-}"'),p.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),p.push(` local _need_empty=0`),p.push(` compopt +o default 2>/dev/null || _need_empty=1`),p.push(` compopt -o filenames 2>/dev/null`),p.push(` local _f _ext _pat _base _ok`),p.push(` while IFS= read -r _f; do`),p.push(` if [[ -d "$_f" ]]; then`),p.push(' COMPREPLY+=("${_ip}${_f}")'),p.push(` continue`),p.push(` fi`),p.push(` _ok=0`),p.push(" if (( ${#_exts[@]} > 0 )); then"),p.push(' for _ext in "${_exts[@]}"; do'),p.push(` [[ -n "$_ext" && "$_f" == *."$_ext" ]] && _ok=1`),p.push(` done`),p.push(` fi`),p.push(" if (( ${#_matchers[@]} > 0 )); then"),p.push(' _base="${_f##*/}"'),p.push(' for _pat in "${_matchers[@]}"; do'),p.push(` [[ -n "$_pat" && "$_base" == $_pat ]] && _ok=1`),p.push(` done`),p.push(` fi`),p.push(' (( _ok )) && COMPREPLY+=("${_ip}${_f}")'),p.push(` done < <(compgen -f -- "$_cur")`),p.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),p.push(` elif (( _directive & ${s.DirectoryCompletion} )); then`),p.push(` local _need_empty=0`),p.push(` compopt +o default 2>/dev/null || _need_empty=1`),p.push(` compopt -o filenames 2>/dev/null`),p.push(` local _d`),p.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),p.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),p.push(` elif (( _directive & ${s.FileCompletion} )); then`),p.push(` compopt -o filenames 2>/dev/null`),p.push(` local _p`),p.push(' while IFS= read -r _p; do COMPREPLY+=("${_ip}${_p}"); done < <(compgen -f -- "$_cur")'),p.push(` elif (( _directive & ${s.NoFileCompletion} )); then`),p.push(` local _need_empty=0`),p.push(` compopt +o default 2>/dev/null || _need_empty=1`),p.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),p.push(` fi`),p.push(` if (( _directive & ${s.NoSpace} )); then`),p.push(` compopt -o nospace 2>/dev/null`),p.push(` fi`),p.push(`}`),p.push(``),p.push(`_${r}_completions() {`),p.push(` COMPREPLY=()`),p.push(` local -a _words=()`),p.push(` local _i=1`),p.push(` while (( _i <= COMP_CWORD )); do`),p.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),p.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),p.push(` (( _i += 2 ))`),p.push(` else`),p.push(' _words+=("${COMP_WORDS[_i]}")'),p.push(` (( _i++ ))`),p.push(` fi`),p.push(` done`),p.push(` local _cur="" _inline_prefix=""`),p.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),p.push(` local _after_dd=0 _di=0`),p.push(" while (( _di < ${#_words[@]} - 1 )); do"),p.push(' [[ "${_words[_di]}" == "--" ]] && { _after_dd=1; break; }'),p.push(` (( _di++ ))`),p.push(` done`),p.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),p.push(' _inline_prefix="${_cur%%=*}="'),p.push(' _cur="${_cur#*=}"'),p.push(` fi`),p.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),p.push(` _bin="$(__${r}_resolve_bin)" || _bin=""`),p.push(` [[ -n "$_bin" ]] || return 0`),p.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)" || _node_compile_cache=""`),p.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")" || _bundled_worker=""`),p.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),p.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),p.push(` return 0`),p.push(` fi`),p.push(` _worker="$(__${r}_static_worker_path)" || _worker=""`),p.push(` _sig="$(__${r}_bin_sig "$_bin")" || _sig=""`),p.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),p.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),p.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),p.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion bash "$_worker" --static --worker 2>/dev/null`),p.push(` fi`),p.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),p.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),p.push(` return 0`),p.push(` fi`),p.push(` fi`),p.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell bash -- "${_words[@]}" 2>/dev/null) || return 0'),p.push(` __${r}_apply_dynamic_output "$_out" "$_cur" "$_inline_prefix"`),p.push(`}`),p.push(``),p.push(`complete -o default -F _${r}_completions ${n}`),p.push(``),{script:p.join(`
|
|
18
|
+
`),shell:`bash`,installInstructions:`# To enable dispatcher bash completions, add this to your ~/.bashrc:
|
|
19
|
+
eval "$(${n} completion bash)"
|
|
20
|
+
|
|
21
|
+
# To save the dispatcher script instead:
|
|
22
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
23
|
+
${n} completion bash > ~/.local/share/bash-completion/completions/${n}
|
|
24
|
+
|
|
25
|
+
# To generate the older static script:
|
|
26
|
+
${n} completion bash --static`}}function Dt(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),c=m(n),l=`_${n}`,u=`"\${funcstack[1]:-}" == "${l}"`,d=Y(`print -r --`,yt(t.cacheDir),vt(n)),f=Y(`print -r --`,J(t.cacheDir,`zsh`),bt(n,`zsh`)),p=St(t,`zsh`),g=Tt(t),_=[];return _.push(`#compdef ${n}`),_.push(...B({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),_.push(`# Generated by politty`),_.push(`# politty-completion-mode: dispatcher`),_.push(``),_.push(`__${r}_resolve_bin() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` if [[ -n "\${${o}:-}" ]]; then`),_.push(` print -r -- "\${${o}}"`),_.push(` return 0`),_.push(` fi`),_.push(` whence -p ${c} 2>/dev/null`),_.push(`}`),_.push(``),_.push(`__${r}_node_compile_cache_dir() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),_.push(` print -r -- "$NODE_COMPILE_CACHE"`),_.push(` return 0`),_.push(` fi`),_.push(d),_.push(`}`),_.push(``),_.push(`__${r}_static_worker_path() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(f),_.push(`}`),_.push(``),_.push(`__${r}_worker_file_sig() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig`),_.push(` _sig=${h(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),_.push(` print -r -- "$_sig"`),_.push(`}`),_.push(``),_.push(`__${r}_is_worker_file() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _head`),_.push(` [[ -f "$_worker" ]] || return 1`),_.push(` _head="$(<$_worker)" || return 1`),_.push(` _head=$'\\n'"$_head"$'\\n'`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# shell: zsh"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),_.push(`}`),_.push(``),_.push(`__${r}_load_worker() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig _key`),_.push(` __${r}_is_worker_file "$_worker" || return 1`),_.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),_.push(` _key="$_worker:$_sig"`),_.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),_.push(` source "$_worker" 2>/dev/null || return 1`),_.push(` typeset -g __${r}_loaded_worker_key="$_key"`),_.push(` fi`),_.push(` (( $+functions[_${i}_completions] ))`),_.push(`}`),_.push(``),_.push(`__${r}_realpath() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _path="$1"`),_.push(` [[ -n "$_path" ]] || return 1`),_.push(' print -r -- "${_path:A}"'),_.push(`}`),_.push(``),_.push(`__${r}_worker_from_dir() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _dir="$1" _rel _candidate`),p.length>0&&(_.push(` for _rel in ${p}; do`),_.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),_.push(` if __${r}_is_worker_file "$_candidate"; then`),_.push(` print -r -- "$_candidate"`),_.push(` return 0`),_.push(` fi`),_.push(` done`)),_.push(` return 1`),_.push(`}`),_.push(``),_.push(`__${r}_cmd_shim_target() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` [[ -f "$1" ]] || return 0`),_.push(` local _l _t=""`),_.push(' for _l in "${(@f)$(<$1)}"; do'),_.push(' [[ "$_l" == "# cmd-shim-target="* ]] && _t="${_l#\\# cmd-shim-target=}"'),_.push(` done`),_.push(` [[ -n "$_t" ]] && print -r -- "$_t"`),_.push(`}`),_.push(``),_.push(`__${r}_bundled_worker_path() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),_.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),_.push(` if [[ -n "$_real" ]]; then`),_.push(' _dir="${_real:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` fi`),_.push(' _dir="${_bin:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),_.push(` if [[ -n "$_target" ]]; then`),_.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),_.push(' _dir="${_real:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` fi`),g&&(_.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),_.push(` print -r -- "\${__${r}_queried_worker}"`),_.push(` return 0`),_.push(` fi`),_.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path zsh 2>/dev/null)" || _reported=""`),_.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),_.push(` typeset -g __${r}_queried_bin="$_bin"`),_.push(` typeset -g __${r}_queried_worker="$_reported"`),_.push(` print -r -- "$_reported"`),_.push(` return 0`),_.push(` fi`)),_.push(` return 1`),_.push(`}`),_.push(``),_.push(`__${r}_bin_sig() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _bin="$1" _sig`),_.push(` _sig=${h(`$_bin`,{shell:`posix`})} || return 1`),_.push(` print -r -- "$_sig"`),_.push(`}`),_.push(``),_.push(`__${r}_worker_matches_bin() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),_.push(` [[ -f "$_worker" ]] || return 1`),_.push(` _head=$'\\n'"$(<$_worker)"$'\\n'`),_.push(` [[ "$_head" == *$'\\n'"# politty-bin-sig: $_sig"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-bin-path: $_bin"$'\\n'* ]] || return 1`),_.push(`}`),_.push(``),_.push(`__${r}_cdescribe() {`),_.push(` _describe "$@" 2>/dev/null && return 0`),_.push(` shift`),_.push(` local _cd_arr="$1"`),_.push(` shift`),_.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),_.push(` compadd "$@" -a _cd_vals 2>/dev/null`),_.push(` return 0`),_.push(`}`),_.push(``),_.push(`__${r}_add_path_candidate() {`),_.push(` compadd -f -- "$1" 2>/dev/null && return 0`),_.push(` print -r -- "$1"`),_.push(`}`),_.push(``),_.push(`__${r}_apply_dynamic_output() {`),_.push(` local _raw="$1"`),_.push(` local _directive=0`),_.push(` local -a _vals _lines _exts _matchers`),_.push(` local _meta`),_.push(' _lines=("${(@f)_raw}")'),_.push(` local _last=$#_lines`),_.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<->* ]]; then'),_.push(' local _dline="${_lines[$_last]}"'),_.push(` _lines[$_last]=()`),_.push(` local -a _dfields`),_.push(' _dfields=("${(@ps:\\t:)_dline}")'),_.push(' _directive="${_dfields[1]#:}"'),_.push(` local _m`),_.push(' for _m in "${(@)_dfields[2,-1]}"; do'),_.push(` if [[ "$_m" == @ext:* ]]; then`),_.push(' _meta="${_m#@ext:}"'),_.push(' _exts=("${(@s:,:)_meta}")'),_.push(` elif [[ "$_m" == @matcher:* ]]; then`),_.push(' _meta="${_m#@matcher:}"'),_.push(' _matchers=("${(@s:,:)_meta}")'),_.push(` fi`),_.push(` done`),_.push(` fi`),_.push(` local _l`),_.push(' for _l in "${_lines[@]}"; do'),_.push(` [[ -z "$_l" ]] && continue`),_.push(` _vals+=("$_l")`),_.push(` done`),_.push(" if (( ${#_vals[@]} > 0 )); then"),_.push(` if (( _directive & ${s.NoSpace} )); then`),_.push(` __${r}_cdescribe 'completions' _vals -S ''`),_.push(` else`),_.push(` __${r}_cdescribe 'completions' _vals`),_.push(` fi`),_.push(` fi`),_.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),_.push(` setopt local_options null_glob`),_.push(' local _cur="${words[CURRENT]:-}" _dir _prefix _f _out _ext _pat'),_.push(` if [[ -z "$_cur" || "$_cur" != */* ]]; then`),_.push(` _dir="."`),_.push(` _prefix="$_cur"`),_.push(` elif [[ "$_cur" == */ ]]; then`),_.push(' _dir="${_cur%/}"'),_.push(` _prefix=""`),_.push(` else`),_.push(' _dir="${_cur%/*}"'),_.push(' _prefix="${_cur##*/}"'),_.push(` fi`),_.push(` for _f in "$_dir"/"$_prefix"*(N/); do`),_.push(' _out="${_f#./}"'),_.push(` __${r}_add_path_candidate "$_out"`),_.push(` done`),_.push(` for _f in "$_dir"/"$_prefix"*(N.); do`),_.push(' _out="${_f#./}"'),_.push(' for _ext in "${_exts[@]}"; do'),_.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${r}_add_path_candidate "$_out"; break; }`),_.push(` done`),_.push(` done`),_.push(' for _pat in "${_matchers[@]}"; do'),_.push(` [[ -n "$_pat" ]] || continue`),_.push(' for _f in "$_dir"/${~_pat}(N.); do'),_.push(' _out="${_f#./}"'),_.push(` [[ "$_out" == "$_cur"* ]] && __${r}_add_path_candidate "$_out"`),_.push(` done`),_.push(` done`),_.push(` elif (( _directive & ${s.DirectoryCompletion} )); then`),_.push(` _files -/`),_.push(` elif (( _directive & ${s.FileCompletion} )); then`),_.push(` _files`),_.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${s.NoFileCompletion} )); then`),_.push(` _files`),_.push(` fi`),_.push(`}`),_.push(``),_.push(`${l}() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),_.push(` _bin="$(__${r}_resolve_bin)"`),_.push(` [[ -n "$_bin" ]] || return 1`),_.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)"`),_.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")"`),_.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),_.push(` return 0`),_.push(` fi`),_.push(` _worker="$(__${r}_static_worker_path)"`),_.push(` _sig="$(__${r}_bin_sig "$_bin")"`),_.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),_.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),_.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion zsh "$_worker" --static --worker 2>/dev/null`),_.push(` fi`),_.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),_.push(` return 0`),_.push(` fi`),_.push(` fi`),_.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell zsh -- "${(@)words[2,CURRENT]}" 2>/dev/null) || return 1'),_.push(` __${r}_apply_dynamic_output "$_out"`),_.push(`}`),_.push(``),_.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),_.push(``),_.push(`if [[ ${u} ]]; then`),_.push(` ${l} "$@"`),_.push(`else`),_.push(` compdef ${l} ${n}`),_.push(`fi`),_.push(``),{script:_.join(`
|
|
27
|
+
`),shell:`zsh`,installInstructions:`# To enable dispatcher zsh completions, add this to your ~/.zshrc after compinit:
|
|
28
|
+
eval "$(${n} completion zsh)"
|
|
29
|
+
|
|
30
|
+
# To save the dispatcher script in your fpath:
|
|
31
|
+
mkdir -p ~/.zsh/completions
|
|
32
|
+
${n} completion zsh > ~/.zsh/completions/_${n}
|
|
33
|
+
|
|
34
|
+
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
35
|
+
fpath=(~/.zsh/completions $fpath)
|
|
36
|
+
autoload -Uz compinit && compinit
|
|
37
|
+
|
|
38
|
+
# To generate the older static script:
|
|
39
|
+
${n} completion zsh --static`}}function Ot(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),c=m(n),l=xt(yt(t.cacheDir),vt(n)),u=xt(J(t.cacheDir,`fish`),bt(n,`fish`)),d=wt(t),f=Tt(t),p=[];return p.push(...B({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),p.push(`# Generated by politty`),p.push(`# politty-completion-mode: dispatcher`),p.push(``),p.push(`function __${r}_resolve_bin`),p.push(` if set -q ${o}; and test -n "$${o}"`),p.push(` printf '%s\\n' "$${o}"`),p.push(` return 0`),p.push(` end`),p.push(` set -l _bin (command -v ${c})`),p.push(` test -n "$_bin"; and test -x "$_bin"; and not test -d "$_bin"; and printf '%s\\n' "$_bin"`),p.push(`end`),p.push(``),p.push(`function __${r}_node_compile_cache_dir`),p.push(` if set -q NODE_COMPILE_CACHE; and test -n "$NODE_COMPILE_CACHE"`),p.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),p.push(` return 0`),p.push(` end`),p.push(l),p.push(`end`),p.push(``),p.push(`function __${r}_static_worker_path`),p.push(u),p.push(`end`),p.push(``),p.push(`function __${r}_worker_file_sig`),p.push(` set -l _worker $argv[1]`),p.push(` set -l _sig ${h(`$_worker`,{shell:`fish`,withSize:!0})}`),p.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),p.push(`end`),p.push(``),p.push(`function __${r}_is_worker_file`),p.push(` set -l _worker $argv[1]`),p.push(` test -f "$_worker"; or return 1`),p.push(` set -l _head (head -n 24 "$_worker" 2>/dev/null)`),p.push(` string match -q -- "# politty-completion-version: 1" $_head; or return 1`),p.push(` string match -q -- "# program: ${n}" $_head; or return 1`),p.push(` string match -q -- "# shell: fish" $_head; or return 1`),p.push(` string match -q -- "# politty-completion-mode: worker" $_head; or return 1`),p.push(` string match -q -- "# politty-completion-worker: true" $_head; or return 1`),p.push(`end`),p.push(``),p.push(`function __${r}_load_worker`),p.push(` set -l _worker $argv[1]`),p.push(` __${r}_is_worker_file "$_worker"; or return 1`),p.push(` set -l _sig (__${r}_worker_file_sig "$_worker")`),p.push(` test -n "$_sig"; or return 1`),p.push(` set -l _key "$_worker:$_sig"`),p.push(` if not set -q __${r}_loaded_worker_key; or test "$__${r}_loaded_worker_key" != "$_key"`),p.push(` source "$_worker" 2>/dev/null; or return 1`),p.push(` set -g __${r}_loaded_worker_key "$_key"`),p.push(` end`),p.push(` functions -q __fish_${i}_complete`),p.push(`end`),p.push(``),p.push(`function __${r}_realpath`),p.push(` set -l _path $argv[1]`),p.push(` set -l _old_pwd (pwd)`),p.push(` set -l _limit 0`),p.push(` while test -L "$_path"; and test $_limit -lt 40`),p.push(` set -l _dir (dirname "$_path")`),p.push(` if not cd "$_dir" 2>/dev/null`),p.push(` cd "$_old_pwd" 2>/dev/null`),p.push(` return 1`),p.push(` end`),p.push(` set -l _absdir (pwd -P)`),p.push(` cd "$_old_pwd" 2>/dev/null`),p.push(` test -n "$_absdir"; or return 1`),p.push(` set -l _target (readlink "$_path")`),p.push(` test -n "$_target"; or return 1`),p.push(` if string match -q '/*' -- "$_target"`),p.push(` set _path "$_target"`),p.push(` else`),p.push(` set _path "$_absdir/$_target"`),p.push(` end`),p.push(` set _limit (math $_limit + 1)`),p.push(` end`),p.push(` set -l _dir (dirname "$_path")`),p.push(` if not cd "$_dir" 2>/dev/null`),p.push(` cd "$_old_pwd" 2>/dev/null`),p.push(` return 1`),p.push(` end`),p.push(` set -l _absdir (pwd -P)`),p.push(` cd "$_old_pwd" 2>/dev/null`),p.push(` test -n "$_absdir"; or return 1`),p.push(` set -l _base (basename "$_path")`),p.push(` printf '%s\\n' "$_absdir/$_base"`),p.push(`end`),p.push(``),p.push(`function __${r}_worker_from_dir`),p.push(` set -l _dir $argv[1]`),d.length>0&&(p.push(` for _rel in ${d}`),p.push(` if string match -q '/*' -- "$_rel"`),p.push(` set _candidate "$_rel"`),p.push(` else`),p.push(` set _candidate "$_dir/$_rel"`),p.push(` end`),p.push(` if __${r}_is_worker_file "$_candidate"`),p.push(` printf '%s\\n' "$_candidate"`),p.push(` return 0`),p.push(` end`),p.push(` end`)),p.push(` return 1`),p.push(`end`),p.push(``),p.push(`function __${r}_cmd_shim_target`),p.push(` sed -n 's/^# cmd-shim-target=//p' "$argv[1]" 2>/dev/null | tail -n 1`),p.push(`end`),p.push(``),p.push(`function __${r}_bundled_worker_path`),p.push(` set -l _bin $argv[1]`),p.push(` set -l _node_compile_cache $argv[2]`),p.push(` set -l _real (__${r}_realpath "$_bin" 2>/dev/null)`),p.push(` if test -n "$_real"`),p.push(` set -l _dir (dirname "$_real")`),p.push(` __${r}_worker_from_dir "$_dir"; and return 0`),p.push(` end`),p.push(` set -l _dir (dirname "$_bin")`),p.push(` __${r}_worker_from_dir "$_dir"; and return 0`),p.push(` set -l _target (__${r}_cmd_shim_target "$_bin")`),p.push(` if test -n "$_target"`),p.push(` set _real (__${r}_realpath "$_target" 2>/dev/null)`),p.push(` test -n "$_real"; or set _real "$_target"`),p.push(` set _dir (dirname "$_real")`),p.push(` __${r}_worker_from_dir "$_dir"; and return 0`),p.push(` end`),f&&(p.push(` if set -q __${r}_queried_bin; and test "$__${r}_queried_bin" = "$_bin"; and test -n "$__${r}_queried_worker"; and __${r}_is_worker_file "$__${r}_queried_worker"`),p.push(` printf '%s\\n' "$__${r}_queried_worker"`),p.push(` return 0`),p.push(` end`),p.push(` set -l _reported (env NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path fish 2>/dev/null)`),p.push(` if test -n "$_reported"; and __${r}_is_worker_file "$_reported"`),p.push(` set -g __${r}_queried_bin "$_bin"`),p.push(` set -g __${r}_queried_worker "$_reported"`),p.push(` printf '%s\\n' "$_reported"`),p.push(` return 0`),p.push(` end`)),p.push(` return 1`),p.push(`end`),p.push(``),p.push(`function __${r}_bin_sig`),p.push(` set -l _bin $argv[1]`),p.push(` set -l _sig ${h(`$_bin`,{shell:`fish`})}`),p.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),p.push(`end`),p.push(``),p.push(`function __${r}_worker_matches_bin`),p.push(` set -l _worker $argv[1]`),p.push(` set -l _sig $argv[2]`),p.push(` set -l _bin $argv[3]`),p.push(` test -f "$_worker"; or return 1`),p.push(` set -l _head (head -n 12 "$_worker" 2>/dev/null)`),p.push(` contains -- "# politty-bin-sig: $_sig" $_head; or return 1`),p.push(` contains -- "# politty-bin-path: $_bin" $_head; or return 1`),p.push(`end`),p.push(``),p.push(`function __${r}_apply_dynamic_output`),p.push(` set -l _cur $argv[1]`),p.push(` set -l _directive 0`),p.push(` set -l _emitted 0`),p.push(` set -l _exts`),p.push(` set -l _matchers`),p.push(` set -l _lines`),p.push(` while read -l _l`),p.push(` set -a _lines $_l`),p.push(` end`),p.push(` set -l _n (count $_lines)`),p.push(` if test $_n -ge 1; and string match -qr '^:[0-9]+' -- $_lines[$_n]`),p.push(` set -l _fields (string split \\t -- $_lines[$_n])`),p.push(` set -e _lines[$_n]`),p.push(` set _directive (string sub -s 2 -- $_fields[1])`),p.push(` for _f in $_fields[2..-1]`),p.push(` if string match -q '@ext:*' -- $_f`),p.push(` set _exts (string split , -- (string sub -s 6 -- $_f))`),p.push(` else if string match -q '@matcher:*' -- $_f`),p.push(` set _matchers (string split , -- (string sub -s 10 -- $_f))`),p.push(` end`),p.push(` end`),p.push(` end`),p.push(` for _l in $_lines`),p.push(` if test -n "$_l"`),p.push(` printf '%s\\n' $_l`),p.push(` set _emitted 1`),p.push(` end`),p.push(` end`),p.push(` if test (count $_exts) -gt 0; or test (count $_matchers) -gt 0`),p.push(` __fish_complete_directories "$_cur"`),p.push(` set -l _dir ""`),p.push(` if string match -q '*/*' "$_cur"`),p.push(` set _dir (string replace -r '[^/]*$' '' "$_cur")`),p.push(` end`),p.push(` for _f in "$_cur"*`),p.push(` test -f "$_f"; or continue`),p.push(` for _ext in $_exts`),p.push(` if string match -q -- "*.$_ext" "$_f"`),p.push(` printf '%s\\n' "$_f"`),p.push(` break`),p.push(` end`),p.push(` end`),p.push(` end`),p.push(` for _pat in $_matchers`),p.push(` for _f in "$_dir"$_pat`),p.push(` test -f "$_f"; and string match -q "$_cur*" "$_f"; and printf '%s\\n' "$_f"`),p.push(` end`),p.push(` end`),p.push(` else if test (math "bitand($_directive, ${s.DirectoryCompletion})") -ne 0`),p.push(` __fish_complete_directories "$_cur"`),p.push(` else if test (math "bitand($_directive, ${s.FileCompletion})") -ne 0`),p.push(` __fish_complete_path "$_cur"`),p.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${s.NoFileCompletion})") -eq 0`),p.push(` __fish_complete_path "$_cur"`),p.push(` end`),p.push(`end`),p.push(``),p.push(`function __fish_${r}_complete`),p.push(` set -l _bin (__${r}_resolve_bin)`),p.push(` test -n "$_bin"; or return 0`),p.push(` set -l _node_compile_cache (__${r}_node_compile_cache_dir)`),p.push(` set -l _bundled_worker (__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")`),p.push(` if test -n "$_bundled_worker"; and __${r}_load_worker "$_bundled_worker"`),p.push(` set -lx ${a} "$_bin"`),p.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),p.push(` __fish_${i}_complete`),p.push(` return 0`),p.push(` end`),p.push(` set -l _worker (__${r}_static_worker_path)`),p.push(` set -l _sig (__${r}_bin_sig "$_bin")`),p.push(` if test -n "$_worker"; and test -n "$_sig"`),p.push(` if not __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),p.push(` mkdir -p (dirname "$_worker") 2>/dev/null`),p.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" $_bin __refresh-completion fish "$_worker" --static --worker 2>/dev/null`),p.push(` end`),p.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),p.push(` if __${r}_load_worker "$_worker"`),p.push(` set -lx ${a} "$_bin"`),p.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),p.push(` __fish_${i}_complete`),p.push(` return 0`),p.push(` end`),p.push(` end`),p.push(` end`),p.push(` set -l _args (commandline -opc)`),p.push(` set -l _cur (commandline -ct)`),p.push(` if test (count $_args) -gt 0`),p.push(` set _args $_args[2..]`),p.push(` end`),p.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" $_bin __complete --shell fish -- $_args "$_cur" 2>/dev/null | __${r}_apply_dynamic_output "$_cur"`),p.push(`end`),p.push(``),p.push(`complete -e -c ${n}`),p.push(`complete -c ${n} -f -a '(__fish_${r}_complete)'`),p.push(``),{script:p.join(`
|
|
40
|
+
`),shell:`fish`,installInstructions:`# To enable dispatcher fish completions, run:
|
|
41
|
+
${n} completion fish --install
|
|
42
|
+
|
|
43
|
+
# To generate the older static script:
|
|
44
|
+
${n} completion fish --static`}}function kt(e,t){switch(L(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=D(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=D(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,u(i,e,t));if(a.length===0)continue;let o=F(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 a=i(e,t);if(a.every(e=>e===void 0))return;let o=[` set _slot -1; set _left ${r}`];return e.forEach((e,t)=>{let r=a[t],i=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`;o.push(` if test $_slot -lt 0${i}; ${s}; end`)}),o}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,l(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,n){let r=[];for(let i of e){let a=X(i.description??``);if(i.valueType===`array`){r.push(` echo "--${i.cliName}\t${a}"`);continue}let o=t(i.cliName,i.alias,i.negation,{isGlobal:i.isGlobal===!0,frameOptions:e}),s=`__${n}_not_used ${o.join(` `)}`,c=i.negationDescription?X(i.negationDescription):a,l=[{name:i.cliName,desc:a}];i.negation&&l.push({name:i.negation,desc:c});for(let e of l)o.includes(`"--${e.name}"`)&&r.push(` ${s}; and echo "--${e.name}\t${e.desc}"`)}return r.push(` if test $_any_opt_used -eq 0`),r.push(` echo "--help Show help"`),r.push(` echo "--help-all Show help with all subcommand options"`),r.push(` echo "--help-json Show help as JSON"`),r.push(` end`),r}function Rt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(D).join(`_`)}`,a=A(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=j(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 N(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=L(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,c=r.command,l=A(c.subcommands),u=Ie(c),d=Re(c,u,r.globalOptions),f=u.length>0,p=u.filter(e=>e.isArrayOption),m=p.length>0,g=[];if(g.push(...B({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),g.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&g.push(`# politty-completion-worker: true`),g.push(`# Generated by politty`),g.push(``),!o){let e=z(n,t.binPath),r=R(e),o=O(i),s=`__${a}_refresh_completion`;g.push(`function ${s} --no-scope-shadowing`),g.push(` set -l _bin $${o}`),g.push(` test -z "$_bin"; and set _bin (command -v ${n})`),g.push(` test -z "$_bin"; and return 1`),g.push(` set -l _sig ${h(`$_bin`,{shell:`fish`})}`),g.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),g.push(` set -l _target (status current-filename)`),g.push(` test -n "$_target"; and test -f "$_target"; or return 1`),g.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),g.push(` and source "$_target" 2>/dev/null`),g.push(` and return 0`),g.push(` return 1`),g.push(`end`),g.push(`${s}`),g.push(`set -l _politty_refreshed $status`),g.push(`functions -e ${s}`),g.push(`test $_politty_refreshed -eq 0; and return`),g.push(``)}if(I(c)&&(g.push(`function __${a}_invoke_complete`),g.push(` set -l _shell $argv[1]`),g.push(` set -l _argv $argv[2..]`),g.push(` set -l _bin ${n}`),g.push(` if set -q ${O(a)}`),g.push(` set _bin $${O(a)}`),g.push(` end`),g.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),g.push(`end`),g.push(``),g.push(`function __${a}_apply_dynamic_output`),g.push(` set -l _cur $argv[1]`),g.push(` set -l _directive 0`),g.push(` set -l _emitted 0`),g.push(` set -l _prev ""`),g.push(` set -l _has_prev 0`),g.push(` while read -l _l`),g.push(` if test $_has_prev -eq 1`),g.push(` if test -n "$_prev"`),g.push(` printf '%s\\n' "$_prev"`),g.push(` set _emitted 1`),g.push(` end`),g.push(` end`),g.push(` set _prev $_l`),g.push(` set _has_prev 1`),g.push(` end`),g.push(` if test $_has_prev -eq 1`),g.push(` if string match -qr '^:[0-9]+$' -- $_prev`),g.push(` set _directive (string sub -s 2 -- $_prev)`),g.push(` else`),g.push(` if test -n "$_prev"`),g.push(` printf '%s\\n' "$_prev"`),g.push(` set _emitted 1`),g.push(` end`),g.push(` end`),g.push(` end`),g.push(` if test (math "bitand($_directive, ${s.DirectoryCompletion})") -ne 0`),g.push(` __fish_complete_directories "$_cur"`),g.push(` else if test (math "bitand($_directive, ${s.FileCompletion})") -ne 0`),g.push(` __fish_complete_path "$_cur"`),g.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${s.NoFileCompletion})") -eq 0`),g.push(` __fish_complete_path "$_cur"`),g.push(` end`),g.push(`end`),g.push(``)),g.push(`function __${a}_not_used --no-scope-shadowing`),g.push(` for _chk in $argv`),g.push(` if contains -- "$_chk" $_used_opts`),g.push(` return 1`),g.push(` end`),g.push(` end`),g.push(` return 0`),g.push(`end`),g.push(``),g.push(`function __${a}_opt_takes_value`),g.push(` switch "$argv[1]:$argv[2]"`),g.push(...zt(c,``)),g.push(` end`),g.push(` return 1`),g.push(`end`),g.push(``),f){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${D(e.fieldName)}`;g.push(`function __${a}_track_opt --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let t of d){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);g.push(` case ${n}`),g.push(` set -g ${e(t)} "$argv[3]"`)}g.push(` end`),g.push(`end`),g.push(``),g.push(`function __${a}_track_pos --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let t of d){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);g.push(` case ${n}`),g.push(` set -g ${e(t)} "$argv[3]"`)}g.push(` end`),g.push(`end`),g.push(``),g.push(`function __${a}_track_positionals --no-scope-shadowing`),g.push(` set -l _k 0`),g.push(` for _w in $_pos_words`),g.push(` set -l _slot $_k; set -l _left`),g.push(` switch "$_subcmd"`);for(let e of Oe(c)){g.push(` case ${e.pathStrs.map(e=>`"${e}"`).join(` `)}`);for(let t of Ft(e.positionals,e.options,a,`$_k`)??[])g.push(` ${t}`)}g.push(` end`),g.push(` __${a}_track_pos "$_subcmd" "$_slot" "$_w"`),g.push(` set _k (math $_k + 1)`),g.push(` end`),g.push(`end`),g.push(``)}if(m){g.push(`function __${a}_track_array_expand --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let e of p){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=D(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;g.push(` case ${t}`),g.push(` if string match -q '*=*' -- "$argv[3]"`),g.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),g.push(` if test -n "$_k"`),e.isGlobal?(g.push(` if not set -q _global_arr_seen_${n}`),g.push(` set -g ${r}${n} "$_k"`),g.push(` set -g _global_arr_seen_${n} 1`),g.push(` else if not contains -- "$_k" $${r}${n}`),g.push(` set -ga ${r}${n} "$_k"`),g.push(` end`)):(g.push(` if not contains -- "$_k" $${r}${n}`),g.push(` set -ga ${r}${n} "$_k"`),g.push(` end`)),g.push(` end`),g.push(` end`)}g.push(` end`),g.push(`end`),g.push(``)}let _=P(c);if(_.length>0){g.push(`function __${a}_is_subcmd`),g.push(` switch "$argv[1]:$argv[2]"`);for(let e of _)g.push(` case "${e.lookupPattern}"`),g.push(` return 0`);g.push(` end`),g.push(` return 1`),g.push(`end`),g.push(``)}for(let e of l)g.push(...Rt(e,a,[]));if(g.push(`function __${a}_complete_root --no-scope-shadowing`),g.push(...Pt(c.options,c.positionals,a)),g.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),c.positionals.length>0?(g.push(` if test $_after_dd -eq 1`),g.push(...Z(c.positionals,a,c.options).map(e=>` ${e}`)),g.push(` return`),g.push(` end`)):g.push(` if test $_after_dd -eq 1; return; end`),g.push(` if string match -q -- '-*' "$_cur"`),g.push(...Lt(c.options,a)),l.length>0){g.push(` else`);let e=j(c.subcommands);g.push(...It(e,c.positionals,a,c.options).map(e=>` ${e}`))}else c.positionals.length>0&&(g.push(` else`),g.push(...Z(c.positionals,a,c.options)));if(g.push(` end`),g.push(`end`),g.push(``),g.push(`function __fish_${a}_complete`),g.push(` set -l _args (commandline -opc)`),g.push(` set -e _args[1]`),g.push(``),g.push(` set -l _ct (commandline -ct)`),g.push(` if test (count $_ct) -eq 0`),g.push(` set -a _args ""`),g.push(` else`),g.push(` set -a _args $_ct`),g.push(` end`),g.push(``),g.push(` set -l _cur ""`),g.push(` if test (count $_args) -gt 0`),g.push(` set _cur "$_args[-1]"`),g.push(` end`),g.push(``),g.push(` set -l _prev ""`),g.push(` if test (count $_args) -gt 1`),g.push(` set _prev "$_args[-2]"`),g.push(` end`),g.push(``),g.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),g.push(` set -l _used_opts`),f&&g.push(` set -l _pos_words`),g.push(` set -l _any_opt_used 0`),g.push(``),f)for(let e of d)g.push(` set -e _arg_values_${D(e.fieldName)}`),g.push(` set -e _global_arg_values_${D(e.fieldName)}`);if(m)for(let e of p)g.push(` set -e _used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_arr_seen_${D(e.fieldName)}`);g.push(` set -l _j 1`),g.push(` set -l _limit (math (count $_args) - 1)`),g.push(` while test $_j -le $_limit`),g.push(` set -l _w "$_args[$_j]"`),g.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),g.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let v=f?`set -a _pos_words "$_w"; `:``;if(g.push(` if test $_after_dd -eq 1; ${v}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),g.push(` if string match -q -- '-*=*' "$_w"`),g.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),g.push(` set -a _used_opts "$_opt"`),g.push(` set _any_opt_used 1`),f&&(g.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),g.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),m&&g.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),g.push(` set _j (math $_j + 1); continue`),g.push(` end`),g.push(` if string match -q -- '-*' "$_w"`),g.push(` set -a _used_opts "$_w"`),g.push(` set _any_opt_used 1`),g.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),g.push(` set -l _next ""`),g.push(` set -l _next_idx (math $_j + 1)`),g.push(` if test $_next_idx -le (count $_args)`),g.push(` set _next "$_args[$_next_idx]"`),g.push(` end`),g.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),g.push(` set _skip_next 1`),f&&(g.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),m&&(g.push(` if test $_j -lt $_limit`),g.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),g.push(` end`))),g.push(` end`),g.push(` end`),g.push(` set _j (math $_j + 1); continue`),g.push(` end`),_.length>0){if(g.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),g.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),g.push(` set _used_opts; set _pos_count 0`),f){g.push(` set _pos_words`);for(let e of d)g.push(` set -e _arg_values_${D(e.fieldName)}`);if(m)for(let e of p)g.push(` set -e _used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_arr_seen_${D(e.fieldName)}`)}g.push(` else`),f&&g.push(` set -a _pos_words "$_w"`),g.push(` set _pos_count (math $_pos_count + 1)`),g.push(` end`)}else f&&g.push(` set -a _pos_words "$_w"`),g.push(` set _pos_count (math $_pos_count + 1)`);g.push(` set _j (math $_j + 1)`),g.push(` end`),f&&g.push(` __${a}_track_positionals`),g.push(``),g.push(` switch "$_subcmd"`);for(let e of _)g.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return g.push(` case '*'; __${a}_complete_root`),g.push(` end`),g.push(`end`),g.push(``),o||(g.push(`# Clear existing completions`),g.push(`complete -e -c ${n}`),g.push(``),g.push(`# Register completion`),g.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),g.push(``),{script:g.join(`
|
|
45
|
+
`),shell:`fish`,installInstructions:`# To enable auto-refreshing fish completions, run:
|
|
46
|
+
${n} completion fish --install --static`}}function Vt(e,t){ie(E(e),{recursive:!0});let n=`${e}.tmp.${process.pid}`;se(n,t),ae(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=b(e.programName,t,e.cacheDir);return Vt(n,Ht(e,t)),n}function Wt(e){try{if(!S(e))return;let t=C(e,`utf8`).split(`
|
|
47
|
+
`,10).join(`
|
|
48
|
+
`).match(/^# politty-completion-mode: (dispatcher|static)$/m);return t?t[1]:void 0}catch{return}}function Gt(e){try{if(!S(e))return null;let t=C(e,`utf8`).split(`
|
|
49
|
+
`,10).join(`
|
|
50
|
+
`).match(/^# politty-bin-path: (.*)$/m);return t?t[1]:null}catch{return null}}function Kt(e,t,n){try{if(!S(e))return!1;let r=C(e,`utf8`).split(`
|
|
51
|
+
`,8).map(e=>e.trimEnd());return r.some(e=>/^# politty-completion-version: \S+$/.test(e))&&r.includes(`# program: ${t}`)&&r.includes(`# shell: ${n}`)}catch{return!1}}function qt(e,t){try{let n=e.targetPath?S(e.targetPath)?w(e.targetPath):e.targetPath:b(e.programName,t,e.cacheDir);if(e.targetPath&&S(n)&&!Kt(n,e.programName,t)||e.targetPath&&!S(n)&&!e.allowTargetCreate)return;let r=z(e.programName,e.binPath);if(!r)return;let i;try{i=Math.floor(T(r).mtimeMs/1e3).toString()}catch{return}if(te(n)===i&&Gt(n)===r)return;let a=e.completionMode??Wt(n)??(S(n)?`static`:`dispatcher`);Vt(n,Ht({...e,completionMode:a},t))}catch{}}function Jt(e,t,n){return t?m(`${t}/completion.${n}`):`"\${XDG_CACHE_HOME:-$HOME/.cache}/${e}/completion.${n}"`}function Yt(e){let t=D(e.programName),n=O(t),r=Jt(e.programName,e.cacheDir,`bash`);return`__${t}_load_completion() {
|
|
52
|
+
local _bin _cache _sig _sig_hdr _path_hdr
|
|
53
|
+
_bin="\${${n}:-$(type -P ${e.programName} 2>/dev/null)}"
|
|
54
|
+
[[ -n "$_bin" ]] || return 0
|
|
55
|
+
_cache=${r}
|
|
56
|
+
_sig=$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null) || return 0
|
|
57
|
+
_sig_hdr="# politty-bin-sig: $_sig"
|
|
58
|
+
_path_hdr="# politty-bin-path: $_bin"
|
|
59
|
+
if [[ ! -f "$_cache" ]] || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_sig_hdr" || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_path_hdr"; then
|
|
60
|
+
# Use the hidden __refresh-completion subcommand instead of
|
|
61
|
+
# \`$_bin completion bash\`: the foreground completion command
|
|
62
|
+
# is subject to user setup/cleanup/prompt and required
|
|
63
|
+
# globalArgs validation, which can silently fail or block when
|
|
64
|
+
# invoked from rc; runMain bypasses those for __-prefixed
|
|
65
|
+
# internal subcommands.
|
|
66
|
+
"$_bin" __refresh-completion bash 2>/dev/null
|
|
67
|
+
fi
|
|
68
|
+
# If regen failed but a stale cache survived from a previous run,
|
|
69
|
+
# source it anyway — a stale completion is preferable to no
|
|
70
|
+
# completion at all.
|
|
71
|
+
[[ -f "$_cache" ]] || return 0
|
|
72
|
+
# shellcheck disable=SC1090
|
|
73
|
+
source "$_cache"
|
|
74
|
+
}
|
|
75
|
+
__${t}_load_completion
|
|
76
|
+
unset -f __${t}_load_completion
|
|
77
|
+
`}function Xt(e){let t=D(e.programName),n=O(t),r=Jt(e.programName,e.cacheDir,`zsh`);return`__${t}_load_completion() {
|
|
78
|
+
emulate -L zsh
|
|
79
|
+
setopt local_options no_aliases
|
|
80
|
+
local _bin _cache _sig _sig_hdr _path_hdr
|
|
81
|
+
_bin="\${${n}:-$(whence -p ${e.programName} 2>/dev/null)}"
|
|
82
|
+
[[ -n "$_bin" ]] || return 0
|
|
83
|
+
_cache=${r}
|
|
84
|
+
_sig=$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null) || return 0
|
|
85
|
+
_sig_hdr="# politty-bin-sig: $_sig"
|
|
86
|
+
_path_hdr="# politty-bin-path: $_bin"
|
|
87
|
+
if [[ ! -f "$_cache" ]] || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_sig_hdr" || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_path_hdr"; then
|
|
88
|
+
# See bash loader for why we use __refresh-completion instead
|
|
89
|
+
# of \`$_bin completion zsh\`.
|
|
90
|
+
"$_bin" __refresh-completion zsh 2>/dev/null
|
|
91
|
+
fi
|
|
92
|
+
# See bash loader: keep stale completion over no completion.
|
|
93
|
+
[[ -f "$_cache" ]] || return 0
|
|
94
|
+
source "$_cache"
|
|
95
|
+
}
|
|
96
|
+
__${t}_load_completion
|
|
97
|
+
unfunction __${t}_load_completion
|
|
98
|
+
`}function Zt(e){switch(e.shell){case`bash`:return Yt(e);case`zsh`:return Xt(e);case`fish`:throw Error("fish does not use an rc loader. Run `<program> completion fish --install` to write the self-refreshing autoload file instead.")}}function Q(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`").replace(/:/g,`\\:`)}function Qt(e){return e.replace(/\\/g,`\\\\`).replace(/:/g,`\\:`)}function $t(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function en(e){return e.map(e=>`"${$t(e)}"`).join(` `)}function tn(e,t,n){let r=[`setopt local_options null_glob`,'local _cur="${words[CURRENT]:-}" _dir _prefix _f _out',`local -a ${t===`extensions`?`_exts`:`_matchers`}=(${en(n)})`,`if [[ -z "$_cur" || "$_cur" != */* ]]; then`,` _dir="."`,` _prefix="$_cur"`,`elif [[ "$_cur" == */ ]]; then`,' _dir="${_cur%/}"',` _prefix=""`,`else`,' _dir="${_cur%/*}"',' _prefix="${_cur##*/}"',`fi`,`for _f in "$_dir"/"$_prefix"*(N/); do`,' _out="${_f#./}"',` __${e}_add_path_candidate "$_out"`,`done`];return t===`extensions`?(r.push(`local _ext`),r.push(`for _f in "$_dir"/"$_prefix"*(N.); do`),r.push(' _out="${_f#./}"'),r.push(' for _ext in "${_exts[@]}"; do'),r.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${e}_add_path_candidate "$_out"; break; }`),r.push(` done`),r.push(`done`)):(r.push(`local _pat`),r.push('for _pat in "${_matchers[@]}"; do'),r.push(` [[ -n "$_pat" ]] || continue`),r.push(' for _f in "$_dir"/${~_pat}(N.); do'),r.push(' _out="${_f#./}"'),r.push(` [[ "$_out" == "$_cur"* ]] && __${e}_add_path_candidate "$_out"`),r.push(` done`),r.push(`done`)),r}function nn(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`zshValueLines: expand variant requires a location`);let e=k(t,n.funcSuffix,n.fieldName),r=n.resolvedDeps.map(e=>e.isGlobal?`"\${_global_arg_values[${e.name}]:-}"`:`"\${_arg_values[${e.name}]:-}"`).join(`$'\\x1f'`),i=D(n.fieldName),a=n.isGlobal?`\${_global_used_field_keys[${i}]:-}`:`\${_used_field_keys[${i}]:-}`,o=n.isArrayOption?[` if [[ -n "$_ck" && " ${a} " == *" $_ck "* ]]; then continue; fi`]:[];return[`local _key=${r}`,`local _raw="\${${e}[$_key]:-}"`,`if [[ -n "$_raw" ]]; then`,' local -a _candidates=("${(@f)_raw}")',` _vals=()`,` local _c _ck _cke _vp _seen_keys=" " _desc _has_eq=0 _tmp`,' for _c in "${_candidates[@]}"; do',` _tmp="\${_c//\\\\:/$'\\x01'}"`,' _vp="${_tmp%%:*}"',` if [[ "$_vp" == *=* ]]; then`,' _cke="${_c%%=*}"',' _ck="${_cke//\\\\:/:}"',...o,' if [[ "${words[CURRENT]}" != *=* ]]; then',` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,` if [[ "$_tmp" == *:* ]]; then`,` _desc="\${\${_tmp#*:}//$'\\x01'/\\\\:}"`,' _c="${_cke}=:$_desc"',` else`,' _c="${_cke}="',` fi`,` _has_eq=1`,` else`,` [[ "$_vp" == *=?* ]] || continue`,` fi`,` fi`,` _vals+=("$_c")`,` done`,` if (( _has_eq )); then`,` __${t}_cdescribe 'completions' _vals -S ''`,` else`,` __${t}_cdescribe 'completions' _vals`,` fi`,`fi`]}case`dynamic`:return[`__${t}_apply_dynamic_output "$(__${t}_invoke_complete zsh "\${(@)words[2,CURRENT]}")"`];case`choices`:return[`_vals=(${e.choices.map(e=>`"${Q(e)}"`).join(` `)})`,`__${t}_cdescribe 'completions' _vals`];case`file`:return e.matcher?.length?tn(t,`matchers`,e.matcher):e.extensions?.length?tn(t,`extensions`,e.extensions):[`_files`];case`directory`:return[`_files -/`];case`command`:return[`_vals=("\${(@f)$(${e.shellCommand})}")`,`__${t}_cdescribe 'completions' _vals`];case`none`:return[];case`runtime-expand`:return[]}}function rn(e,t,n,r){let i=[];for(let a of e){if(!a.takesValue||!a.valueCompletion)continue;let o=nn(a.valueCompletion,n,{funcSuffix:r,...u(a,e,t)});if(o.length===0)continue;let s=F(a,e);if(s.length!==0){i.push(` ${s.join(`|`)})`);for(let e of o)i.push(` ${e}`);i.push(` return 0 ;;`)}}return i}function $(e,t,n,r=[]){if(e.length===0)return[];let i=o(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})`);let s=nn(o.valueCompletion,t,{funcSuffix:n,...l(o,r,e)});for(let e of s)a.push(` ${e}`);a.push(` ;;`)}return a.push(` esac`),a}function an(e,t,n,r,i){let a=[`local -a _subs=(${e.map(e=>{let t=e.description?`:${Q(e.description)}`:``;return`"${e.name}${t}"`}).join(` `)})`,`__${n}_cdescribe 'subcommands' _subs`];return t.length===0?a:[`local -a _sub_names=(${e.map(e=>`"${$t(e.name)}"`).join(` `)})`,'local _cur_word="${words[CURRENT]:-}" _sub_name _sub_match=0','for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur_word"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...$(t,n,r,i),`fi`]}function on(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=rn(e,t,n,r);return i.length===0?[]:[' case "${words[CURRENT-1]}" in',...i,` esac`]}function sn(e,n){let r=[];for(let i of e){let a=i.description?`:${Q(i.description)}`:``;if(i.valueType===`array`){r.push(` _opts+=("--${i.cliName}${a}")`);continue}let o=t(i.cliName,i.alias,i.negation,{isGlobal:i.isGlobal===!0,frameOptions:e}),s=`__${n}_not_used ${o.join(` `)}`,c=i.negationDescription?`:${Q(i.negationDescription)}`:a,l=[{name:i.cliName,desc:a}];i.negation&&l.push({name:i.negation,desc:c});for(let e of l)o.includes(`"--${e.name}"`)&&r.push(` ${s} && _opts+=("--${e.name}${e.desc}")`)}return r.push(` if (( ! _any_opt_used )); then`),r.push(` _opts+=("--help:Show help")`),r.push(` _opts+=("--help-all:Show help with all subcommand options")`),r.push(` _opts+=("--help-json:Show help as JSON")`),r.push(` fi`),r}function cn(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...cn(e,t,r));s.push(`${a}() {`),s.push(` local -a _vals=()`),s.push(...on(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if __${t}_opt_takes_value "${c}" "\${words[CURRENT-1]}"; then return 0; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...$(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return 0`),s.push(` fi`)):s.push(` if (( _after_dd )); then return 0; fi`),s.push(' if [[ "${words[CURRENT]}" == -* ]]; then'),s.push(` local -a _opts=()`),s.push(...sn(e.options,t)),s.push(` __${t}_cdescribe 'options' _opts`),s.push(` return 0`),s.push(` fi`),o.length>0){let n=j(e.subcommands);s.push(...an(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...$(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function ln(e,t){let{programName:r}=t,i=L(e,r,t.globalArgsSchema),o=D(r),c=t.staticWorker?`${o}_${D(t.staticWorker.functionSuffix)}`:o,l=t.staticWorker!==void 0,u=l?`_${c}_completions`:`_${r}`,d=`"\${funcstack[1]:-}" == "${$t(u)}"`,f=i.command,p=A(f.subcommands),m=Ie(f),h=Re(f,m,i.globalOptions),g=m.length>0,_=m.filter(e=>e.isArrayOption),v=_.length>0,y=[];l||(y.push(`#compdef ${r}`),y.push(``)),y.push(...B({programName:r,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),y.push(`# politty-completion-mode: ${l?`worker`:`static`}`),l&&y.push(`# politty-completion-worker: true`),y.push(`# Generated by politty`),y.push(``),l||y.push(...We({programName:r,binPath:t.binPath}));for(let e of m){let t=k(c,e.funcSuffix,e.fieldName);if(e.vc.table.length===0)y.push(`typeset -gA ${t}=()`);else{y.push(`typeset -gA ${t}=(`);for(let t of e.vc.table){let e=t.key.join(``),r=t.candidates.map(e=>{let t=Qt(e.value);return e.description?`${t}:${e.description}`:t}).join(`
|
|
99
|
+
`);y.push(` ${n(e)} ${n(r)}`)}y.push(`)`)}y.push(``)}I(f)&&(y.push(...xe(c,r)),y.push(``),y.push(`__${c}_apply_dynamic_output() {`),y.push(` local _raw="$1"`),y.push(` local _directive=0`),y.push(` local -a _vals _lines`),y.push(' _lines=("${(@f)_raw}")'),y.push(` local _last=$#_lines`),y.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<-> ]]; then'),y.push(' _directive="${_lines[$_last]#:}"'),y.push(` _lines[$_last]=()`),y.push(` fi`),y.push(` local _l`),y.push(' for _l in "${_lines[@]}"; do'),y.push(` [[ -z "$_l" ]] && continue`),y.push(` _vals+=("$_l")`),y.push(` done`),y.push(" if (( ${#_vals[@]} > 0 )); then"),y.push(` if (( _directive & ${s.NoSpace} )); then`),y.push(` __${c}_cdescribe 'completions' _vals -S ''`),y.push(` else`),y.push(` __${c}_cdescribe 'completions' _vals`),y.push(` fi`),y.push(` fi`),y.push(` if (( _directive & ${s.DirectoryCompletion} )); then`),y.push(` _files -/`),y.push(` elif (( _directive & ${s.FileCompletion} )); then`),y.push(` _files`),y.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${s.NoFileCompletion} )); then`),y.push(` _files`),y.push(` fi`),y.push(`}`),y.push(``)),y.push(`__${c}_not_used() {`),y.push(` local _u _chk`),y.push(' for _u in "${_used_opts[@]}"; do'),y.push(` for _chk in "$@"; do`),y.push(` [[ "$_u" == "$_chk" ]] && return 1`),y.push(` done`),y.push(` done`),y.push(` return 0`),y.push(`}`),y.push(``),y.push(`__${c}_cdescribe() {`),y.push(` _describe "$@" 2>/dev/null && return 0`),y.push(` shift`),y.push(` local _cd_arr="$1"`),y.push(` shift`),y.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),y.push(` compadd "$@" -a _cd_vals 2>/dev/null`),y.push(` return 0`),y.push(`}`),y.push(``),y.push(`__${c}_add_path_candidate() {`),y.push(` compadd -f -- "$1" 2>/dev/null && return 0`),y.push(` print -r -- "$1"`),y.push(`}`),y.push(``),y.push(`__${c}_opt_takes_value() {`),y.push(` case "$1:$2" in`),y.push(...ke(f,``)),y.push(` esac`),y.push(` return 1`),y.push(`}`),y.push(``),g&&(y.push(`__${c}_track_opt() {`),y.push(` case "$1:$2" in`),y.push(...Ne(h,`zsh`)),y.push(` esac`),y.push(`}`),y.push(``),y.push(`__${c}_track_pos() {`),y.push(` case "$1:$2" in`),y.push(...Pe(h,`zsh`)),y.push(` esac`),y.push(`}`),y.push(``),y.push(...a(c,Oe(f)))),v&&(y.push(`__${c}_track_array_expand() {`),y.push(` case "$1:$2" in`),y.push(...Fe(_,`zsh`)),y.push(` esac`),y.push(`}`),y.push(``));let b=P(f);b.length>0&&(y.push(`__${c}_is_subcmd() {`),y.push(` case "$1:$2" in`),y.push(...Ae(b)),y.push(` esac`),y.push(` return 1`),y.push(`}`),y.push(``));for(let e of p)y.push(...cn(e,c,[]));if(y.push(`__${c}_complete_root() {`),y.push(` local -a _vals=()`),y.push(...on(f.options,f.positionals,c,`root`)),y.push(` if __${c}_opt_takes_value "" "\${words[CURRENT-1]}"; then return 0; fi`),f.positionals.length>0?(y.push(` if (( _after_dd )); then`),y.push(...$(f.positionals,c,`root`,f.options).map(e=>` ${e}`)),y.push(` return 0`),y.push(` fi`)):y.push(` if (( _after_dd )); then return 0; fi`),y.push(' if [[ "${words[CURRENT]}" == -* ]]; then'),y.push(` local -a _opts=()`),y.push(...sn(f.options,c)),y.push(` __${c}_cdescribe 'options' _opts`),p.length>0){y.push(` else`);let e=j(f.subcommands);y.push(...an(e,f.positionals,c,`root`,f.options).map(e=>` ${e}`))}else f.positionals.length>0&&(y.push(` else`),y.push(...$(f.positionals,c,`root`,f.options).map(e=>` ${e}`)));y.push(` fi`),y.push(`}`),y.push(``);let ee=je(b,c).join(`
|
|
100
|
+
`);y.push(`${u}() {`),y.push(" (( CURRENT )) || CURRENT=${#words}"),y.push(``),y.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),y.push(` local -a _used_opts=()`),g&&y.push(` local -a _pos_words=()`),y.push(` local _any_opt_used=0`),g&&(y.push(` local -A _arg_values=()`),y.push(` local -A _global_arg_values=()`)),v&&(y.push(` local -A _used_field_keys=()`),y.push(` local -A _global_used_field_keys=()`),y.push(` local -A _global_arr_seen=()`)),y.push(``),y.push(` local _j=2`),y.push(` while (( _j < CURRENT )); do`),y.push(' local _w="${words[_j]}"'),y.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),y.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let x=g?`_pos_words+=("$_w"); `:``;y.push(` if (( _after_dd )); then ${x}(( _pos_count++ )); (( _j++ )); continue; fi`),y.push(` if [[ "$_w" == -*=* ]]; then`),y.push(' _used_opts+=("${_w%%=*}")'),y.push(` _any_opt_used=1`),g&&(y.push(` __${c}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),v&&y.push(` __${c}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),y.push(` (( _j++ )); continue`),y.push(` fi`),y.push(` if [[ "$_w" == -* ]]; then`),y.push(` _used_opts+=("$_w")`),y.push(` _any_opt_used=1`),y.push(` if __${c}_opt_takes_value "$_subcmd" "$_w"; then`),y.push(' local _next="${words[_j+1]:-}"'),y.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),g&&(y.push(` if (( _skip_next )); then`),y.push(` __${c}_track_opt "$_subcmd" "$_w" "$_next"`),v&&(y.push(` if (( _j + 1 < CURRENT )); then`),y.push(` __${c}_track_array_expand "$_subcmd" "$_w" "$_next"`),y.push(` fi`)),y.push(` fi`)),y.push(` fi`),y.push(` (( _j++ )); continue`),y.push(` fi`);let te=v?`; _arg_values=(); _used_field_keys=(); _global_arr_seen=()`:g?`; _arg_values=()`:``,ne=g?`_pos_words+=("$_w"); `:``;return b.length>0?y.push(` if __${c}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${g?`; _pos_words=()`:``}${te}; else ${ne}(( _pos_count++ )); fi`):(g&&y.push(` _pos_words+=("$_w")`),y.push(` (( _pos_count++ ))`)),y.push(` (( _j++ ))`),y.push(` done`),g&&y.push(` __${c}_track_positionals`),y.push(``),y.push(` case "$_subcmd" in`),y.push(ee),y.push(` *) __${c}_complete_root ;;`),y.push(` esac`),y.push(`}`),y.push(``),y.push(`zstyle ':completion:*:*:${r}:*' file-patterns '%p:globbed-files *(-/):directories'`),y.push(``),l||(y.push(`if [[ ${d} ]]; then`),y.push(` ${u} "$@"`),y.push(`else`),y.push(` compdef ${u} ${r}`),y.push(`fi`),y.push(``)),{script:y.join(`
|
|
101
|
+
`),shell:`zsh`,installInstructions:`# To enable auto-refreshing zsh completions, add this to your ~/.zshrc after compinit:
|
|
102
|
+
eval "$(${r} completion zsh --static)"
|
|
103
|
+
|
|
104
|
+
# For faster shell startup, save the script in your fpath:
|
|
105
|
+
mkdir -p ~/.zsh/completions
|
|
106
|
+
${r} completion zsh --static > ~/.zsh/completions/_${r}
|
|
107
|
+
|
|
108
|
+
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
109
|
+
fpath=(~/.zsh/completions $fpath)
|
|
110
|
+
autoload -Uz compinit && compinit
|
|
111
|
+
|
|
112
|
+
# If ~/.zshrc already calls compinit, add only the fpath line before
|
|
113
|
+
# the existing compinit call.
|
|
114
|
+
|
|
115
|
+
# Then reload your shell or run:
|
|
116
|
+
source ~/.zshrc`}}function un(e,t){if(t.mode===`dispatcher`)return kt(e,t);switch(t.shell){case`bash`:return et(e,t);case`zsh`:return ln(e,t);case`fish`:return Bt(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function dn(){return[`bash`,`zsh`,`fish`]}function fn(e,t){console.error(``),console.error(`Configure zsh fpath with:`),console.error(``),console.error(` mkdir -p ~/.zsh/completions`),console.error(` ln -sf ${m(t)} ~/.zsh/completions/_${e}`),console.error(``),console.error(`Add only this block to your ~/.zshrc before compinit:`),console.error(``),console.error(` fpath=(~/.zsh/completions $fpath)`),console.error(` autoload -Uz compinit && compinit`)}function pn(t,n,r,i={}){let a=n??t.name,{cacheDir:o,programVersion:s}=i,c={...o!==void 0&&{cacheDir:o},...s!==void 0&&{programVersion:s},...r!==void 0&&{globalArgsSchema:r},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker}},l={programName:a,...c},u={programName:a,...o!==void 0&&{cacheDir:o}};return t.subCommands?.__complete||(t.subCommands={...t.subCommands,__complete:f(t,a,r)}),t.subCommands?.[`__refresh-completion`]||(t.subCommands={...t.subCommands,"__refresh-completion":mn(t,a,c)}),t.subCommands?.[`__completion-worker-path`]||(t.subCommands={...t.subCommands,"__completion-worker-path":hn(a,c)}),e({name:`completion`,description:`Generate shell completion script`,args:x,run(e){let n=e.shell||re();if(!n){console.error(`Could not detect shell type. Please specify one of: bash, zsh, fish`),process.exitCode=1;return}if(e.static&&e.dispatcher)throw Error(`Choose only one completion mode: --dispatcher or --static.`);if(e.worker&&!e.static)throw Error("`--worker` requires `--static`.");if(e.worker&&(e.install||e.loader||e.instructions))throw Error("`--worker` can only print a worker artifact.");let c=e.static?`static`:`dispatcher`;if(e.install){let e;try{e=Ut({rootCommand:t,...l,completionMode:c},n)}catch(e){throw Error(`install failed: ${e instanceof Error?e.message:String(e)}`)}console.error(`installed: ${e}`),n===`bash`?(console.error(``),console.error(`Add to your ~/.${n}rc:`),console.error(``),console.error(Zt({...u,shell:n}).trim().replace(/^/gm,` `))):n===`zsh`&&fn(a,e);return}if(e.loader){if(n===`fish`)throw Error("fish does not use an rc loader. Run `<program> completion fish --install` to write the self-refreshing autoload file instead.");process.stdout.write(Zt({...u,shell:n}));return}let d=un(t,{shell:n,programName:a,mode:c,includeDescriptions:!0,...r!==void 0&&{globalArgsSchema:r},...s!==void 0&&{programVersion:s},...o!==void 0&&{cacheDir:o},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker},...e.worker&&{staticWorker:{functionSuffix:`worker`}}});e.instructions?console.log(d.installInstructions):console.log(d.script)}})}function mn(t,n,r={}){return e({name:`__refresh-completion`,description:`(internal) Refresh the on-disk completion cache if stale.`,args:ne,run(e){qt({rootCommand:t,programName:n,...r,completionMode:e.static||e.worker?`static`:void 0,...e.worker&&{staticWorker:{functionSuffix:`worker`}},...e.worker&&{allowTargetCreate:!0},...e.target!==void 0&&{targetPath:e.target}},e.shell)}})}function hn(t,n={}){return e({name:`__completion-worker-path`,description:`(internal) Print the bundled completion worker path when available.`,args:ee,run(e){let r=dt({programName:t,shell:e.shell,...n.binPath!==void 0&&{binPath:n.binPath},...n.bundledWorker!==void 0&&{bundledWorker:n.bundledWorker}});if(!r)throw Error(`No bundled completion worker found for ${t} (${e.shell}).`);console.log(r)}})}export{dn as a,_t as c,Ce as d,un as i,K as l,hn as n,rt as o,mn as r,it as s,pn as t,L as u};
|
package/dist/completion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as e,t}from"./with-completion-command-
|
|
1
|
+
import{s as e,t}from"./with-completion-command-BH--VXVo.js";import"./register-D-aEK58y.js";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./dynamic-iwEE4Vdk.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-BlhEgaLs.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{c as e,n as t,o as n,r,s as i,t as a,y as o}from"./schema-extractor-BI5ypJ21.js";import{t as s}from"./
|
|
1
|
+
import"./register-D-aEK58y.js";import{c as e,n as t,o as n,r,s as i,t as a,y as o}from"./schema-extractor-BI5ypJ21.js";import{t as s}from"./log-collector-uhRWYT-z.js";import{t as c}from"./registry-ZnSdmqJ1.js";import{r as l}from"./subcommand-router-40vA6Mka.js";import*as u from"node:fs";import d,*as f from"node:path";import{isDeepStrictEqual as p}from"node:util";const m=[`option`,`alias`,`description`,`required`,`default`];function h(e){return`(↔ \`--${e.cliName}\`)`}function g(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function _(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${g(e)}>`}function v(e){let t=_(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:h(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function y(e){return e.map(v)}function b(e){return e.replace(/\r?\n/g,`<br>`)}function x(e){return b(e.replace(/\|/g,`\\|`))}function S(e){return`\`${e}\``}function C(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function ee(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function E(e,t){switch(t){case`option`:{let t=S(e.longFlag);return e.inlineNegation?`${t} / ${S(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(S).join(`, `):`-`;case`description`:return x(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return C(e);case`env`:return ee(e.env)}}function D(e,t){switch(t){case`option`:return S(e.flag);case`description`:return`${x(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function O(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...m,`env`]:m),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>E(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>D(t.negationRow,e)).join(` | `)} |`);return r.join(`
|
|
2
2
|
`)}function k(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.aliases.filter(e=>!e.startsWith(`--`)),r=n.aliases.filter(e=>e.startsWith(`--`)),i=[...e,n.longFlag,...r].map(S).join(`, `);n.inlineNegation&&(i+=` / ${S(n.inlineNegation)}`);let a=n.description?` - ${b(n.description)}`:``,o=n.required?` (required)`:``,s=n.hasDefault?` (default: ${JSON.stringify(n.defaultValue)})`:``,c=w(n.env);t.push(`- ${i}${a}${o}${s}${c}`),n.negationRow&&t.push(`- ${S(n.negationRow.flag)} - ${b(n.negationRow.description)} ${n.negationRow.relationMarker}`)}return t.join(`
|
|
3
3
|
`)}const A=`POLITTY_DOCS_UPDATE`,j=`POLITTY_DOCS_DOCTOR`,M=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],N=`politty:command`;function P(e,t){return`<!-- ${N}:${t}:${e}:start -->`}function F(e,t){return`<!-- ${N}:${t}:${e}:end -->`}const I=`politty:global-options`;function L(){return`<!-- ${I}:start -->`}function te(){return`<!-- ${I}:end -->`}const R=`politty:root-header`;function ne(){return`<!-- ${R}:start -->`}function re(){return`<!-- ${R}:end -->`}const z=`politty:root-footer`;function ie(){return`<!-- ${z}:start -->`}function ae(){return`<!-- ${z}:end -->`}const B=`politty:index`;function V(e){return`<!-- ${B}:${e}:start -->`}function oe(e){return`<!-- ${B}:${e}:end -->`}function se(e){return b(e.replace(/\|/g,`\\|`))}function ce(e){let t=[e.fullCommandPath];e.options.length>0&&t.push(`[options]`),e.subCommands.length>0&&(e.command.run||e.command.defaultSubCommand?t.push(`[command]`):t.push(`<command>`));for(let n of e.positionalArgs)n.required?t.push(`<${n.name}>`):t.push(`[${n.name}]`);return t.join(` `)}function le(e){return fe(e,Ce)}function ue(e){return e.named?`\`${e.name}\`, \`${_(e)}\``:`\`${e.name}\``}function de(e){return fe(e,we)}function fe(e,t,n=e.positionalArgs){let r=pe(e.extracted),i=r.length>0?a(r):void 0,o=new Set(n.map(e=>e.name)),s=[],c=n.filter(e=>i===void 0||i.has(e.name));c.length>0&&s.push(t(c));for(let e of r){let n=e.fields.filter(e=>e.positional&&!i?.has(e.name)&&o.has(e.name));n.length>0&&s.push(`${e.label}\n\n${t(n)}`)}return s.join(`
|
|
4
4
|
|
|
@@ -18,9 +18,9 @@ import{c as e,n as t,o as n,r,s as i,t as a,y as o}from"./schema-extractor-BI5yp
|
|
|
18
18
|
`}}const ke={command:e=>W(e),tableStyle:W({optionStyle:`table`}),listStyle:W({optionStyle:`list`})};function Ae(e,t){let n=f.resolve(t);if(!u.existsSync(n))return{match:!1,fileExists:!1};let r=u.readFileSync(n,`utf-8`);return e===r?{match:!0,fileExists:!0}:{match:!1,diff:G(r,e),fileExists:!0}}function G(e,t){let n=e.split(`
|
|
19
19
|
`),r=t.split(`
|
|
20
20
|
`),i=[];i.push(`--- existing`),i.push(`+++ generated`),i.push(``);let a=Math.max(n.length,r.length),o=!1,s=0,c=[],l=()=>{c.length>0&&(i.push(`@@ -${s+1},${c.length} @@`),i.push(...c),c.length=0),o=!1};for(let e=0;e<a;e++){let t=n[e],i=r[e];if(t===i){if(o){c.push(` ${t??``}`);let e=c.findIndex((e,t)=>(e.startsWith(`-`)||e.startsWith(`+`))&&c.slice(t+1).every(e=>e.startsWith(` `)));e!==-1&&c.length-e>3&&l()}}else{if(!o){o=!0,s=e;let t=Math.max(0,e-3);for(let r=t;r<e;r++)c.push(` ${n[r]??``}`)}t!==void 0&&(i===void 0||t!==i)&&c.push(`-${t}`),i!==void 0&&(t===void 0||t!==i)&&c.push(`+${i}`)}}return l(),i.join(`
|
|
21
|
-
`)}function K(e,t){let n=f.resolve(e),r=f.dirname(n);u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(n,t,`utf-8`)}function je(e){let t=f.resolve(e);return u.existsSync(t)?u.readFileSync(t,`utf-8`):null}function Me(e,t=u){let n=f.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,t,n=[]){return Pe(e,t,n,!1)}async function Pe(t,n,a,o){let s=r(t),
|
|
22
|
-
`),u=
|
|
23
|
-
`);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:
|
|
21
|
+
`)}function K(e,t){let n=f.resolve(e),r=f.dirname(n);u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(n,t,`utf-8`)}function je(e){let t=f.resolve(e);return u.existsSync(t)?u.readFileSync(t,`utf-8`):null}function Me(e,t=u){let n=f.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,t,n=[]){return Pe(e,t,n,!1)}async function Pe(t,n,a,o){let s=r(t),c=s?e(s):[],u=s?i(s):[],d=[];if(t.subCommands)for(let[e,n]of Object.entries(t.subCommands)){let r=await l(n,e=>o||!!t.requiredPackages?.length||!!e.requiredPackages?.length),i=[...a,e];d.push({name:e,description:r.description,aliases:r.aliases,fullPath:i})}return{name:t.name??``,description:t.description,aliases:t.aliases,fullCommandPath:a.length>0?`${n} ${a.join(` `)}`:n,commandPath:a.join(` `),depth:a.length+1,positionalArgs:c,options:u,subCommands:d,extracted:s,command:t,notes:t.notes,examples:t.examples}}async function Fe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t,a){a||=!!e.requiredPackages?.length;let o=await Pe(e,n,t,a),s=t.join(` `);if(r.set(s,o),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await l(r,e=>a||!!e.requiredPackages?.length),[...t,n],a)}return await i(e,[],!1),r}async function Ie(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Le(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Le(e,t,n){let r=Re(e.cmd),i=[...n,...r],a=s({passthrough:!1});a.start();let o=!0;try{let{runCommand:e}=await import(`./runner-CPph9QvL.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
|
+
`),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 Re(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function ze(e){let t=c();return Object.entries(e).map(([e,n])=>t.resolveFieldMeta(e,n))}function Be(e,t){let n=ze(e).filter(e=>!e.positional);return n.length===0?``:O(y(n),t?.columns)}function Ve(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function He(e){return e.replace(/\s+/g,`-`).toLowerCase()}function Ue(e){return e.subCommands.length===0}function We(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function Ge(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(Ue(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(Ue(a)||!n)&&r.push(e)}}return r}function Ke(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:Ge(e.commands,t,r),s=o,c=/* @__PURE__ */ new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>We(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!Ue(i))continue;let o=n||i.name,s=He(o),l=Ve(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
|
|
24
24
|
`)}async function qe(e,t,n){let r=n?.headingLevel??3,i=n?.leafOnly??!0,a=await Fe(e),o=[];for(let e of t){let t=Ke(e,a,r,i);o.push(t)}return o.join(`
|
|
25
25
|
|
|
26
26
|
`)}async function q(e,t){if(!t)return e;let n=await t(e);return!e.endsWith(`
|
|
@@ -67,7 +67,7 @@ import{c as e,n as t,o as n,r,s as i,t as a,y as o}from"./schema-extractor-BI5yp
|
|
|
67
67
|
`:`
|
|
68
68
|
`}function Dt(e){return(e.match(/\n/g)??[]).length}function Ot(e){return M.some(t=>t===e)}function kt(e){switch(Math.min(6,Math.max(1,Math.trunc(e)))){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 5:return 5;default:return 6}}function At(e,t){if(e.length===0)return t===void 0||t.has(``)?``:null;let n=e.join(`:`);if(t?.has(n))return n;let r=e.join(` `);return t?.has(r)||t===void 0?r:null}function jt(e){return e.join(` `)}function Mt(e,t){let n=e.slice(2,-2).split(`:`),r=n[1];if(r===`command`){let r=n.slice(2);if(r.length===1&&r[0]===``)return{kind:`invalid`,reason:`Trailing colon in "${e}"; use {{politty:command}} for the root command.`};let i=At(r,t);if(i!==null)return{kind:`command`,scope:i,type:void 0};if(r.length>=2){let e=r[r.length-1],n=r.slice(0,-1),i=At(n,t);if(e!==void 0&&Ot(e))return{kind:`command`,scope:i??jt(n),type:e};if(e!==void 0&&i!==null)return{kind:`invalid`,reason:`Unknown section type "${e}" for command scope "${Z(i)}". Valid section types: ${M.join(`, `)}`}}return{kind:`command`,scope:jt(r),type:void 0}}return r===`global-options`?n.length===2?{kind:`global-options`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:global-options}}.`}:r===`index`?n.length===2?{kind:`index`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:index}}.`}:{kind:`invalid`,reason:`Unknown politty directive "${r??``}" in "${e}". Valid directives: command, global-options, index`}}function Nt(e,t){let n=it(e);for(let r of e){let e=Mt(`{{politty:${r}}}`,t);if(e.kind===`command`){if(e.type===void 0)n.commandScopes.add(e.scope);else{let t=n.commandSections.get(e.scope);t||(t=/* @__PURE__ */ new Set,n.commandSections.set(e.scope,t)),t.add(e.type)}}else e.kind===`global-options`?n.globalOptions=!0:e.kind===`index`&&(n.index=!0)}return n}function Pt(e,t){for(let n of t)if(J(e,n))return!0;return!1}function Ft(e,t,n){return Pt(e,n.commandScopes)?!0:n.commandSections.get(e)?.has(t)??!1}function It(e,t,n,r){return mt(ut(lt([e],t),n).filter(e=>!Pt(e,r.commandScopes)),[e])}function Lt(e,t,n){return n.rawKeys.has($e(e))?!0:t.kind===`command`?Pt(t.scope,n.commandScopes)?!0:t.type!==void 0&&(n.commandSections.get(t.scope)?.has(t.type)??!1):t.kind===`global-options`?n.globalOptions:t.kind===`index`&&n.index}function Rt(e,t){if(!e.startsWith(`command:`))return!1;let n=e.slice(8).split(`:`);for(let e of t.commandScopes){if(e===``)return!0;let t=e.split(` `);if(n.slice(0,t.length).join(` `)===e)return!0;let r=e.split(`:`);if(n.slice(0,r.length).join(`:`)===e)return!0}return!1}const zt=/\{\{politty:[^{}]*\}\}/g;function Bt(e,t){let n=/* @__PURE__ */ new Set;for(let r of e.matchAll(zt)){let i=r.index,a=i+r[0].length;if(e[i-1]===`{`||e[a]===`}`){let n=e.slice(Math.max(0,i-1),Math.min(e.length,a+1)).split(`
|
|
69
69
|
`)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}n.add(i)}let r=0;for(;;){let i=e.indexOf(`{{politty:`,r);if(i===-1)return;if(!n.has(i)){let n=e.slice(i,i+80).split(`
|
|
70
|
-
`)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Vt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${Z(r)}". Valid section types: ${M.join(`, `)}`}function Ht(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ut(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Wt(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Gt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Wt(e.args)}function Kt(e){let t=
|
|
70
|
+
`)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Vt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${Z(r)}". Valid section types: ${M.join(`, `)}`}function Ht(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ut(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Wt(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Gt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Wt(e.args)}function Kt(e){let t=c();return Object.entries(e).map(([e,n])=>t.resolveFieldMeta(e,n)).filter(e=>!e.positional)}function qt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return p(r,a)}function Jt(e){if(e)return Gt(e)?e:{args:e}}function Yt(e){if(!e)return;let n=t(e).fields.filter(e=>!e.positional);if(n.length!==0)return Object.fromEntries(n.map(e=>[e.name,e.schema]))}function Xt(e){let t=/* @__PURE__ */ new Map;if(!e?.globalOptions)return t;let n=Jt(e.globalOptions);if(!n)return t;for(let e of Kt(n.args))t.set(e.name,e);return t}function Zt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=X(o,n,r);if(e.length===0)continue;let c=`./`+f.relative(f.dirname(t),a).replace(/\\/g,`/`),l=e[0],u=l===void 0?void 0:n.get(l),d=Array.isArray(o)?void 0:o;i.push({title:d?.title??u?.name??f.basename(a,f.extname(a)),description:d?.description??u?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Qt(e,t,n,r){let i=$(t),a=[];for(let[t,o]of e.entries()){if($(t)===i)continue;let e=o.headingScopes;if(e.length===0)continue;let s=`./`+f.relative(f.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??f.basename(t,f.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function $t(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of Object.values(e)){let{commandPaths:e}=X(i,t,n);for(let t of e)r.add(t)}return r}function en(e,t,n,r){let i=/* @__PURE__ */ new Set;for(let a of Object.keys(t)){let o=pn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function tn(e,t){return t.some(t=>J(e,t))}function nn(e,t){return e.referencedScopes.some(e=>tn(e,t))}function rn(e,t){return e.emitsIndex||e.emitsGlobalOptions||nn(e,t)}function an(e,t,n){if(n.size===0)return;let r=[];for(let i of e){let e=t.get(i);if(e)for(let t of e.options){let e=n.get(t.name);e&&(qt(e,t)||r.push(`Command "${Z(i)}" option "--${t.cliName}" does not match globalOptions definition for "${t.name}".`))}}if(r.length>0)throw Error(`Invalid globalOptions configuration:\n - ${r.join(`
|
|
71
71
|
- `)}`)}function on(e){return[`<a id="global-options"></a>`,Be(e.args,e.options)].join(`
|
|
72
72
|
`)}function sn(e){return[L(),on(e),te()].join(`
|
|
73
73
|
`)}async function cn(e,t,n,r){let i=V(n),a=oe(n);return[i,await qe(t,e,r),a].join(`
|
|
@@ -91,4 +91,4 @@ import{c as e,n as t,o as n,r,s as i,t as a,y as o}from"./schema-extractor-BI5yp
|
|
|
91
91
|
|
|
92
92
|
`):void 0})}return{success:!B,files:z,error:B?`Documentation is out of date. ${y?`Run with ${j}=true ${A}=true to fix missing markers.`:`Run with ${A}=true to update.`}`:void 0}}async function Sn(e){let t=await xn(e);if(!t.success){let e=t.files.filter(e=>e.status===`diff`).map(e=>{let t=`File: ${e.path}\n`;return e.diff&&(t+=e.diff),t}).join(`
|
|
93
93
|
|
|
94
|
-
`);throw Error(`Documentation does not match golden files.\n\n${e}\n\n`+(t.error??`Run with POLITTY_DOCS_UPDATE=true to update the documentation.`))}}function Cn(e,t){if(Je(`POLITTY_DOCS_UPDATE`)){if(typeof e==`string`)Me(e,t);else{let n=new Set(Object.values(e.templates??{}).map($));e.rootDoc&&n.add($(e.rootDoc.path));let r=e=>n.has($(e));if(e.files)for(let n of Object.keys(e.files))r(n)||Me(n,t);if(e.templates)for(let n of Object.keys(e.templates))r(n)||Me(n,t)}}}export{j as DOCTOR_ENV,I as GLOBAL_OPTIONS_MARKER_PREFIX,B as INDEX_MARKER_PREFIX,z as ROOT_FOOTER_MARKER_PREFIX,R as ROOT_HEADER_MARKER_PREFIX,N as SECTION_MARKER_PREFIX,M as SECTION_TYPES,A as UPDATE_GOLDEN_ENV,Sn as assertDocMatch,Ne as buildCommandInfo,Fe as collectAllCommands,Ae as compareWithExisting,W as createCommandRenderer,ke as defaultRenderers,Ie as executeExamples,G as formatDiff,xn as generateDoc,te as globalOptionsEndMarker,L as globalOptionsStartMarker,oe as indexEndMarker,V as indexStartMarker,Cn as initDocFile,Be as renderArgsTable,de as renderArgumentsList,we as renderArgumentsListFromArray,le as renderArgumentsTable,Ce as renderArgumentsTableFromArray,qe as renderCommandIndex,Ee as renderExamplesDefault,_e as renderOptionsList,U as renderOptionsListFromArray,ge as renderOptionsTable,H as renderOptionsTableFromArray,be as renderSubcommandsTable,Te as renderSubcommandsTableFromArray,ce as renderUsage,
|
|
94
|
+
`);throw Error(`Documentation does not match golden files.\n\n${e}\n\n`+(t.error??`Run with POLITTY_DOCS_UPDATE=true to update the documentation.`))}}function Cn(e,t){if(Je(`POLITTY_DOCS_UPDATE`)){if(typeof e==`string`)Me(e,t);else{let n=new Set(Object.values(e.templates??{}).map($));e.rootDoc&&n.add($(e.rootDoc.path));let r=e=>n.has($(e));if(e.files)for(let n of Object.keys(e.files))r(n)||Me(n,t);if(e.templates)for(let n of Object.keys(e.templates))r(n)||Me(n,t)}}}export{j as DOCTOR_ENV,I as GLOBAL_OPTIONS_MARKER_PREFIX,B as INDEX_MARKER_PREFIX,z as ROOT_FOOTER_MARKER_PREFIX,R as ROOT_HEADER_MARKER_PREFIX,N as SECTION_MARKER_PREFIX,M as SECTION_TYPES,A as UPDATE_GOLDEN_ENV,Sn as assertDocMatch,Ne as buildCommandInfo,Fe as collectAllCommands,Ae as compareWithExisting,W as createCommandRenderer,ke as defaultRenderers,Ie as executeExamples,G as formatDiff,xn as generateDoc,te as globalOptionsEndMarker,L as globalOptionsStartMarker,oe as indexEndMarker,V as indexStartMarker,Cn as initDocFile,Be as renderArgsTable,de as renderArgumentsList,we as renderArgumentsListFromArray,le as renderArgumentsTable,Ce as renderArgumentsTableFromArray,qe as renderCommandIndex,Ee as renderExamplesDefault,_e as renderOptionsList,U as renderOptionsListFromArray,ge as renderOptionsTable,H as renderOptionsTableFromArray,be as renderSubcommandsTable,Te as renderSubcommandsTableFromArray,ce as renderUsage,l as resolveLazyCommand,ae as rootFooterEndMarker,ie as rootFooterStartMarker,re as rootHeaderEndMarker,ne as rootHeaderStartMarker,F as sectionEndMarker,P as sectionStartMarker,K as writeFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as createDynamicCompleteCommand}from"./dynamic-iwEE4Vdk.js";
|