@politty/zod 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/{arg-registry-DdEs3jd0.d.ts → arg-registry-Dvi0co21.d.ts} +9 -2
- package/dist/argv-parser-DZQ0qnXG.js +1 -0
- package/dist/augment.d.ts +4 -2
- package/dist/cli-main-BX5IVgNq.js +1 -0
- package/dist/{cli-main-q4kY1qaL.js → cli-main-uRzr666k.js} +2 -2
- package/dist/cli-run-DtG5fM18.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/completion-8frPuaX8.js +1 -0
- package/dist/completion-OvSe3W9y.js +116 -0
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +47 -47
- package/dist/dynamic-4uRohypH.js +6 -0
- package/dist/dynamic-C5e2NuDv.js +1 -0
- package/dist/{field-meta-D7G8a7IG.js → field-meta-_l-FHbh7.js} +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/{register-D0mDOOyc.js → register-BXOytPt7.js} +1 -1
- package/dist/runner-BTD1-gUd.js +30 -0
- package/dist/runner-BTF0HIGj.js +1 -0
- package/dist/{schema-ohwvrBGz.js → schema-DhMPssIJ.js} +1 -1
- package/dist/{schema-extractor-QpSHJvwI.js → schema-extractor-Du9ipDD4.js} +1 -1
- package/dist/skill.d.ts +3 -3
- package/dist/skill.js +2 -2
- package/dist/{with-completion-command-Bi7v_Wlq.d.ts → with-completion-command-BKHwbzEc.d.ts} +1 -1
- package/dist/{with-completion-command-CZ9qcezN.js → with-completion-command-CQcqFHq8.js} +2 -2
- package/package.json +4 -4
- package/dist/cli-main-DXoFbgu3.js +0 -1
- package/dist/cli-run-HJaZHDXb.js +0 -1
- package/dist/completion-CDwNvtfE.js +0 -1
- package/dist/completion-DwBjO-3Q.js +0 -116
- package/dist/dynamic-BBr42fJH.js +0 -1
- package/dist/dynamic-BK6Tq_FR.js +0 -6
- package/dist/runner-FI1rpYp3.js +0 -1
- package/dist/runner-bjKUtqk1.js +0 -29
package/README.md
CHANGED
|
@@ -138,19 +138,21 @@ $ my-cli World -g "Hi" -l
|
|
|
138
138
|
HI, WORLD!
|
|
139
139
|
|
|
140
140
|
$ my-cli --help
|
|
141
|
-
|
|
141
|
+
greet
|
|
142
142
|
|
|
143
143
|
A CLI tool that displays greetings
|
|
144
144
|
|
|
145
|
+
Usage: greet [options] <name>
|
|
146
|
+
|
|
145
147
|
Arguments:
|
|
146
|
-
name
|
|
148
|
+
<name> Name of the person to greet
|
|
147
149
|
|
|
148
150
|
Options:
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
|
|
152
|
-
-
|
|
153
|
-
|
|
151
|
+
-h, --help Show help
|
|
152
|
+
-H, --help-all Show help with all subcommand options
|
|
153
|
+
--help-json Show help as JSON
|
|
154
|
+
-g, --greeting <GREETING> Greeting phrase (default: "Hello")
|
|
155
|
+
-l, --loud Output in uppercase (default: false)
|
|
154
156
|
```
|
|
155
157
|
|
|
156
158
|
Every command also accepts `--help-json`, which prints the same information as a single JSON object instead of formatted text — useful for tools that consume a CLI's help programmatically (e.g. generating docs or another UI) rather than parsing `--help`'s output:
|
|
@@ -68,6 +68,8 @@ interface ResolvedFieldMeta {
|
|
|
68
68
|
description?: string | undefined;
|
|
69
69
|
/** Whether this is a positional argument */
|
|
70
70
|
positional: boolean;
|
|
71
|
+
/** Whether this is accepted as a long option (`--cli-name`) */
|
|
72
|
+
named: boolean;
|
|
71
73
|
/** Placeholder for help display */
|
|
72
74
|
placeholder?: string | undefined;
|
|
73
75
|
/**
|
|
@@ -833,8 +835,13 @@ type EffectContext = {
|
|
|
833
835
|
interface BaseArgMeta<TValue = unknown> {
|
|
834
836
|
/** Argument description */
|
|
835
837
|
description?: string;
|
|
836
|
-
/**
|
|
837
|
-
|
|
838
|
+
/**
|
|
839
|
+
* Treat as positional argument. Pass `{ named: true }` to also accept it as
|
|
840
|
+
* a long option (`--name <value>`), e.g. for values that may start with `-`.
|
|
841
|
+
*/
|
|
842
|
+
positional?: boolean | {
|
|
843
|
+
named?: boolean;
|
|
844
|
+
};
|
|
838
845
|
/** Placeholder for help display */
|
|
839
846
|
placeholder?: string;
|
|
840
847
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,n as t}from"./field-meta-_l-FHbh7.js";const n=new Set([`1`,`t`,`T`,`TRUE`,`true`,`True`]),r=new Set([`0`,`f`,`F`,`FALSE`,`false`,`False`]);function i(e){return n.has(e)?!0:!r.has(e)&&e}function a(e,t){return t===`boolean`?i(e):e}function o(e){let t=e.indexOf(`=`);return t>=0?e.slice(2,t):e.slice(2)}function s(e,t){let n=o(e);if(!e.includes(`=`)){let e=t.negationMap.get(n);if(e&&t.booleanFlags.has(e))return{resolvedName:e,withoutDashes:n,isNegated:!0,isCustomNegation:!0,isSuppressedNegation:!1}}let r=e.includes(`=`);if(!r&&n.startsWith(`no-`)){let e=n.slice(3);if(e===e.toLowerCase()){let r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}}if(!r&&n.length>2&&n.startsWith(`no`)&&/[A-Z]/.test(n[2])){let e=n[2].toLowerCase()+n.slice(3),r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}return{resolvedName:t.aliasMap.get(n)??n,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!1}}const c=/^-\.?\d/;function l(e){return c.test(e)}function u(e,t={}){let{aliasMap:n=new Map,booleanFlags:r=new Set,arrayFlags:a=new Set,definedNames:o=new Set,negationMap:c=new Map,defaultNegationDisabledFields:u}=t,d={aliasMap:n,booleanFlags:r,definedNames:o,negationMap:c,defaultNegationDisabledFields:u??new Set(r)},f={options:{},positionals:[],rest:[]},p=0,m=!1,h=(e,t)=>{let r=n.get(e)??e;if(a.has(r)){let e=f.options[r];Array.isArray(e)?e.push(t):e===void 0?f.options[r]=[t]:f.options[r]=[e,t]}else f.options[r]=t};for(;p<e.length;){let t=e[p];if(m){f.rest.push(t),p++;continue}if(t===`--`){m=!0,p++;continue}if(t.startsWith(`--`)){let a=t.slice(2),o=s(t,d);if(o.isSuppressedNegation){h(o.withoutDashes,!0),p++;continue}if(o.isNegated){h(o.resolvedName,!1),p++;continue}let c=a.indexOf(`=`);if(c!==-1){let e=a.slice(0,c),t=a.slice(c+1),o=n.get(e)??e;h(e,r.has(o)?i(t):t),p++}else{let t=a,i=n.get(t)??t;if(r.has(i))h(t,!0),p++;else{let n=e[p+1];n!==void 0&&(!n.startsWith(`-`)||l(n))?(h(t,n),p+=2):(h(t,!0),p++)}}continue}if(t.startsWith(`-`)&&t.length>1&&!t.startsWith(`--`)){let a=t.slice(1),o=a.indexOf(`=`);if(o!==-1){let e=a.slice(0,o),t=a.slice(o+1),s=n.get(e)??e;h(e,r.has(s)?i(t):t),p++}else if(a.length===1){let t=a,i=n.get(t)??t;if(r.has(i))h(t,!0),p++;else{let n=e[p+1];n!==void 0&&(!n.startsWith(`-`)||l(n))?(h(t,n),p+=2):(h(t,!0),p++)}}else{for(let e of a)h(e,!0);p++}continue}f.positionals.push(t),p++}return f}function d(n){let r=new Map,i=new Set,a=new Set,o=new Set,s=new Map,c=new Set;for(let e of n.fields)o.add(e.name);for(let l of n.fields){if(!l.named)continue;l.cliName!==l.name&&r.set(l.cliName,l.name);for(let n of t(l))if(r.set(n,l.name),n.length>1&&n.includes(`-`)){let t=e(n);t!==n&&!o.has(t)&&!r.has(t)&&r.set(t,l.name)}let n=e(l.name);if(n!==l.name&&!o.has(n)&&!r.has(n)&&r.set(n,l.name),l.type===`boolean`&&i.add(l.name),l.type===`array`&&a.add(l.name),l.type===`boolean`&&l.negation!==!0&&(c.add(l.name),typeof l.negation==`string`&&(s.set(l.negation,l.name),l.negation.includes(`-`)))){let t=e(l.negation);t!==l.negation&&s.set(t,l.name)}}return{aliasMap:r,booleanFlags:i,arrayFlags:a,definedNames:o,negationMap:s,defaultNegationDisabledFields:c}}function f(e,t){return e.fields.filter(e=>e.positional&&!(e.named&&Object.hasOwn(t,e.name)))}function p(e,t){let n={...e.options},r=t.fields.filter(e=>e.positional),i=e.rest.length>0?[...e.positionals,...e.rest]:e.positionals;for(let e of r)e.named||delete n[e.name];let a=0;for(let r of f(t,e.options)){if(a>=i.length)break;if(r.type===`array`){n[r.name]=i.slice(a);break}n[r.name]=i[a],a++}return n}export{o as a,f as i,p as n,s as o,u as r,a as s,d as t};
|
package/dist/augment.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ArgMeta } from "./arg-registry-
|
|
1
|
+
import { n as ArgMeta } from "./arg-registry-Dvi0co21.js";
|
|
2
2
|
//#region src/augment.d.ts
|
|
3
3
|
declare module "zod" {
|
|
4
4
|
interface ZodTypeDef {
|
|
@@ -6,7 +6,9 @@ declare module "zod" {
|
|
|
6
6
|
}
|
|
7
7
|
interface GlobalMeta {
|
|
8
8
|
description?: string;
|
|
9
|
-
positional?: boolean
|
|
9
|
+
positional?: boolean | {
|
|
10
|
+
named?: boolean;
|
|
11
|
+
};
|
|
10
12
|
placeholder?: string;
|
|
11
13
|
alias?: string | string[] | readonly string[];
|
|
12
14
|
hiddenAlias?: string | string[] | readonly string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./cli-main-uRzr666k.js";export{e as runPolittyCli};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
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=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{d as e,u as t}from"./schema-extractor-Du9ipDD4.js";import{n}from"./command-tLHaJHe6.js";import{n as r}from"./runner-BTD1-gUd.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=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-8frPuaX8.js`);await t({bin:e.bin,programName:e.program,shell:e.shell,...e.out!==void 0&&{outputPath:e.out},verify:e.verify})}}),A=t({entry:e.optionalStringArray({description:`Module specifier the shim imports, relative to the shim file; repeatable, one per bin/--out (defaults to ./cli.js, ./cli.mjs, ./index.js, or ./index.mjs next to each shim)`,placeholder:`SPECIFIER`}),out:e.optionalStringArray({description:`Output path for the generated shim; repeatable, one per --entry (defaults to the bin paths in package.json)`,placeholder:`PATH`}),program:e.optionalString({description:`Program name for the cache directory, applied to all shims (defaults per shim to its bin name)`,placeholder:`NAME`}),compileCacheSpecifier:e.optionalString({description:`Module specifier the shim imports enableCompileCache from (defaults to the compile-cache subpath of the politty package running this command)`,placeholder:`SPECIFIER`})});function j(e){let t=T(e),i=n({name:`generate-shim`,description:`Generate a compile-cache bin shim that loads the real CLI via dynamic import`,args:A,run(e){let n=process.cwd(),r=t({...e.entry!==void 0&&{entry:e.entry},...e.out!==void 0&&{out:e.out},...e.program!==void 0&&{program:e.program},...e.compileCacheSpecifier!==void 0&&{compileCacheSpecifier:e.compileCacheSpecifier},cwd:n});for(let e of r)console.log(`Generated compile-cache shim: ${D(e.outputPath,n)} (program: ${e.program}, entry: ${e.entry}, compile-cache: ${e.compileCacheSpecifier})`)}}),a=n({name:`politty`,description:`politty development utilities`,subCommands:{"generate-shim":i,"generate-worker":k}});return r(a).catch(e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)})}export{T as n,j as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./register-BXOytPt7.js";const{runPolittyCli:e}=await import(`./cli-main-BX5IVgNq.js`);await e(`@politty/zod`);export{};
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as e}from"./compile-cache-6u9hgeWu.js";e(`politty`),await import(`./cli-run-
|
|
2
|
+
import{n as e}from"./compile-cache-6u9hgeWu.js";e(`politty`),await import(`./cli-run-DtG5fM18.js`);export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./with-completion-command-CQcqFHq8.js";import"./dynamic-4uRohypH.js";import{c as e,n as t,r as n,t as r}from"./completion-OvSe3W9y.js";export{r as createCompletionCommand,t as createCompletionWorkerPathCommand,n as createRefreshCompletionCommand,e as generateBundledCompletionWorker};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import{a as e,c as t,n}from"./schema-extractor-Du9ipDD4.js";import{n as r}from"./command-tLHaJHe6.js";import{c as i}from"./subcommand-router-D8GTMXYL.js";import{a,i as o,n as s,o as c,r as l,s as u}from"./with-completion-command-CQcqFHq8.js";import{_ as d,c as f,d as p,f as m,g as h,h as g,i as _,l as v,m as y,p as b,s as ee,t as te,u as ne,v as x,y as S}from"./dynamic-4uRohypH.js";import{existsSync as C,mkdirSync as re,readFileSync as w,realpathSync as T,renameSync as ie,rmSync as ae,statSync as E,writeFileSync as oe}from"node:fs";import{dirname as D,extname as se,isAbsolute as O,join as k,relative as ce,resolve as le}from"node:path";import{promisify as ue}from"node:util";import{execFile as de}from"node:child_process";function fe(e,t,n=[],r=!1){if(t.length===0)return;let i=pe(e,n);for(let e of t)e.set(me(e,i,r))}function pe(e,t){let n=new Map,r=new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function me(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ge(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=he(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function he(e){let t=[],n=new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ge(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function _e(e,t,n,r){let i=ee(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function A(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function j(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function M(e,t,n){return`__${e}_expand_${t}__${A(n)}`}function ve(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${j(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function N(e){return e.filter(e=>!e.name.startsWith(`__`))}function P(e){let t=[];for(let n of N(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function ye(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return _e(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function be(e){return e.args?t(n(e.args)):[]}function xe(e,t){return e.filter(e=>e.named).map(e=>ye(e,t))}function Se(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return _e(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ce(r,a,o=[],s=!1){let c=[];if(a.subCommands)for(let[e,t]of Object.entries(a.subCommands)){let n=i(t);n?c.push(Ce(e,n,o,s)):c.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let l=[],u=a.args?n(a.args):void 0,d={name:r,description:a.description,aliases:a.aliases,subcommands:c,options:xe(u?e(u):[],l),positionals:Se(u?t(u):[],l)};return fe(d,l,o,s),d}function F(e,t,n){return e?`${e}${n}${t}`:t}function we(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>F(e,t,`:`)))}function Te(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function I(e,t){let n=[],r=N(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?v(i.cliName,i.alias):R(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of N(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...I(r,F(t,e,`:`)));return n}function Ee(e,t){return I(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function L(e,t=``,n=``){let r=[];for(let i of N(e.subcommands)){let e=F(n,A(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=F(t,n,`:`);r.push(...L(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function De(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Oe(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function ke(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${A(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ae(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function je(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function Me(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=A(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function R(e,t){let n=v(e.cliName,e.alias);if(e.isGlobal===!0){let e=new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of p(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ne(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function z(e){let t=[];return Ne(e,[],[``],[],`root`,t),t}function Ne(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?R(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of N(e.subcommands))Ne(o,[...t,o.name],we(n,o),[...r,...n],i===`root`?A(o.name):`${i}_${A(o.name)}`,a)}function B(e,t,n=[]){let r=Pe(e),i=new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of p(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=v(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:R(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function V(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(V(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function H(e,t,r,i=!1){let a=[];if(r){let e=[];a=xe(n(r).fields,e).map(e=>(e.isGlobal=!0,e)),fe({name:t,subcommands:[],options:a,positionals:[]},e,[],i)}let o=Ce(t,e,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:t,globalOptions:a}}function U(e){try{return Math.floor(E(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=k(n,e);try{if(E(t).isFile())return t}catch{}}return null}function W(e,t){return t||process.env[j(A(e))]||(Le(e)??process.argv[1]??``)}function G(e){let t=W(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${U(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=W(t,n),o=U(a),s=x(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=`_${t}`,o=W(t,n),s=U(o),c=x(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=M(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=A(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${A(r.fieldName)}:-}`:`\${_used_field_keys_${A(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function K(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...b(o,e,t)});if(s.length===0)continue;let c=R(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function q(e,t,n,r=[]){if(e.length===0)return[];let i=g(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of He(o.valueCompletion,!1,t,{funcSuffix:n,...y(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...q(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _avail+=(--help --help-all --help-json)`),n.push(` fi`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(A).join(`_`),a=`__${t}_complete_${i}`,o=N(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...q(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=P(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...q(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=[];d.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),d.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&d.push(`# politty-completion-worker: true`),d.push(`# Generated by politty`),d.push(``),o||d.push(...Re({programName:n,binPath:t.binPath}));let p=l.length>0,m=l.filter(e=>e.isArrayOption),g=m.length>0;p&&(d.push(`__${a}_enc() {`),d.push(` local LC_ALL=C`),d.push(` local _s=$1 _r='' _c _i`),d.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),d.push(" _c=${_s:_i:1}"),d.push(` case "$_c" in`),d.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),d.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),d.push(` esac`),d.push(` done`),d.push(` printf '%s' "$_r"`),d.push(`}`),d.push(``));for(let e of l){let t=M(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
2
|
+
`);d.push(`${t}__${e}=${f(r)}`)}d.push(``)}V(s)&&(d.push(...ve(a,n)),d.push(``),d.push(`__${a}_apply_dynamic_output() {`),d.push(` local _raw="$1"`),d.push(` COMPREPLY=()`),d.push(` local _directive=0`),d.push(` local -a _lines=()`),d.push(` local _line`),d.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),d.push(" local _last=$((${#_lines[@]} - 1))"),d.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),d.push(' _directive="${_lines[$_last]#:}"'),d.push(` unset '_lines[_last]'`),d.push(` fi`),d.push(' for _line in "${_lines[@]}"; do'),d.push(` [[ -z "$_line" ]] && continue`),d.push(` COMPREPLY+=("$_line")`),d.push(` done`),d.push(' local _ip="${_inline_prefix:-}"'),d.push(` if (( _directive & ${_.DirectoryCompletion} )); then`),d.push(` compopt +o default 2>/dev/null`),d.push(` compopt -o filenames 2>/dev/null`),d.push(` local _d`),d.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),d.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),d.push(` elif (( _directive & ${_.FileCompletion} )); then`),d.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),d.push(` compopt -o filenames 2>/dev/null`),d.push(` local _f`),d.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),d.push(` else`),d.push(` compopt -o default 2>/dev/null`),d.push(` fi`),d.push(` else`),d.push(` if (( _directive & ${_.NoFileCompletion} )); then`),d.push(` compopt +o default 2>/dev/null`),d.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),d.push(` fi`),d.push(` fi`),d.push(` if (( _directive & ${_.NoSpace} )); then`),d.push(` compopt -o nospace 2>/dev/null`),d.push(` fi`),d.push(`}`),d.push(``)),d.push(`__${a}_not_used() {`),d.push(' for _u in "${_used_opts[@]}"; do'),d.push(` for _chk in "$@"; do`),d.push(` [[ "$_u" == "$_chk" ]] && return 1`),d.push(` done`),d.push(` done`),d.push(` return 0`),d.push(`}`),d.push(``),d.push(`__${a}_opt_takes_value() {`),d.push(` case "$1:$2" in`),d.push(...Ee(s,``)),d.push(` esac`),d.push(` return 1`),d.push(`}`),d.push(``),p&&(d.push(`__${a}_track_opt() {`),d.push(` case "$1:$2" in`),d.push(...Ae(u,`bash`)),d.push(` esac`),d.push(`}`),d.push(``),d.push(`__${a}_track_pos() {`),d.push(` case "$1:$2" in`),d.push(...je(u,`bash`)),d.push(` esac`),d.push(`}`),d.push(``),d.push(...h(a,Te(s)))),g&&(d.push(`__${a}_track_array_expand() {`),d.push(` case "$1:$2" in`),d.push(...Me(m,`bash`)),d.push(` esac`),d.push(`}`),d.push(``));let v=L(s);v.length>0&&(d.push(`__${a}_is_subcmd() {`),d.push(` case "$1:$2" in`),d.push(...De(v)),d.push(` esac`),d.push(` return 1`),d.push(`}`),d.push(``));for(let e of c)d.push(...Je(e,a,[]));if(d.push(`__${a}_complete_root() {`),d.push(...Ke(s.options,s.positionals,a,`root`)),d.push(` if [[ -z "$_inline_prefix" ]] && __${a}_opt_takes_value "" "$_prev"; then return; fi`),d.push(` if [[ -n "$_inline_prefix" ]] && __${a}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),s.positionals.length>0?(d.push(` if (( _after_dd )); then`),d.push(...q(s.positionals,a,`root`,s.options).map(e=>` ${e}`)),d.push(` return`),d.push(` fi`)):d.push(` if (( _after_dd )); then return; fi`),d.push(` if [[ "$_cur" == -* ]]; then`),d.push(` local -a _avail=()`),d.push(...qe(s.options,a)),d.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),d.push(` compopt +o default 2>/dev/null`),c.length>0){d.push(` else`);let e=P(s.subcommands).map(e=>e.name).join(` `);d.push(...Ge(e,s.positionals,a,`root`,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(d.push(` else`),d.push(...q(s.positionals,a,`root`,s.options).map(e=>` ${e}`)));d.push(` fi`),d.push(`}`),d.push(``);let y=Oe(v,a).join(`
|
|
3
|
+
`);d.push(`_${a}_completions() {`),d.push(` COMPREPLY=()`),d.push(``),d.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),d.push(` local -a _words=()`),d.push(` local _i=1`),d.push(` while (( _i <= COMP_CWORD )); do`),d.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),d.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),d.push(` (( _i += 2 ))`),d.push(` else`),d.push(' _words+=("${COMP_WORDS[_i]}")'),d.push(` (( _i++ ))`),d.push(` fi`),d.push(` done`),d.push(``),d.push(` local _cur=""`),d.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),d.push(` local _inline_prefix=""`),d.push(``),d.push(` local _prev=""`),d.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),d.push(``),d.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),d.push(` local -a _used_opts=()`),p&&d.push(` local -a _pos_words=()`),d.push(` local _any_opt_used=0`),p&&(d.push(` ${K(`_arg_values_`)}`),d.push(` ${K(`_global_arg_values_`)}`)),g&&(d.push(` ${K(`_used_field_keys_`)}`),d.push(` ${K(`_global_used_field_keys_`)}`),d.push(` ${K(`_global_arr_seen_`)}`)),d.push(``),d.push(` local _j=0`),d.push(" while (( _j < ${#_words[@]} - 1 )); do"),d.push(' local _w="${_words[_j]}"'),d.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),d.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=p?`_pos_words+=("$_w"); `:``;d.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),d.push(` if [[ "$_w" == -*=* ]]; then`),d.push(' _used_opts+=("${_w%%=*}")'),d.push(` _any_opt_used=1`),p&&(d.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),g&&d.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),d.push(` (( _j++ )); continue`),d.push(` fi`),d.push(` if [[ "$_w" == -* ]]; then`),d.push(` _used_opts+=("$_w")`),d.push(` _any_opt_used=1`),d.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),d.push(' local _next="${_words[_j+1]:-}"'),d.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),p&&(d.push(` if (( _skip_next )); then`),d.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),g&&(d.push(" if (( _j + 2 < ${#_words[@]} )); then"),d.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),d.push(` fi`)),d.push(` fi`)),d.push(` fi`),d.push(` (( _j++ )); continue`),d.push(` fi`);let ee=g?`; ${K(`_arg_values_`)}; ${K(`_used_field_keys_`)}; ${K(`_global_arr_seen_`)}`:p?`; ${K(`_arg_values_`)}`:``,te=p?`_pos_words+=("$_w"); `:``;return v.length>0?d.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${p?`; _pos_words=()`:``}${ee}; else ${te}(( _pos_count++ )); fi`):(p&&d.push(` _pos_words+=("$_w")`),d.push(` (( _pos_count++ ))`)),d.push(` (( _j++ ))`),d.push(` done`),p&&d.push(` __${a}_track_positionals`),d.push(``),d.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),d.push(' _inline_prefix="${_cur%%=*}="'),d.push(' _cur="${_cur#*=}"'),d.push(` fi`),d.push(``),d.push(` case "$_subcmd" in`),d.push(y),d.push(` *) __${a}_complete_root ;;`),d.push(` esac`),d.push(`}`),d.push(``),o||d.push(`complete -o default -F _${a}_completions ${n}`),d.push(``),{script:d.join(`
|
|
4
|
+
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
5
|
+
eval "$(${n} completion bash --static)"
|
|
6
|
+
|
|
7
|
+
# For faster shell startup, save the script instead:
|
|
8
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
9
|
+
${n} completion bash --static > ~/.local/share/bash-completion/completions/${n}
|
|
10
|
+
|
|
11
|
+
# Then reload your shell or run:
|
|
12
|
+
source ~/.bashrc`}}const Xe=ue(de),Ze={bash:`bash`,zsh:`zsh`,fish:`fish`},Qe=[`# politty-completion-version: 1`,`# politty-completion-mode: worker`,`# politty-completion-worker: true`];function $e(e){return Ze[e]}function et(e){return k(`dist`,`completion`,`${e}-worker.${$e(e)}`)}function tt(e){let t=Ze[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 nt(e,t,n){if(n?.disabled)return[];let r=n?.relativePaths?.[t];return(r&&r.length>0?r:tt(t)).map(n=>n.replaceAll(`{shell}`,t).replaceAll(`{ext}`,Ze[t]).replaceAll(`{program}`,e))}function rt(e){try{let t=w(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 J(e,t){if(!t)return;e.add(D(le(t)));try{e.add(D(T(t)))}catch{}let n=rt(t);n&&J(e,n)}function it(e){return w(e,`utf8`).split(`
|
|
14
|
+
`,24).join(`
|
|
15
|
+
`)}function at(e,t){return[...Qe,`# program: ${e}`,`# shell: ${t}`]}function ot(e,t,n){let r=e.split(`
|
|
16
|
+
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function st(e,t,n){if(!C(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function ct(e,t,n){try{return st(e,t,n),!0}catch{return!1}}function lt(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n=new Set;e.binPath!==void 0&&J(n,e.binPath),process.argv[1]&&J(n,process.argv[1]),J(n,W(e.programName,e.binPath));for(let n of t)if(O(n)&&ct(n,e.programName,e.shell))return n;for(let r of n)for(let n of t){if(O(n))continue;let t=k(r,n);if(ct(t,e.programName,e.shell))return t}return null}function ut(e,t){return O(e)?e:le(t,e)}function dt(e,t,n){let r=e.startsWith(`.`)||e.includes(`/`)||e.includes(`\\`)?ut(e,n):e,i=se(r).toLowerCase();return i===`.js`||i===`.mjs`||i===`.cjs`?{command:process.execPath,args:[r,...t]}:{command:r,args:[...t]}}async function ft(e,t,n){let r=dt(e,t,n.cwd);try{let{stdout:e,stderr:t}=await Xe(r.command,r.args,{cwd:n.cwd,env:{...process.env,...n.env},encoding:`utf8`,maxBuffer:10485760});return{stdout:e,stderr:t}}catch(e){let t=typeof e==`object`&&e&&`stderr`in e?String(e.stderr??``).trim():``,n=t?`\n${t}`:``;throw Error(`Command failed: ${r.command} ${r.args.join(` `)}${n}`,e instanceof Error?{cause:e}:void 0)}}function pt(e){let t=E(e);if(!t.isFile()||t.size===0)throw Error(`Generated bundled completion worker is empty: ${e}`);return t.size}function mt(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KiB`}function ht(e,t,n){let r=ce(n,e);console.log(`Generated bundled completion worker: ${r&&!r.startsWith(`..`)?r:e} (${mt(t)})`)}async function gt(e){let t=e.cwd??process.cwd(),n=ut(e.outputPath??et(e.shell),t);re(D(n),{recursive:!0}),ae(n,{force:!0}),await ft(e.bin,[`__refresh-completion`,e.shell,n,`--static`,`--worker`],{cwd:t,env:e.env});let r=pt(n);st(n,e.programName,e.shell);let i;if(e.verify){let r=(await ft(e.bin,[`__completion-worker-path`,e.shell],{cwd:t,env:e.env})).stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);if(r.length!==1)throw Error(`Expected __completion-worker-path ${e.shell} to print exactly one path, got ${r.length}.`);i=ut(r[0],t);let a=T(n),o=T(i);if(o!==a)throw Error(`Bundled completion worker path mismatch: generated ${a}, reported ${o}`)}return e.quiet||ht(n,r,t),{outputPath:n,size:r,...i!==void 0&&{reportedPath:i}}}function _t(e){return x(`/${e}/node-compile-cache`)}function vt(e){return e?x(`${e}/node-compile-cache`):void 0}function yt(e,t){return e?x(`${e}/completion-worker.${t}`):void 0}function bt(e,t){return x(`/${e}/completion-worker.${t}`)}function Y(e,t,n){return t?` ${e} ${t}`:` ${e} "\${XDG_CACHE_HOME:-$HOME/.cache}"${n}`}function xt(e,t){return e?` printf '%s\\n' ${e}`:[` set -l _cache_root "$XDG_CACHE_HOME"`,` test -n "$_cache_root"; or set _cache_root "$HOME/.cache"`,` printf '%s\\n' "$_cache_root"${t}`].join(`
|
|
17
|
+
`)}function St(e,t){return nt(e.programName,t,e.bundledWorker).map(x).join(` `)}function Ct(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}"`}function wt(e){return nt(e.programName,`fish`,e.bundledWorker).map(Ct).join(` `)}function Tt(e){return e.bundledWorker?.queryCommand===!0&&!e.bundledWorker.disabled}function Et(e,t){let{programName:n}=t,r=A(n),i=`${r}_worker`,a=j(i),o=j(r),s=x(n),c=Y(`printf '%s\\n'`,vt(t.cacheDir),_t(n)),l=Y(`printf '%s\\n'`,yt(t.cacheDir,`bash`),bt(n,`bash`)),u=St(t,`bash`),d=Tt(t),f=[];return f.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),f.push(`# Generated by politty`),f.push(`# politty-completion-mode: dispatcher`),f.push(``),f.push(`__${r}_resolve_bin() {`),f.push(` if [[ -n "\${${o}:-}" ]]; then`),f.push(` printf '%s\\n' "\${${o}}"`),f.push(` return 0`),f.push(` fi`),f.push(` type -P ${s} 2>/dev/null`),f.push(`}`),f.push(``),f.push(`__${r}_node_compile_cache_dir() {`),f.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),f.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),f.push(` return 0`),f.push(` fi`),f.push(c),f.push(`}`),f.push(``),f.push(`__${r}_static_worker_path() {`),f.push(l),f.push(`}`),f.push(``),f.push(`__${r}_worker_file_sig() {`),f.push(` local _worker="$1" _sig`),f.push(` _sig=${S(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),f.push(` printf '%s\\n' "$_sig"`),f.push(`}`),f.push(``),f.push(`__${r}_is_worker_file() {`),f.push(` local _worker="$1" _head`),f.push(` [[ -f "$_worker" ]] || return 1`),f.push(` _head="$(head -n 24 "$_worker" 2>/dev/null)" || return 1`),f.push(` _head=$'\\n'"$_head"$'\\n'`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# shell: bash"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),f.push(`}`),f.push(``),f.push(`__${r}_load_worker() {`),f.push(` local _worker="$1" _sig _key`),f.push(` __${r}_is_worker_file "$_worker" || return 1`),f.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),f.push(` _key="$_worker:$_sig"`),f.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),f.push(` source "$_worker" 2>/dev/null || return 1`),f.push(` __${r}_loaded_worker_key="$_key"`),f.push(` fi`),f.push(` declare -F _${i}_completions >/dev/null 2>&1`),f.push(`}`),f.push(``),f.push(`__${r}_realpath() {`),f.push(` local _path="$1" _dir _target _limit=0`),f.push(` while [[ -L "$_path" && $_limit -lt 40 ]]; do`),f.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),f.push(` _target="$(readlink "$_path")" || return 1`),f.push(` if [[ "$_target" == /* ]]; then _path="$_target"; else _path="$_dir/$_target"; fi`),f.push(` (( _limit++ ))`),f.push(` done`),f.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),f.push(` printf '%s\\n' "$_dir/$(basename "$_path")"`),f.push(`}`),f.push(``),f.push(`__${r}_worker_from_dir() {`),f.push(` local _dir="$1" _rel _candidate`),u.length>0&&(f.push(` for _rel in ${u}; do`),f.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),f.push(` if __${r}_is_worker_file "$_candidate"; then`),f.push(` printf '%s\\n' "$_candidate"`),f.push(` return 0`),f.push(` fi`),f.push(` done`)),f.push(` return 1`),f.push(`}`),f.push(``),f.push(`__${r}_cmd_shim_target() {`),f.push(` sed -n 's/^# cmd-shim-target=//p' "$1" 2>/dev/null | tail -n 1`),f.push(`}`),f.push(``),f.push(`__${r}_bundled_worker_path() {`),f.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),f.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),f.push(` if [[ -n "$_real" ]]; then`),f.push(` _dir="$(dirname "$_real")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` fi`),f.push(` _dir="$(dirname "$_bin")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),f.push(` if [[ -n "$_target" ]]; then`),f.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),f.push(` _dir="$(dirname "$_real")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` fi`),d&&(f.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),f.push(` printf '%s\\n' "\${__${r}_queried_worker}"`),f.push(` return 0`),f.push(` fi`),f.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path bash 2>/dev/null)" || _reported=""`),f.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),f.push(` __${r}_queried_bin="$_bin"`),f.push(` __${r}_queried_worker="$_reported"`),f.push(` printf '%s\\n' "$_reported"`),f.push(` return 0`),f.push(` fi`)),f.push(` return 1`),f.push(`}`),f.push(``),f.push(`__${r}_bin_sig() {`),f.push(` local _bin="$1" _sig`),f.push(` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`),f.push(` printf '%s\\n' "$_sig"`),f.push(`}`),f.push(``),f.push(`__${r}_worker_matches_bin() {`),f.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),f.push(` [[ -f "$_worker" ]] || return 1`),f.push(` _head="$(head -n 12 "$_worker" 2>/dev/null)" || return 1`),f.push(` grep -qxF "# politty-bin-sig: $_sig" <<< "$_head" || return 1`),f.push(` grep -qxF "# politty-bin-path: $_bin" <<< "$_head" || return 1`),f.push(`}`),f.push(``),f.push(`__${r}_apply_dynamic_output() {`),f.push(` local _raw="$1" _cur="$2" _inline_prefix="$3"`),f.push(` COMPREPLY=()`),f.push(` local _directive=0`),f.push(` local -a _lines=() _exts=() _matchers=()`),f.push(` local _line`),f.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),f.push(" local _last=$((${#_lines[@]} - 1))"),f.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" == :[0-9]* ]]; then'),f.push(` local -a _meta=()`),f.push(` IFS=$'\\t' read -r -a _meta <<< "\${_lines[$_last]}"`),f.push(` unset '_lines[_last]'`),f.push(' _directive="${_meta[0]#:}"'),f.push(` local _m`),f.push(' for _m in "${_meta[@]:1}"; do'),f.push(` if [[ "$_m" == @ext:* ]]; then`),f.push(` IFS=',' read -r -a _exts <<< "\${_m#@ext:}"`),f.push(` elif [[ "$_m" == @matcher:* ]]; then`),f.push(` IFS=',' read -r -a _matchers <<< "\${_m#@matcher:}"`),f.push(` fi`),f.push(` done`),f.push(` fi`),f.push(' for _line in "${_lines[@]}"; do'),f.push(` [[ -z "$_line" ]] && continue`),f.push(` COMPREPLY+=("$_line")`),f.push(` done`),f.push(' local _ip="${_inline_prefix:-}"'),f.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _f _ext _pat _base _ok`),f.push(` while IFS= read -r _f; do`),f.push(` if [[ -d "$_f" ]]; then`),f.push(' COMPREPLY+=("${_ip}${_f}")'),f.push(` continue`),f.push(` fi`),f.push(` _ok=0`),f.push(" if (( ${#_exts[@]} > 0 )); then"),f.push(' for _ext in "${_exts[@]}"; do'),f.push(` [[ -n "$_ext" && "$_f" == *."$_ext" ]] && _ok=1`),f.push(` done`),f.push(` fi`),f.push(" if (( ${#_matchers[@]} > 0 )); then"),f.push(' _base="${_f##*/}"'),f.push(' for _pat in "${_matchers[@]}"; do'),f.push(` [[ -n "$_pat" && "$_base" == $_pat ]] && _ok=1`),f.push(` done`),f.push(` fi`),f.push(' (( _ok )) && COMPREPLY+=("${_ip}${_f}")'),f.push(` done < <(compgen -f -- "$_cur")`),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${_.DirectoryCompletion} )); then`),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _d`),f.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${_.FileCompletion} )); then`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _p`),f.push(' while IFS= read -r _p; do COMPREPLY+=("${_ip}${_p}"); done < <(compgen -f -- "$_cur")'),f.push(` elif (( _directive & ${_.NoFileCompletion} )); then`),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` fi`),f.push(` if (( _directive & ${_.NoSpace} )); then`),f.push(` compopt -o nospace 2>/dev/null`),f.push(` fi`),f.push(`}`),f.push(``),f.push(`_${r}_completions() {`),f.push(` COMPREPLY=()`),f.push(` local -a _words=()`),f.push(` local _i=1`),f.push(` while (( _i <= COMP_CWORD )); do`),f.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),f.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),f.push(` (( _i += 2 ))`),f.push(` else`),f.push(' _words+=("${COMP_WORDS[_i]}")'),f.push(` (( _i++ ))`),f.push(` fi`),f.push(` done`),f.push(` local _cur="" _inline_prefix=""`),f.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),f.push(` local _after_dd=0 _di=0`),f.push(" while (( _di < ${#_words[@]} - 1 )); do"),f.push(' [[ "${_words[_di]}" == "--" ]] && { _after_dd=1; break; }'),f.push(` (( _di++ ))`),f.push(` done`),f.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),f.push(' _inline_prefix="${_cur%%=*}="'),f.push(' _cur="${_cur#*=}"'),f.push(` fi`),f.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),f.push(` _bin="$(__${r}_resolve_bin)" || _bin=""`),f.push(` [[ -n "$_bin" ]] || return 0`),f.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)" || _node_compile_cache=""`),f.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")" || _bundled_worker=""`),f.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),f.push(` return 0`),f.push(` fi`),f.push(` _worker="$(__${r}_static_worker_path)" || _worker=""`),f.push(` _sig="$(__${r}_bin_sig "$_bin")" || _sig=""`),f.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),f.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),f.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion bash "$_worker" --static --worker 2>/dev/null`),f.push(` fi`),f.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),f.push(` return 0`),f.push(` fi`),f.push(` fi`),f.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell bash -- "${_words[@]}" 2>/dev/null) || return 0'),f.push(` __${r}_apply_dynamic_output "$_out" "$_cur" "$_inline_prefix"`),f.push(`}`),f.push(``),f.push(`complete -o default -F _${r}_completions ${n}`),f.push(``),{script:f.join(`
|
|
18
|
+
`),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=A(n),i=`${r}_worker`,a=j(i),o=j(r),s=x(n),c=`_${n}`,l=`"\${funcstack[1]:-}" == "${c}"`,u=Y(`print -r --`,vt(t.cacheDir),_t(n)),d=Y(`print -r --`,yt(t.cacheDir,`zsh`),bt(n,`zsh`)),f=St(t,`zsh`),p=Tt(t),m=[];return m.push(`#compdef ${n}`),m.push(...G({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# Generated by politty`),m.push(`# politty-completion-mode: dispatcher`),m.push(``),m.push(`__${r}_resolve_bin() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` if [[ -n "\${${o}:-}" ]]; then`),m.push(` print -r -- "\${${o}}"`),m.push(` return 0`),m.push(` fi`),m.push(` whence -p ${s} 2>/dev/null`),m.push(`}`),m.push(``),m.push(`__${r}_node_compile_cache_dir() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),m.push(` print -r -- "$NODE_COMPILE_CACHE"`),m.push(` return 0`),m.push(` fi`),m.push(u),m.push(`}`),m.push(``),m.push(`__${r}_static_worker_path() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(d),m.push(`}`),m.push(``),m.push(`__${r}_worker_file_sig() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _worker="$1" _sig`),m.push(` _sig=${S(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),m.push(` print -r -- "$_sig"`),m.push(`}`),m.push(``),m.push(`__${r}_is_worker_file() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _worker="$1" _head`),m.push(` [[ -f "$_worker" ]] || return 1`),m.push(` _head="$(<$_worker)" || return 1`),m.push(` _head=$'\\n'"$_head"$'\\n'`),m.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),m.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),m.push(` [[ "$_head" == *$'\\n'"# shell: zsh"$'\\n'* ]] || return 1`),m.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),m.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),m.push(`}`),m.push(``),m.push(`__${r}_load_worker() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _worker="$1" _sig _key`),m.push(` __${r}_is_worker_file "$_worker" || return 1`),m.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),m.push(` _key="$_worker:$_sig"`),m.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),m.push(` source "$_worker" 2>/dev/null || return 1`),m.push(` typeset -g __${r}_loaded_worker_key="$_key"`),m.push(` fi`),m.push(` (( $+functions[_${i}_completions] ))`),m.push(`}`),m.push(``),m.push(`__${r}_realpath() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _path="$1"`),m.push(` [[ -n "$_path" ]] || return 1`),m.push(' print -r -- "${_path:A}"'),m.push(`}`),m.push(``),m.push(`__${r}_worker_from_dir() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _dir="$1" _rel _candidate`),f.length>0&&(m.push(` for _rel in ${f}; do`),m.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),m.push(` if __${r}_is_worker_file "$_candidate"; then`),m.push(` print -r -- "$_candidate"`),m.push(` return 0`),m.push(` fi`),m.push(` done`)),m.push(` return 1`),m.push(`}`),m.push(``),m.push(`__${r}_cmd_shim_target() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` [[ -f "$1" ]] || return 0`),m.push(` local _l _t=""`),m.push(' for _l in "${(@f)$(<$1)}"; do'),m.push(' [[ "$_l" == "# cmd-shim-target="* ]] && _t="${_l#\\# cmd-shim-target=}"'),m.push(` done`),m.push(` [[ -n "$_t" ]] && print -r -- "$_t"`),m.push(`}`),m.push(``),m.push(`__${r}_bundled_worker_path() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),m.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),m.push(` if [[ -n "$_real" ]]; then`),m.push(' _dir="${_real:h}"'),m.push(` __${r}_worker_from_dir "$_dir" && return 0`),m.push(` fi`),m.push(' _dir="${_bin:h}"'),m.push(` __${r}_worker_from_dir "$_dir" && return 0`),m.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),m.push(` if [[ -n "$_target" ]]; then`),m.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),m.push(' _dir="${_real:h}"'),m.push(` __${r}_worker_from_dir "$_dir" && return 0`),m.push(` fi`),p&&(m.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),m.push(` print -r -- "\${__${r}_queried_worker}"`),m.push(` return 0`),m.push(` fi`),m.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path zsh 2>/dev/null)" || _reported=""`),m.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),m.push(` typeset -g __${r}_queried_bin="$_bin"`),m.push(` typeset -g __${r}_queried_worker="$_reported"`),m.push(` print -r -- "$_reported"`),m.push(` return 0`),m.push(` fi`)),m.push(` return 1`),m.push(`}`),m.push(``),m.push(`__${r}_bin_sig() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _bin="$1" _sig`),m.push(` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`),m.push(` print -r -- "$_sig"`),m.push(`}`),m.push(``),m.push(`__${r}_worker_matches_bin() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),m.push(` [[ -f "$_worker" ]] || return 1`),m.push(` _head=$'\\n'"$(<$_worker)"$'\\n'`),m.push(` [[ "$_head" == *$'\\n'"# politty-bin-sig: $_sig"$'\\n'* ]] || return 1`),m.push(` [[ "$_head" == *$'\\n'"# politty-bin-path: $_bin"$'\\n'* ]] || return 1`),m.push(`}`),m.push(``),m.push(`__${r}_cdescribe() {`),m.push(` _describe "$@" 2>/dev/null && return 0`),m.push(` shift`),m.push(` local _cd_arr="$1"`),m.push(` shift`),m.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),m.push(` compadd "$@" -a _cd_vals 2>/dev/null`),m.push(` return 0`),m.push(`}`),m.push(``),m.push(`__${r}_add_path_candidate() {`),m.push(` compadd -f -- "$1" 2>/dev/null && return 0`),m.push(` print -r -- "$1"`),m.push(`}`),m.push(``),m.push(`__${r}_apply_dynamic_output() {`),m.push(` local _raw="$1"`),m.push(` local _directive=0`),m.push(` local -a _vals _lines _exts _matchers`),m.push(` local _meta`),m.push(' _lines=("${(@f)_raw}")'),m.push(` local _last=$#_lines`),m.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<->* ]]; then'),m.push(' local _dline="${_lines[$_last]}"'),m.push(` _lines[$_last]=()`),m.push(` local -a _dfields`),m.push(' _dfields=("${(@ps:\\t:)_dline}")'),m.push(' _directive="${_dfields[1]#:}"'),m.push(` local _m`),m.push(' for _m in "${(@)_dfields[2,-1]}"; do'),m.push(` if [[ "$_m" == @ext:* ]]; then`),m.push(' _meta="${_m#@ext:}"'),m.push(' _exts=("${(@s:,:)_meta}")'),m.push(` elif [[ "$_m" == @matcher:* ]]; then`),m.push(' _meta="${_m#@matcher:}"'),m.push(' _matchers=("${(@s:,:)_meta}")'),m.push(` fi`),m.push(` done`),m.push(` fi`),m.push(` local _l`),m.push(' for _l in "${_lines[@]}"; do'),m.push(` [[ -z "$_l" ]] && continue`),m.push(` _vals+=("$_l")`),m.push(` done`),m.push(" if (( ${#_vals[@]} > 0 )); then"),m.push(` if (( _directive & ${_.NoSpace} )); then`),m.push(` __${r}_cdescribe 'completions' _vals -S ''`),m.push(` else`),m.push(` __${r}_cdescribe 'completions' _vals`),m.push(` fi`),m.push(` fi`),m.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),m.push(` setopt local_options null_glob`),m.push(' local _cur="${words[CURRENT]:-}" _dir _prefix _f _out _ext _pat'),m.push(` if [[ -z "$_cur" || "$_cur" != */* ]]; then`),m.push(` _dir="."`),m.push(` _prefix="$_cur"`),m.push(` elif [[ "$_cur" == */ ]]; then`),m.push(' _dir="${_cur%/}"'),m.push(` _prefix=""`),m.push(` else`),m.push(' _dir="${_cur%/*}"'),m.push(' _prefix="${_cur##*/}"'),m.push(` fi`),m.push(` for _f in "$_dir"/"$_prefix"*(N/); do`),m.push(' _out="${_f#./}"'),m.push(` __${r}_add_path_candidate "$_out"`),m.push(` done`),m.push(` for _f in "$_dir"/"$_prefix"*(N.); do`),m.push(' _out="${_f#./}"'),m.push(' for _ext in "${_exts[@]}"; do'),m.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${r}_add_path_candidate "$_out"; break; }`),m.push(` done`),m.push(` done`),m.push(' for _pat in "${_matchers[@]}"; do'),m.push(` [[ -n "$_pat" ]] || continue`),m.push(' for _f in "$_dir"/${~_pat}(N.); do'),m.push(' _out="${_f#./}"'),m.push(` [[ "$_out" == "$_cur"* ]] && __${r}_add_path_candidate "$_out"`),m.push(` done`),m.push(` done`),m.push(` elif (( _directive & ${_.DirectoryCompletion} )); then`),m.push(` _files -/`),m.push(` elif (( _directive & ${_.FileCompletion} )); then`),m.push(` _files`),m.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${_.NoFileCompletion} )); then`),m.push(` _files`),m.push(` fi`),m.push(`}`),m.push(``),m.push(`${c}() {`),m.push(` emulate -L zsh`),m.push(` setopt local_options no_aliases`),m.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),m.push(` _bin="$(__${r}_resolve_bin)"`),m.push(` [[ -n "$_bin" ]] || return 1`),m.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)"`),m.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")"`),m.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),m.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),m.push(` return 0`),m.push(` fi`),m.push(` _worker="$(__${r}_static_worker_path)"`),m.push(` _sig="$(__${r}_bin_sig "$_bin")"`),m.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),m.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),m.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),m.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion zsh "$_worker" --static --worker 2>/dev/null`),m.push(` fi`),m.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),m.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),m.push(` return 0`),m.push(` fi`),m.push(` fi`),m.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell zsh -- "${(@)words[2,CURRENT]}" 2>/dev/null) || return 1'),m.push(` __${r}_apply_dynamic_output "$_out"`),m.push(`}`),m.push(``),m.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),m.push(``),m.push(`if [[ ${l} ]]; then`),m.push(` ${c} "$@"`),m.push(`else`),m.push(` compdef ${c} ${n}`),m.push(`fi`),m.push(``),{script:m.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=A(n),i=`${r}_worker`,a=j(i),o=j(r),s=x(n),c=xt(vt(t.cacheDir),_t(n)),l=xt(yt(t.cacheDir,`fish`),bt(n,`fish`)),u=wt(t),d=Tt(t),f=[];return f.push(...G({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),f.push(`# Generated by politty`),f.push(`# politty-completion-mode: dispatcher`),f.push(``),f.push(`function __${r}_resolve_bin`),f.push(` if set -q ${o}; and test -n "$${o}"`),f.push(` printf '%s\\n' "$${o}"`),f.push(` return 0`),f.push(` end`),f.push(` set -l _bin (command -v ${s})`),f.push(` test -n "$_bin"; and test -x "$_bin"; and not test -d "$_bin"; and printf '%s\\n' "$_bin"`),f.push(`end`),f.push(``),f.push(`function __${r}_node_compile_cache_dir`),f.push(` if set -q NODE_COMPILE_CACHE; and test -n "$NODE_COMPILE_CACHE"`),f.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),f.push(` return 0`),f.push(` end`),f.push(c),f.push(`end`),f.push(``),f.push(`function __${r}_static_worker_path`),f.push(l),f.push(`end`),f.push(``),f.push(`function __${r}_worker_file_sig`),f.push(` set -l _worker $argv[1]`),f.push(` set -l _sig ${S(`$_worker`,{shell:`fish`,withSize:!0})}`),f.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),f.push(`end`),f.push(``),f.push(`function __${r}_is_worker_file`),f.push(` set -l _worker $argv[1]`),f.push(` test -f "$_worker"; or return 1`),f.push(` set -l _head (head -n 24 "$_worker" 2>/dev/null)`),f.push(` string match -q -- "# politty-completion-version: 1" $_head; or return 1`),f.push(` string match -q -- "# program: ${n}" $_head; or return 1`),f.push(` string match -q -- "# shell: fish" $_head; or return 1`),f.push(` string match -q -- "# politty-completion-mode: worker" $_head; or return 1`),f.push(` string match -q -- "# politty-completion-worker: true" $_head; or return 1`),f.push(`end`),f.push(``),f.push(`function __${r}_load_worker`),f.push(` set -l _worker $argv[1]`),f.push(` __${r}_is_worker_file "$_worker"; or return 1`),f.push(` set -l _sig (__${r}_worker_file_sig "$_worker")`),f.push(` test -n "$_sig"; or return 1`),f.push(` set -l _key "$_worker:$_sig"`),f.push(` if not set -q __${r}_loaded_worker_key; or test "$__${r}_loaded_worker_key" != "$_key"`),f.push(` source "$_worker" 2>/dev/null; or return 1`),f.push(` set -g __${r}_loaded_worker_key "$_key"`),f.push(` end`),f.push(` functions -q __fish_${i}_complete`),f.push(`end`),f.push(``),f.push(`function __${r}_realpath`),f.push(` set -l _path $argv[1]`),f.push(` set -l _old_pwd (pwd)`),f.push(` set -l _limit 0`),f.push(` while test -L "$_path"; and test $_limit -lt 40`),f.push(` set -l _dir (dirname "$_path")`),f.push(` if not cd "$_dir" 2>/dev/null`),f.push(` cd "$_old_pwd" 2>/dev/null`),f.push(` return 1`),f.push(` end`),f.push(` set -l _absdir (pwd -P)`),f.push(` cd "$_old_pwd" 2>/dev/null`),f.push(` test -n "$_absdir"; or return 1`),f.push(` set -l _target (readlink "$_path")`),f.push(` test -n "$_target"; or return 1`),f.push(` if string match -q '/*' -- "$_target"`),f.push(` set _path "$_target"`),f.push(` else`),f.push(` set _path "$_absdir/$_target"`),f.push(` end`),f.push(` set _limit (math $_limit + 1)`),f.push(` end`),f.push(` set -l _dir (dirname "$_path")`),f.push(` if not cd "$_dir" 2>/dev/null`),f.push(` cd "$_old_pwd" 2>/dev/null`),f.push(` return 1`),f.push(` end`),f.push(` set -l _absdir (pwd -P)`),f.push(` cd "$_old_pwd" 2>/dev/null`),f.push(` test -n "$_absdir"; or return 1`),f.push(` set -l _base (basename "$_path")`),f.push(` printf '%s\\n' "$_absdir/$_base"`),f.push(`end`),f.push(``),f.push(`function __${r}_worker_from_dir`),f.push(` set -l _dir $argv[1]`),u.length>0&&(f.push(` for _rel in ${u}`),f.push(` if string match -q '/*' -- "$_rel"`),f.push(` set _candidate "$_rel"`),f.push(` else`),f.push(` set _candidate "$_dir/$_rel"`),f.push(` end`),f.push(` if __${r}_is_worker_file "$_candidate"`),f.push(` printf '%s\\n' "$_candidate"`),f.push(` return 0`),f.push(` end`),f.push(` end`)),f.push(` return 1`),f.push(`end`),f.push(``),f.push(`function __${r}_cmd_shim_target`),f.push(` sed -n 's/^# cmd-shim-target=//p' "$argv[1]" 2>/dev/null | tail -n 1`),f.push(`end`),f.push(``),f.push(`function __${r}_bundled_worker_path`),f.push(` set -l _bin $argv[1]`),f.push(` set -l _node_compile_cache $argv[2]`),f.push(` set -l _real (__${r}_realpath "$_bin" 2>/dev/null)`),f.push(` if test -n "$_real"`),f.push(` set -l _dir (dirname "$_real")`),f.push(` __${r}_worker_from_dir "$_dir"; and return 0`),f.push(` end`),f.push(` set -l _dir (dirname "$_bin")`),f.push(` __${r}_worker_from_dir "$_dir"; and return 0`),f.push(` set -l _target (__${r}_cmd_shim_target "$_bin")`),f.push(` if test -n "$_target"`),f.push(` set _real (__${r}_realpath "$_target" 2>/dev/null)`),f.push(` test -n "$_real"; or set _real "$_target"`),f.push(` set _dir (dirname "$_real")`),f.push(` __${r}_worker_from_dir "$_dir"; and return 0`),f.push(` end`),d&&(f.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"`),f.push(` printf '%s\\n' "$__${r}_queried_worker"`),f.push(` return 0`),f.push(` end`),f.push(` set -l _reported (env NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path fish 2>/dev/null)`),f.push(` if test -n "$_reported"; and __${r}_is_worker_file "$_reported"`),f.push(` set -g __${r}_queried_bin "$_bin"`),f.push(` set -g __${r}_queried_worker "$_reported"`),f.push(` printf '%s\\n' "$_reported"`),f.push(` return 0`),f.push(` end`)),f.push(` return 1`),f.push(`end`),f.push(``),f.push(`function __${r}_bin_sig`),f.push(` set -l _bin $argv[1]`),f.push(` set -l _sig ${S(`$_bin`,{shell:`fish`})}`),f.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),f.push(`end`),f.push(``),f.push(`function __${r}_worker_matches_bin`),f.push(` set -l _worker $argv[1]`),f.push(` set -l _sig $argv[2]`),f.push(` set -l _bin $argv[3]`),f.push(` test -f "$_worker"; or return 1`),f.push(` set -l _head (head -n 12 "$_worker" 2>/dev/null)`),f.push(` contains -- "# politty-bin-sig: $_sig" $_head; or return 1`),f.push(` contains -- "# politty-bin-path: $_bin" $_head; or return 1`),f.push(`end`),f.push(``),f.push(`function __${r}_apply_dynamic_output`),f.push(` set -l _cur $argv[1]`),f.push(` set -l _directive 0`),f.push(` set -l _emitted 0`),f.push(` set -l _exts`),f.push(` set -l _matchers`),f.push(` set -l _lines`),f.push(` while read -l _l`),f.push(` set -a _lines $_l`),f.push(` end`),f.push(` set -l _n (count $_lines)`),f.push(` if test $_n -ge 1; and string match -qr '^:[0-9]+' -- $_lines[$_n]`),f.push(` set -l _fields (string split \\t -- $_lines[$_n])`),f.push(` set -e _lines[$_n]`),f.push(` set _directive (string sub -s 2 -- $_fields[1])`),f.push(` for _f in $_fields[2..-1]`),f.push(` if string match -q '@ext:*' -- $_f`),f.push(` set _exts (string split , -- (string sub -s 6 -- $_f))`),f.push(` else if string match -q '@matcher:*' -- $_f`),f.push(` set _matchers (string split , -- (string sub -s 10 -- $_f))`),f.push(` end`),f.push(` end`),f.push(` end`),f.push(` for _l in $_lines`),f.push(` if test -n "$_l"`),f.push(` printf '%s\\n' $_l`),f.push(` set _emitted 1`),f.push(` end`),f.push(` end`),f.push(` if test (count $_exts) -gt 0; or test (count $_matchers) -gt 0`),f.push(` __fish_complete_directories "$_cur"`),f.push(` set -l _dir ""`),f.push(` if string match -q '*/*' "$_cur"`),f.push(` set _dir (string replace -r '[^/]*$' '' "$_cur")`),f.push(` end`),f.push(` for _f in "$_cur"*`),f.push(` test -f "$_f"; or continue`),f.push(` for _ext in $_exts`),f.push(` if string match -q -- "*.$_ext" "$_f"`),f.push(` printf '%s\\n' "$_f"`),f.push(` break`),f.push(` end`),f.push(` end`),f.push(` end`),f.push(` for _pat in $_matchers`),f.push(` for _f in "$_dir"$_pat`),f.push(` test -f "$_f"; and string match -q "$_cur*" "$_f"; and printf '%s\\n' "$_f"`),f.push(` end`),f.push(` end`),f.push(` else if test (math "bitand($_directive, ${_.DirectoryCompletion})") -ne 0`),f.push(` __fish_complete_directories "$_cur"`),f.push(` else if test (math "bitand($_directive, ${_.FileCompletion})") -ne 0`),f.push(` __fish_complete_path "$_cur"`),f.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${_.NoFileCompletion})") -eq 0`),f.push(` __fish_complete_path "$_cur"`),f.push(` end`),f.push(`end`),f.push(``),f.push(`function __fish_${r}_complete`),f.push(` set -l _bin (__${r}_resolve_bin)`),f.push(` test -n "$_bin"; or return 0`),f.push(` set -l _node_compile_cache (__${r}_node_compile_cache_dir)`),f.push(` set -l _bundled_worker (__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")`),f.push(` if test -n "$_bundled_worker"; and __${r}_load_worker "$_bundled_worker"`),f.push(` set -lx ${a} "$_bin"`),f.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),f.push(` __fish_${i}_complete`),f.push(` return 0`),f.push(` end`),f.push(` set -l _worker (__${r}_static_worker_path)`),f.push(` set -l _sig (__${r}_bin_sig "$_bin")`),f.push(` if test -n "$_worker"; and test -n "$_sig"`),f.push(` if not __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),f.push(` mkdir -p (dirname "$_worker") 2>/dev/null`),f.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" $_bin __refresh-completion fish "$_worker" --static --worker 2>/dev/null`),f.push(` end`),f.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),f.push(` if __${r}_load_worker "$_worker"`),f.push(` set -lx ${a} "$_bin"`),f.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),f.push(` __fish_${i}_complete`),f.push(` return 0`),f.push(` end`),f.push(` end`),f.push(` end`),f.push(` set -l _args (commandline -opc)`),f.push(` set -l _cur (commandline -ct)`),f.push(` if test (count $_args) -gt 0`),f.push(` set _args $_args[2..]`),f.push(` end`),f.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" $_bin __complete --shell fish -- $_args "$_cur" 2>/dev/null | __${r}_apply_dynamic_output "$_cur"`),f.push(`end`),f.push(``),f.push(`complete -e -c ${n}`),f.push(`complete -c ${n} -f -a '(__fish_${r}_complete)'`),f.push(``),{script:f.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(H(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return Et(e,t);case`zsh`:return Dt(e,t);case`fish`:return Ot(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function At(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function jt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=A(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=A(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${At(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Mt(e.matcher):e.extensions?.length?Nt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Mt(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Nt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Pt(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=jt(i.valueCompletion,n,b(i,e,t));if(a.length===0)continue;let o=R(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Ft(e,t,n,r=`$_pos_count`){let i=m(e,t);if(i.every(e=>e===void 0))return;let a=[` set _slot -1; set _left ${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?`; and __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`set _slot ${e.position}`:`if test $_left -eq 0; set _slot ${e.position}; else; set _left (math $_left - 1); end`;a.push(` if test $_slot -lt 0${o}; ${s}; end`)}),a}function Z(e,t,n=[]){if(e.length===0)return[];let r=Ft(e,n,t),i=r!==void 0,a=i?[` set -l _slot; set -l _left`,...r]:[];for(let r of e){let o=jt(r.valueCompletion,t,y(r,n,e));if(o.length!==0){i?a.push(` if test $_slot -eq ${r.position}`):r.variadic?a.push(` if test $_pos_count -ge ${r.position}`):a.push(` if test $_pos_count -eq ${r.position}`);for(let e of o)a.push(` ${e}`);a.push(` return`),a.push(` end`)}}return a}function It(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function Lt(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` if test $_any_opt_used -eq 0`),n.push(` echo "--help Show help"`),n.push(` echo "--help-all Show help with all subcommand options"`),n.push(` echo "--help-json Show help as JSON"`),n.push(` end`),n}function Rt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(A).join(`_`)}`,a=N(e.subcommands),o=[];for(let e of a)o.push(...Rt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Pt(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...Lt(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=P(e.subcommands);o.push(...It(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function zt(e,t){let n=[];for(let r of I(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Bt(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=l.length>0,f=l.filter(e=>e.isArrayOption),p=f.length>0,m=[];if(m.push(...G({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),!o){let e=W(n,t.binPath),r=U(e),o=j(i),s=`__${a}_refresh_completion`;m.push(`function ${s} --no-scope-shadowing`),m.push(` set -l _bin $${o}`),m.push(` test -z "$_bin"; and set _bin (command -v ${n})`),m.push(` test -z "$_bin"; and return 1`),m.push(` set -l _sig ${S(`$_bin`,{shell:`fish`})}`),m.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),m.push(` set -l _target (status current-filename)`),m.push(` test -n "$_target"; and test -f "$_target"; or return 1`),m.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),m.push(` and source "$_target" 2>/dev/null`),m.push(` and return 0`),m.push(` return 1`),m.push(`end`),m.push(`${s}`),m.push(`set -l _politty_refreshed $status`),m.push(`functions -e ${s}`),m.push(`test $_politty_refreshed -eq 0; and return`),m.push(``)}if(V(s)&&(m.push(`function __${a}_invoke_complete`),m.push(` set -l _shell $argv[1]`),m.push(` set -l _argv $argv[2..]`),m.push(` set -l _bin ${n}`),m.push(` if set -q ${j(a)}`),m.push(` set _bin $${j(a)}`),m.push(` end`),m.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),m.push(`end`),m.push(``),m.push(`function __${a}_apply_dynamic_output`),m.push(` set -l _cur $argv[1]`),m.push(` set -l _directive 0`),m.push(` set -l _emitted 0`),m.push(` set -l _prev ""`),m.push(` set -l _has_prev 0`),m.push(` while read -l _l`),m.push(` if test $_has_prev -eq 1`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` set _prev $_l`),m.push(` set _has_prev 1`),m.push(` end`),m.push(` if test $_has_prev -eq 1`),m.push(` if string match -qr '^:[0-9]+$' -- $_prev`),m.push(` set _directive (string sub -s 2 -- $_prev)`),m.push(` else`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` end`),m.push(` if test (math "bitand($_directive, ${_.DirectoryCompletion})") -ne 0`),m.push(` __fish_complete_directories "$_cur"`),m.push(` else if test (math "bitand($_directive, ${_.FileCompletion})") -ne 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${_.NoFileCompletion})") -eq 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` end`),m.push(`end`),m.push(``)),m.push(`function __${a}_not_used --no-scope-shadowing`),m.push(` for _chk in $argv`),m.push(` if contains -- "$_chk" $_used_opts`),m.push(` return 1`),m.push(` end`),m.push(` end`),m.push(` return 0`),m.push(`end`),m.push(``),m.push(`function __${a}_opt_takes_value`),m.push(` switch "$argv[1]:$argv[2]"`),m.push(...zt(s,``)),m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${A(e.fieldName)}`;m.push(`function __${a}_track_opt --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_pos --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_positionals --no-scope-shadowing`),m.push(` set -l _k 0`),m.push(` for _w in $_pos_words`),m.push(` set -l _slot $_k; set -l _left`),m.push(` switch "$_subcmd"`);for(let e of Te(s)){m.push(` case ${e.pathStrs.map(e=>`"${e}"`).join(` `)}`);for(let t of Ft(e.positionals,e.options,a,`$_k`)??[])m.push(` ${t}`)}m.push(` end`),m.push(` __${a}_track_pos "$_subcmd" "$_slot" "$_w"`),m.push(` set _k (math $_k + 1)`),m.push(` end`),m.push(`end`),m.push(``)}if(p){m.push(`function __${a}_track_array_expand --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of f){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=A(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;m.push(` case ${t}`),m.push(` if string match -q '*=*' -- "$argv[3]"`),m.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),m.push(` if test -n "$_k"`),e.isGlobal?(m.push(` if not set -q _global_arr_seen_${n}`),m.push(` set -g ${r}${n} "$_k"`),m.push(` set -g _global_arr_seen_${n} 1`),m.push(` else if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)):(m.push(` if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)),m.push(` end`),m.push(` end`)}m.push(` end`),m.push(`end`),m.push(``)}let h=L(s);if(h.length>0){m.push(`function __${a}_is_subcmd`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of h)m.push(` case "${e.lookupPattern}"`),m.push(` return 0`);m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``)}for(let e of c)m.push(...Rt(e,a,[]));if(m.push(`function __${a}_complete_root --no-scope-shadowing`),m.push(...Pt(s.options,s.positionals,a)),m.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(m.push(` if test $_after_dd -eq 1`),m.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),m.push(` return`),m.push(` end`)):m.push(` if test $_after_dd -eq 1; return; end`),m.push(` if string match -q -- '-*' "$_cur"`),m.push(...Lt(s.options,a)),c.length>0){m.push(` else`);let e=P(s.subcommands);m.push(...It(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(m.push(` else`),m.push(...Z(s.positionals,a,s.options)));if(m.push(` end`),m.push(`end`),m.push(``),m.push(`function __fish_${a}_complete`),m.push(` set -l _args (commandline -opc)`),m.push(` set -e _args[1]`),m.push(``),m.push(` set -l _ct (commandline -ct)`),m.push(` if test (count $_ct) -eq 0`),m.push(` set -a _args ""`),m.push(` else`),m.push(` set -a _args $_ct`),m.push(` end`),m.push(``),m.push(` set -l _cur ""`),m.push(` if test (count $_args) -gt 0`),m.push(` set _cur "$_args[-1]"`),m.push(` end`),m.push(``),m.push(` set -l _prev ""`),m.push(` if test (count $_args) -gt 1`),m.push(` set _prev "$_args[-2]"`),m.push(` end`),m.push(``),m.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),m.push(` set -l _used_opts`),d&&m.push(` set -l _pos_words`),m.push(` set -l _any_opt_used 0`),m.push(``),d)for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`),m.push(` set -e _global_arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`);m.push(` set -l _j 1`),m.push(` set -l _limit (math (count $_args) - 1)`),m.push(` while test $_j -le $_limit`),m.push(` set -l _w "$_args[$_j]"`),m.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),m.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let g=d?`set -a _pos_words "$_w"; `:``;if(m.push(` if test $_after_dd -eq 1; ${g}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),m.push(` if string match -q -- '-*=*' "$_w"`),m.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),m.push(` set -a _used_opts "$_opt"`),m.push(` set _any_opt_used 1`),d&&(m.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),m.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),p&&m.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),m.push(` if string match -q -- '-*' "$_w"`),m.push(` set -a _used_opts "$_w"`),m.push(` set _any_opt_used 1`),m.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),m.push(` set -l _next ""`),m.push(` set -l _next_idx (math $_j + 1)`),m.push(` if test $_next_idx -le (count $_args)`),m.push(` set _next "$_args[$_next_idx]"`),m.push(` end`),m.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),m.push(` set _skip_next 1`),d&&(m.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),p&&(m.push(` if test $_j -lt $_limit`),m.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` end`))),m.push(` end`),m.push(` end`),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),h.length>0){if(m.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),m.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),m.push(` set _used_opts; set _pos_count 0`),d){m.push(` set _pos_words`);for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`)}m.push(` else`),d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`),m.push(` end`)}else d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`);m.push(` set _j (math $_j + 1)`),m.push(` end`),d&&m.push(` __${a}_track_positionals`),m.push(``),m.push(` switch "$_subcmd"`);for(let e of h)m.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return m.push(` case '*'; __${a}_complete_root`),m.push(` end`),m.push(`end`),m.push(``),o||(m.push(`# Clear existing completions`),m.push(`complete -e -c ${n}`),m.push(``),m.push(`# Register completion`),m.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),m.push(``),{script:m.join(`
|
|
45
|
+
`),shell:`fish`,installInstructions:`# To enable auto-refreshing fish completions, run:
|
|
46
|
+
${n} completion fish --install --static`}}function Vt(e,t){re(D(e),{recursive:!0});let n=`${e}.tmp.${process.pid}`;oe(n,t),ie(n,e)}function Ht(e,t){return un(e.rootCommand,{shell:t,programName:e.programName,mode:e.completionMode??`dispatcher`,includeDescriptions:!0,...e.programVersion!==void 0&&{programVersion:e.programVersion},...e.binPath!==void 0&&{binPath:e.binPath},...e.cacheDir!==void 0&&{cacheDir:e.cacheDir},...e.globalArgsSchema!==void 0&&{globalArgsSchema:e.globalArgsSchema},...e.bundledWorker!==void 0&&{bundledWorker:e.bundledWorker},...e.staticWorker!==void 0&&{staticWorker:e.staticWorker}}).script}function Ut(e,t){let n=a(e.programName,t,e.cacheDir);return Vt(n,Ht(e,t)),n}function Wt(e){try{if(!C(e))return;let t=w(e,`utf8`).split(`
|
|
47
|
+
`,10).join(`
|
|
48
|
+
`).match(/^# politty-completion-mode: (dispatcher|static)$/m);return t?t[1]:void 0}catch{return}}function Gt(e){try{if(!C(e))return null;let t=w(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(!C(e))return!1;let r=w(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?C(e.targetPath)?T(e.targetPath):e.targetPath:a(e.programName,t,e.cacheDir);if(e.targetPath&&C(n)&&!Kt(n,e.programName,t)||e.targetPath&&!C(n)&&!e.allowTargetCreate)return;let r=W(e.programName,e.binPath);if(!r)return;let i;try{i=Math.floor(E(r).mtimeMs/1e3).toString()}catch{return}if(c(n)===i&&Gt(n)===r)return;let o=e.completionMode??Wt(n)??(C(n)?`static`:`dispatcher`);Vt(n,Ht({...e,completionMode:o},t))}catch{}}function Jt(e,t,n){return t?x(`${t}/completion.${n}`):`"\${XDG_CACHE_HOME:-$HOME/.cache}/${e}/completion.${n}"`}function Yt(e){let t=A(e.programName),n=j(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=A(e.programName),n=j(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=M(t,n.funcSuffix,n.fieldName),r=n.resolvedDeps.map(e=>e.isGlobal?`"\${_global_arg_values[${e.name}]:-}"`:`"\${_arg_values[${e.name}]:-}"`).join(`$'\\x1f'`),i=A(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,...b(a,e,t)});if(o.length===0)continue;let s=R(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=g(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);let s=nn(o.valueCompletion,t,{funcSuffix:n,...y(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,t){let n=[];for(let r of e){let i=r.description?`:${Q(r.description)}`:``;if(r.valueType===`array`){n.push(` _opts+=("--${r.cliName}${i}")`);continue}let a=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?`:${Q(r.negationDescription)}`:i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o} && _opts+=("--${e.name}${e.desc}")`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _opts+=("--help:Show help")`),n.push(` _opts+=("--help-all:Show help with all subcommand options")`),n.push(` _opts+=("--help-json:Show help as JSON")`),n.push(` fi`),n}function cn(e,t,n){let r=[...n,e.name],i=r.map(A).join(`_`),a=`__${t}_complete_${i}`,o=N(e.subcommands),s=[];for(let e of o)s.push(...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=P(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:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=o?`_${a}_completions`:`_${n}`,c=`"\${funcstack[1]:-}" == "${$t(s)}"`,l=r.command,u=N(l.subcommands),d=z(l),p=B(l,d,r.globalOptions),m=d.length>0,g=d.filter(e=>e.isArrayOption),v=g.length>0,y=[];o||(y.push(`#compdef ${n}`),y.push(``)),y.push(...G({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),y.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&y.push(`# politty-completion-worker: true`),y.push(`# Generated by politty`),y.push(``),o||y.push(...ze({programName:n,binPath:t.binPath}));for(let e of d){let t=M(a,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(``),n=t.candidates.map(e=>{let t=Qt(e.value);return e.description?`${t}:${e.description}`:t}).join(`
|
|
99
|
+
`);y.push(` ${f(e)} ${f(n)}`)}y.push(`)`)}y.push(``)}V(l)&&(y.push(...ve(a,n)),y.push(``),y.push(`__${a}_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 & ${_.NoSpace} )); then`),y.push(` __${a}_cdescribe 'completions' _vals -S ''`),y.push(` else`),y.push(` __${a}_cdescribe 'completions' _vals`),y.push(` fi`),y.push(` fi`),y.push(` if (( _directive & ${_.DirectoryCompletion} )); then`),y.push(` _files -/`),y.push(` elif (( _directive & ${_.FileCompletion} )); then`),y.push(` _files`),y.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${_.NoFileCompletion} )); then`),y.push(` _files`),y.push(` fi`),y.push(`}`),y.push(``)),y.push(`__${a}_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(`__${a}_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(`__${a}_add_path_candidate() {`),y.push(` compadd -f -- "$1" 2>/dev/null && return 0`),y.push(` print -r -- "$1"`),y.push(`}`),y.push(``),y.push(`__${a}_opt_takes_value() {`),y.push(` case "$1:$2" in`),y.push(...Ee(l,``)),y.push(` esac`),y.push(` return 1`),y.push(`}`),y.push(``),m&&(y.push(`__${a}_track_opt() {`),y.push(` case "$1:$2" in`),y.push(...Ae(p,`zsh`)),y.push(` esac`),y.push(`}`),y.push(``),y.push(`__${a}_track_pos() {`),y.push(` case "$1:$2" in`),y.push(...je(p,`zsh`)),y.push(` esac`),y.push(`}`),y.push(``),y.push(...h(a,Te(l)))),v&&(y.push(`__${a}_track_array_expand() {`),y.push(` case "$1:$2" in`),y.push(...Me(g,`zsh`)),y.push(` esac`),y.push(`}`),y.push(``));let b=L(l);b.length>0&&(y.push(`__${a}_is_subcmd() {`),y.push(` case "$1:$2" in`),y.push(...De(b)),y.push(` esac`),y.push(` return 1`),y.push(`}`),y.push(``));for(let e of u)y.push(...cn(e,a,[]));if(y.push(`__${a}_complete_root() {`),y.push(` local -a _vals=()`),y.push(...on(l.options,l.positionals,a,`root`)),y.push(` if __${a}_opt_takes_value "" "\${words[CURRENT-1]}"; then return 0; fi`),l.positionals.length>0?(y.push(` if (( _after_dd )); then`),y.push(...$(l.positionals,a,`root`,l.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(l.options,a)),y.push(` __${a}_cdescribe 'options' _opts`),u.length>0){y.push(` else`);let e=P(l.subcommands);y.push(...an(e,l.positionals,a,`root`,l.options).map(e=>` ${e}`))}else l.positionals.length>0&&(y.push(` else`),y.push(...$(l.positionals,a,`root`,l.options).map(e=>` ${e}`)));y.push(` fi`),y.push(`}`),y.push(``);let ee=Oe(b,a).join(`
|
|
100
|
+
`);y.push(`${s}() {`),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=()`),m&&y.push(` local -a _pos_words=()`),y.push(` local _any_opt_used=0`),m&&(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 te=m?`_pos_words+=("$_w"); `:``;y.push(` if (( _after_dd )); then ${te}(( _pos_count++ )); (( _j++ )); continue; fi`),y.push(` if [[ "$_w" == -*=* ]]; then`),y.push(' _used_opts+=("${_w%%=*}")'),y.push(` _any_opt_used=1`),m&&(y.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),v&&y.push(` __${a}_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 __${a}_opt_takes_value "$_subcmd" "$_w"; then`),y.push(' local _next="${words[_j+1]:-}"'),y.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),m&&(y.push(` if (( _skip_next )); then`),y.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),v&&(y.push(` if (( _j + 1 < CURRENT )); then`),y.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),y.push(` fi`)),y.push(` fi`)),y.push(` fi`),y.push(` (( _j++ )); continue`),y.push(` fi`);let ne=v?`; _arg_values=(); _used_field_keys=(); _global_arr_seen=()`:m?`; _arg_values=()`:``,x=m?`_pos_words+=("$_w"); `:``;return b.length>0?y.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${m?`; _pos_words=()`:``}${ne}; else ${x}(( _pos_count++ )); fi`):(m&&y.push(` _pos_words+=("$_w")`),y.push(` (( _pos_count++ ))`)),y.push(` (( _j++ ))`),y.push(` done`),m&&y.push(` __${a}_track_positionals`),y.push(``),y.push(` case "$_subcmd" in`),y.push(ee),y.push(` *) __${a}_complete_root ;;`),y.push(` esac`),y.push(`}`),y.push(``),y.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),y.push(``),o||(y.push(`if [[ ${c} ]]; then`),y.push(` ${s} "$@"`),y.push(`else`),y.push(` compdef ${s} ${n}`),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 "$(${n} completion zsh --static)"
|
|
103
|
+
|
|
104
|
+
# For faster shell startup, save the script in your fpath:
|
|
105
|
+
mkdir -p ~/.zsh/completions
|
|
106
|
+
${n} completion zsh --static > ~/.zsh/completions/_${n}
|
|
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 Ye(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 ${x(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(e,t,n,i={}){let a=t??e.name,{cacheDir:o,programVersion:c}=i,l={...o!==void 0&&{cacheDir:o},...c!==void 0&&{programVersion:c},...n!==void 0&&{globalArgsSchema:n},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker}},d={programName:a,...l},f={programName:a,...o!==void 0&&{cacheDir:o}};return e.subCommands?.__complete||(e.subCommands={...e.subCommands,__complete:te(e,a,n)}),e.subCommands?.[`__refresh-completion`]||(e.subCommands={...e.subCommands,"__refresh-completion":mn(e,a,l)}),e.subCommands?.[`__completion-worker-path`]||(e.subCommands={...e.subCommands,"__completion-worker-path":hn(a,l)}),r({name:`completion`,description:`Generate shell completion script`,args:s,run(t){let r=t.shell||u();if(!r){console.error(`Could not detect shell type. Please specify one of: bash, zsh, fish`),process.exitCode=1;return}if(t.static&&t.dispatcher)throw Error(`Choose only one completion mode: --dispatcher or --static.`);if(t.worker&&!t.static)throw Error("`--worker` requires `--static`.");if(t.worker&&(t.install||t.loader||t.instructions))throw Error("`--worker` can only print a worker artifact.");let s=t.static?`static`:`dispatcher`;if(t.install){let t;try{t=Ut({rootCommand:e,...d,completionMode:s},r)}catch(e){throw Error(`install failed: ${e instanceof Error?e.message:String(e)}`)}console.error(`installed: ${t}`),r===`bash`?(console.error(``),console.error(`Add to your ~/.${r}rc:`),console.error(``),console.error(Zt({...f,shell:r}).trim().replace(/^/gm,` `))):r===`zsh`&&fn(a,t);return}if(t.loader){if(r===`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({...f,shell:r}));return}let l=un(e,{shell:r,programName:a,mode:s,includeDescriptions:!0,...n!==void 0&&{globalArgsSchema:n},...c!==void 0&&{programVersion:c},...o!==void 0&&{cacheDir:o},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker},...t.worker&&{staticWorker:{functionSuffix:`worker`}}});t.instructions?console.log(l.installInstructions):console.log(l.script)}})}function mn(e,t,n={}){return r({name:`__refresh-completion`,description:`(internal) Refresh the on-disk completion cache if stale.`,args:l,run(r){qt({rootCommand:e,programName:t,...n,completionMode:r.static||r.worker?`static`:void 0,...r.worker&&{staticWorker:{functionSuffix:`worker`}},...r.worker&&{allowTargetCreate:!0},...r.target!==void 0&&{targetPath:r.target}},r.shell)}})}function hn(e,t={}){return r({name:`__completion-worker-path`,description:`(internal) Print the bundled completion worker path when available.`,args:o,run(n){let r=lt({programName:e,shell:n.shell,...t.binPath!==void 0&&{binPath:t.binPath},...t.bundledWorker!==void 0&&{bundledWorker:t.bundledWorker}});if(!r)throw Error(`No bundled completion worker found for ${e} (${n.shell}).`);console.log(r)}})}export{dn as a,gt as c,be as d,un as i,st as l,hn as n,$e as o,mn as r,et as s,pn as t,H as u};
|
package/dist/completion.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Command, Z as ResolvedFieldMeta, _ as DynamicCompletionResult, b as ArgsSchema, d as ExpandCompletion, g as DynamicCompletionResolver, h as DynamicCompletionContext, m as DynamicCompletionCandidate, p as CompletionDirectiveMask, v as AnyCommand } from "./arg-registry-
|
|
2
|
-
import { _ as CompletionResult, a as bundledWorkerShellExtension, b as InferInternalArgs, c as validateBundledWorkerFile, d as CompletablePositional, f as CompletableSubcommand, g as CompletionOptions, h as CompletionMode, i as GenerateBundledCompletionWorkerResult, l as BundledWorkerOptions, m as CompletionGenerator, n as withCompletionCommand, o as defaultBundledWorkerOutputPath, p as CompletionData, r as GenerateBundledCompletionWorkerOptions, s as generateBundledCompletionWorker, t as WithCompletionOptions, u as CompletableOption, v as ShellType, x as InternalArgsSchema, y as ValueCompletion } from "./with-completion-command-
|
|
1
|
+
import { C as Command, Z as ResolvedFieldMeta, _ as DynamicCompletionResult, b as ArgsSchema, d as ExpandCompletion, g as DynamicCompletionResolver, h as DynamicCompletionContext, m as DynamicCompletionCandidate, p as CompletionDirectiveMask, v as AnyCommand } from "./arg-registry-Dvi0co21.js";
|
|
2
|
+
import { _ as CompletionResult, a as bundledWorkerShellExtension, b as InferInternalArgs, c as validateBundledWorkerFile, d as CompletablePositional, f as CompletableSubcommand, g as CompletionOptions, h as CompletionMode, i as GenerateBundledCompletionWorkerResult, l as BundledWorkerOptions, m as CompletionGenerator, n as withCompletionCommand, o as defaultBundledWorkerOutputPath, p as CompletionData, r as GenerateBundledCompletionWorkerOptions, s as generateBundledCompletionWorker, t as WithCompletionOptions, u as CompletableOption, v as ShellType, x as InternalArgsSchema, y as ValueCompletion } from "./with-completion-command-BKHwbzEc.js";
|
|
3
3
|
//#region ../core/src/completion/schemas.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Schema for the completion command arguments
|
package/dist/completion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-BXOytPt7.js";import{s as e,t}from"./with-completion-command-CQcqFHq8.js";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./dynamic-4uRohypH.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-OvSe3W9y.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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Example, W as SubCommandValue, X as ExtractedFields, Z as ResolvedFieldMeta, b as ArgsSchema, nt as SchemaLike, v as AnyCommand } from "./arg-registry-
|
|
1
|
+
import { T as Example, W as SubCommandValue, X as ExtractedFields, Z as ResolvedFieldMeta, b as ArgsSchema, nt as SchemaLike, v as AnyCommand } from "./arg-registry-Dvi0co21.js";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
//#region ../core/src/executor/subcommand-router.d.ts
|
|
4
4
|
/**
|