@politty/valibot 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/argv-parser-bI3e6XXA.js +1 -0
- package/dist/cli-main-BI_Kw8IO.js +1 -0
- package/dist/{cli-main-DWgM0yDd.js → cli-main-BOiqNyRU.js} +2 -2
- package/dist/cli-run-WhNQL09Z.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/{command-BXsTrIgI.js → command-CCiN78NV.js} +1 -1
- package/dist/completion-Bbe2Q4Y-.js +1 -0
- package/dist/{completion-VYVmOfDd.js → completion-CKXI6y7R.js} +1 -1
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +1 -1
- package/dist/content-mapper.d.ts +1 -0
- package/dist/content-mapper.js +6 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +2 -2
- package/dist/dynamic-BiCSjFGx.js +1 -0
- package/dist/{dynamic-D5fSE6ha.js → dynamic-D9Y4kkfj.js} +1 -1
- package/dist/global-args.politty +4 -0
- package/dist/import-meta-resolve-B7ziWO20.js +1 -0
- package/dist/import-meta-resolve-DQM0bLBb.js +3 -0
- package/dist/index.d.ts +26 -4
- package/dist/index.js +1 -1
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/runner-C0PI1zBE.js +33 -0
- package/dist/runner-ysBTWTf6.js +1 -0
- package/dist/skill.d.ts +1 -1
- package/dist/skill.js +1 -1
- package/dist/{subcommand-router-40vA6Mka.js → subcommand-router-CfCW9eG4.js} +1 -1
- package/dist/{types-DItR4zZu.d.ts → types-mJuR-rBV.d.ts} +9 -0
- package/dist/{with-completion-command-c3Re1EXL.d.ts → with-completion-command-Bq-S79VO.d.ts} +1 -1
- package/dist/{with-completion-command-CBdFyo7i.js → with-completion-command-gytc9LNl.js} +2 -2
- package/package.json +15 -4
- package/dist/argv-parser-DVXJQeSu.js +0 -1
- package/dist/cli-main-EvjEkKL0.js +0 -1
- package/dist/cli-run-KrpFxTKE.js +0 -1
- package/dist/completion-DeCErF7y.js +0 -1
- package/dist/dynamic-BvjVVjv2.js +0 -1
- package/dist/import-meta-resolve-DQ_owo_7.js +0 -3
- package/dist/runner-B9qwebyB.js +0 -33
- package/dist/runner-BPr5rtz4.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as e,p as t}from"./unflatten-DVeO9OZ_.js";const n=/* @__PURE__ */ new Set([`1`,`t`,`T`,`TRUE`,`true`,`True`]),r=/* @__PURE__ */ new Set([`0`,`f`,`F`,`FALSE`,`false`,`False`]);function i(e){return n.has(e)?!0:!r.has(e)&&e}function a(e,t){return t===`boolean`?i(e):e}function o(e){let t=e.indexOf(`=`);return t>=0?e.slice(2,t):e.slice(2)}function s(e,t){let n=o(e);if(!e.includes(`=`)){let e=t.negationMap.get(n);if(e&&t.booleanFlags.has(e))return{resolvedName:e,withoutDashes:n,isNegated:!0,isCustomNegation:!0,isSuppressedNegation:!1}}let r=e.includes(`=`);if(!r&&n.startsWith(`no-`)){let e=n.slice(3);if(e===e.toLowerCase()){let r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}}if(!r&&n.length>2&&n.startsWith(`no`)&&/[A-Z]/.test(n[2])){let e=n[2].toLowerCase()+n.slice(3),r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}return{resolvedName:t.aliasMap.get(n)??n,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!1}}const c=/^-\.?\d/;function l(e){return!e.startsWith(`-`)||e===`-`||c.test(e)}function u(e){return e.startsWith(`-`)&&!e.startsWith(`--`)&&e.length>2&&!e.includes(`=`)}function d(e,t){let n=Array.from(e),r=n.findIndex(t);if(r===-1)return{flags:n,valueOption:void 0};let i=n.slice(r+1).join(``);return{flags:n.slice(0,r),valueOption:{name:n[r],value:i===``?void 0:i}}}function f(e,t={}){let{aliasMap:n=/* @__PURE__ */ new Map,booleanFlags:r=/* @__PURE__ */ new Set,arrayFlags:a=/* @__PURE__ */ new Set,valueFlags:o=/* @__PURE__ */ new Set,definedNames:c=/* @__PURE__ */ new Set,negationMap:u=/* @__PURE__ */ new Map,defaultNegationDisabledFields:f,unknownFlagsTakeNoValue:p=!1}=t,m=f??new Set(r),h=e=>r.has(e)||p&&!c.has(e),g={aliasMap:n,booleanFlags:r,definedNames:c,negationMap:u,defaultNegationDisabledFields:m},_={options:{},positionals:[],rest:[]},v=0,y=!1,b=(e,t)=>{let r=n.get(e)??e;if(a.has(r)){let e=_.options[r];Array.isArray(e)?e.push(t):e===void 0?_.options[r]=[t]:_.options[r]=[e,t]}else _.options[r]=t},x=t=>{let n=e[v+1];n!==void 0&&l(n)?(b(t,n),v+=2):(b(t,!0),v++)};for(;v<e.length;){let t=e[v];if(y)_.rest.push(t),v++;else if(t===`--`)y=!0,v++;else if(t.startsWith(`--`)){let e=t.slice(2),a=s(t,g);if(a.isSuppressedNegation){b(a.withoutDashes,!0),v++;continue}if(a.isNegated){b(a.resolvedName,!1),v++;continue}let o=e.indexOf(`=`);if(o!==-1){let t=e.slice(0,o),a=e.slice(o+1),s=n.get(t)??t;b(t,r.has(s)?i(a):a),v++}else{let t=e;h(n.get(t)??t)?(b(t,!0),v++):x(t)}}else if(t.startsWith(`-`)&&t.length>1&&!t.startsWith(`--`)){let e=t.slice(1),a=e.indexOf(`=`);if(a!==-1){let t=e.slice(0,a),o=e.slice(a+1),s=n.get(t)??t;b(t,r.has(s)?i(o):o),v++}else if(e.length===1){let t=e;h(n.get(t)??t)?(b(t,!0),v++):x(t)}else{let{flags:t,valueOption:r}=d(e,e=>o.has(n.get(e)??e));for(let e of t)b(e,!0);r?r.value===void 0?x(r.name):(b(r.name,r.value),v++):v++}}else _.positionals.push(t),v++}return _}function p(n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Set;for(let e of n.fields)s.add(e.name);for(let u of n.fields){if(!u.named)continue;u.cliName!==u.name&&r.set(u.cliName,u.name);for(let n of e(u))if(r.set(n,u.name),n.length>1&&n.includes(`-`)){let e=t(n);e!==n&&!s.has(e)&&!r.has(e)&&r.set(e,u.name)}let n=t(u.name);if(n!==u.name&&!s.has(n)&&!r.has(n)&&r.set(n,u.name),u.type===`boolean`?i.add(u.name):o.add(u.name),u.type===`array`&&a.add(u.name),u.type===`boolean`&&u.negation!==!0&&(l.add(u.name),typeof u.negation==`string`&&(c.set(u.negation,u.name),u.negation.includes(`-`)))){let e=t(u.negation);e!==u.negation&&c.set(e,u.name)}}return{aliasMap:r,booleanFlags:i,arrayFlags:a,valueFlags:o,definedNames:s,negationMap:c,defaultNegationDisabledFields:l}}function m(e,t){return e.fields.filter(e=>e.positional&&!(e.named&&Object.hasOwn(t,e.name)))}function h(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 m(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{f as a,o as c,a as d,h as i,s as l,l as n,m as o,u as r,d as s,p as t,i as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as runPolittyCli}from"./cli-main-BOiqNyRU.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d as e,f as t}from"./schema-extractor-Cwg_WAC-.js";import{n}from"./command-
|
|
2
|
-
`)}function w(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function T(e){return(t={})=>E(`${e}/compile-cache`,t)}function E(e,t){let n=t.cwd??process.cwd(),r=y(n),l=r?.pkg,p=w(t.entry),m=w(t.out),T=b(l),E;if(m.length>0){if(p.length>0&&p.length!==m.length)throw Error(`--entry count (${p.length}) does not match --out count (${m.length}); pass one --out per --entry or omit --out entirely.`);E=m.map(e=>f(e)?e:h(n,e))}else{if(T.length===0||r===void 0)throw Error(`Cannot derive the output path: no bin entry in package.json. Pass --out explicitly.`);if(p.length>0&&p.length!==T.length)throw Error(`--entry count (${p.length}) does not match the package's bin entries (${T.length}); pass one --entry per bin (in declaration order) or matching --out paths.`);E=T.map(([,e])=>h(r.dir,e))}if(new Set(E).size!==E.length)throw Error(`Duplicate output paths; each shim needs a distinct output file. Check the --out values (or the bin paths in package.json when --out is omitted).`);let O=/* @__PURE__ */ new Map;if(r)for(let[e,t]of T)O.set(h(r.dir,t),e);let k=[],A=t.compileCacheSpecifier??e;if(/[\r\n\u2028\u2029]/.test(A))throw Error(`Invalid compile-cache specifier ${JSON.stringify(A)}: a module specifier cannot contain a line terminator.`);let j=E.map((e,r)=>{let i=O.get(e),o=t.program??i??x(l);if(!o)throw Error(`Cannot derive a program name: no bin or name in package.json. Pass --program explicitly.`);if(t.program===void 0&&i===void 0&&m.length>0&&k.push(`Warning: ${D(e,n)} does not match any bin path in package.json, so its cache directory uses the program name ${JSON.stringify(o)}. Pass --program to override.`),e.endsWith(`.cjs`))throw Error(`The generated shim is an ES module and cannot be written to a .cjs file. Use a .mjs (or .js in a "type": "module" package) output path.`);if(d(e)===``)throw Error(`The generated shim is an ES module and cannot be written to an extensionless file (it would not load on every supported Node.js version). Use a .mjs (or .js in a "type": "module" package) output path.`);if(e.endsWith(`.js`)&&l?.type!==`module`)throw Error(l===void 0?`The generated shim is an ES module, and no package.json was found to confirm .js files are treated as ESM. Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`:`The generated shim is an ES module, but the package is not "type": "module". Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`);let c=p[r]??S(e);if(c===void 0)throw Error(`Cannot derive an entry: none of ${v.join(`, `)} exist next to ${e}. Pass --entry explicitly.`);if(!c.startsWith(`./`)&&!c.startsWith(`../`)&&!c.startsWith(`file:`))throw Error(`Invalid entry ${c}: pass a specifier relative to the shim file ("./..." or "../...") or a file: URL.`);let f;if(c.startsWith(`file:`))try{f=g(c)}catch{f=void 0}else f=h(u(e),c);if(f===e)throw Error(`The shim at ${e} would import itself (entry ${c}). Point bin at a separate shim path (e.g. dist/bin.js) or pass a different --entry.`);if(a(e)&&!s(e,`utf8`).includes(_))throw Error(`Refusing to overwrite ${e}: it exists and was not generated by politty. If bin currently points at your real CLI entry, point it at a separate shim path (e.g. dist/bin.js) or pass --out explicitly.`);return{outputPath:e,program:o,entry:c,compileCacheSpecifier:A}});for(let e of k)console.warn(e);for(let{outputPath:e,program:t,entry:n}of j)o(u(e),{recursive:!0}),c(e,C(t,n,A)),i(e,493);return j}function D(e,t){let n=m(t,e);return n&&!n.startsWith(`..`)?n:e}const O=e({bin:t.string({description:`CLI binary or built JS entry file to invoke`,placeholder:`PATH`}),program:t.string({description:`Program name embedded in worker metadata`,placeholder:`NAME`}),shell:t.enum([`bash`,`zsh`,`fish`],{description:`Shell worker to generate`,placeholder:`SHELL`}),out:t.optionalString({description:`Output worker path (defaults to dist/completion/<shell>-worker.<ext>)`,placeholder:`PATH`}),verify:t.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,f as t}from"./schema-extractor-Cwg_WAC-.js";import{n}from"./command-CCiN78NV.js";import{n as r}from"./runner-C0PI1zBE.js";import{chmodSync as i,existsSync as a,mkdirSync as o,readFileSync as s,writeFileSync as c}from"node:fs";import{basename as l,dirname as u,extname as d,isAbsolute as f,join as p,relative as m,resolve as h}from"node:path";import{fileURLToPath as g}from"node:url";const _=`Generated by politty: compile-cache bin shim`,v=[`./cli.js`,`./cli.mjs`,`./index.js`,`./index.mjs`];function y(e){let t=h(e);for(;;){let e=p(t,`package.json`);if(a(e))return{pkg:JSON.parse(s(e,`utf8`)),dir:t};let n=u(t);if(n===t)return;t=n}}function b(e){if(!e)return[];if(typeof e.bin==`string`&&e.bin){let t=x(e);return t?[[t,e.bin]]:[]}return typeof e.bin==`object`&&e.bin!==null?Object.entries(e.bin).filter(e=>typeof e[1]==`string`&&e[1]!==``):[]}function x(e){if(e){if(typeof e.bin==`object`&&e.bin!==null){let[t]=Object.keys(e.bin);if(t)return t}if(typeof e.name==`string`&&e.name){let t=e.name;return t.startsWith(`@`)?t.split(`/`)[1]??t:t}}}function S(e){let t=u(e),n=l(e);for(let e of v)if(l(e)!==n&&a(p(t,e)))return e}function C(e,t,n){return[`#!/usr/bin/env node`,``,`// ${_}.`,`// Enables the Node.js on-disk compile cache (V8 code cache) before the`,`// CLI module graph is compiled, so warm starts skip recompilation`,`// (Node >= 22.8.0; silent no-op otherwise).`,`try {`,` const { enableCompileCache } = await import(${JSON.stringify(n)});`,` enableCompileCache(${JSON.stringify(e)});`,`} catch {`,` // ${n} is not resolvable from here (e.g. a fully`,` // bundled CLI) — start without the compile cache rather than failing`,` // the CLI.`,`}`,`await import(${JSON.stringify(t)});`,``].join(`
|
|
2
|
+
`)}function w(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function T(e){return(t={})=>E(`${e}/compile-cache`,t)}function E(e,t){let n=t.cwd??process.cwd(),r=y(n),l=r?.pkg,p=w(t.entry),m=w(t.out),T=b(l),E;if(m.length>0){if(p.length>0&&p.length!==m.length)throw Error(`--entry count (${p.length}) does not match --out count (${m.length}); pass one --out per --entry or omit --out entirely.`);E=m.map(e=>f(e)?e:h(n,e))}else{if(T.length===0||r===void 0)throw Error(`Cannot derive the output path: no bin entry in package.json. Pass --out explicitly.`);if(p.length>0&&p.length!==T.length)throw Error(`--entry count (${p.length}) does not match the package's bin entries (${T.length}); pass one --entry per bin (in declaration order) or matching --out paths.`);E=T.map(([,e])=>h(r.dir,e))}if(new Set(E).size!==E.length)throw Error(`Duplicate output paths; each shim needs a distinct output file. Check the --out values (or the bin paths in package.json when --out is omitted).`);let O=/* @__PURE__ */ new Map;if(r)for(let[e,t]of T)O.set(h(r.dir,t),e);let k=[],A=t.compileCacheSpecifier??e;if(/[\r\n\u2028\u2029]/.test(A))throw Error(`Invalid compile-cache specifier ${JSON.stringify(A)}: a module specifier cannot contain a line terminator.`);let j=E.map((e,r)=>{let i=O.get(e),o=t.program??i??x(l);if(!o)throw Error(`Cannot derive a program name: no bin or name in package.json. Pass --program explicitly.`);if(t.program===void 0&&i===void 0&&m.length>0&&k.push(`Warning: ${D(e,n)} does not match any bin path in package.json, so its cache directory uses the program name ${JSON.stringify(o)}. Pass --program to override.`),e.endsWith(`.cjs`))throw Error(`The generated shim is an ES module and cannot be written to a .cjs file. Use a .mjs (or .js in a "type": "module" package) output path.`);if(d(e)===``)throw Error(`The generated shim is an ES module and cannot be written to an extensionless file (it would not load on every supported Node.js version). Use a .mjs (or .js in a "type": "module" package) output path.`);if(e.endsWith(`.js`)&&l?.type!==`module`)throw Error(l===void 0?`The generated shim is an ES module, and no package.json was found to confirm .js files are treated as ESM. Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`:`The generated shim is an ES module, but the package is not "type": "module". Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`);let c=p[r]??S(e);if(c===void 0)throw Error(`Cannot derive an entry: none of ${v.join(`, `)} exist next to ${e}. Pass --entry explicitly.`);if(!c.startsWith(`./`)&&!c.startsWith(`../`)&&!c.startsWith(`file:`))throw Error(`Invalid entry ${c}: pass a specifier relative to the shim file ("./..." or "../...") or a file: URL.`);let f;if(c.startsWith(`file:`))try{f=g(c)}catch{f=void 0}else f=h(u(e),c);if(f===e)throw Error(`The shim at ${e} would import itself (entry ${c}). Point bin at a separate shim path (e.g. dist/bin.js) or pass a different --entry.`);if(a(e)&&!s(e,`utf8`).includes(_))throw Error(`Refusing to overwrite ${e}: it exists and was not generated by politty. If bin currently points at your real CLI entry, point it at a separate shim path (e.g. dist/bin.js) or pass --out explicitly.`);return{outputPath:e,program:o,entry:c,compileCacheSpecifier:A}});for(let e of k)console.warn(e);for(let{outputPath:e,program:t,entry:n}of j)o(u(e),{recursive:!0}),c(e,C(t,n,A)),i(e,493);return j}function D(e,t){let n=m(t,e);return n&&!n.startsWith(`..`)?n:e}const O=e({bin:t.string({description:`CLI binary or built JS entry file to invoke`,placeholder:`PATH`}),program:t.string({description:`Program name embedded in worker metadata`,placeholder:`NAME`}),shell:t.enum([`bash`,`zsh`,`fish`],{description:`Shell worker to generate`,placeholder:`SHELL`}),out:t.optionalString({description:`Output worker path (defaults to dist/completion/<shell>-worker.<ext>)`,placeholder:`PATH`}),verify:t.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-Bbe2Q4Y-.js`);await t({bin:e.bin,programName:e.program,shell:e.shell,...e.out!==void 0&&{outputPath:e.out},verify:e.verify})}}),A=e({entry:t.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:t.optionalStringArray({description:`Output path for the generated shim; repeatable, one per --entry (defaults to the bin paths in package.json)`,placeholder:`PATH`}),program:t.optionalString({description:`Program name for the cache directory, applied to all shims (defaults per shim to its bin name)`,placeholder:`NAME`}),compileCacheSpecifier:t.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-ZdhcM-o7.js";const{runPolittyCli:e}=await import(`./cli-main-BI_Kw8IO.js`);await e(`@politty/valibot`);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-WhNQL09Z.js`);export{};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){return{name:e.name,description:e.description,requiredPackages:e.requiredPackages,aliases:e.aliases,args:e.args,subCommands:e.subCommands,defaultSubCommand:e.defaultSubCommand,setup:e.setup,run:e.run,cleanup:e.cleanup,notes:e.notes,examples:e.examples}}function t(){return e}export{e as n,t};
|
|
1
|
+
function e(e){return{name:e.name,description:e.description,requiredPackages:e.requiredPackages,aliases:e.aliases,args:e.args,subCommands:e.subCommands,defaultSubCommand:e.defaultSubCommand,setup:e.setup,run:e.run,gracefulShutdown:e.gracefulShutdown,cleanup:e.cleanup,notes:e.notes,examples:e.examples}}function t(){return e}export{e as n,t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./with-completion-command-gytc9LNl.js";import"./dynamic-D9Y4kkfj.js";export{t as createCompletionCommand,n as createCompletionWorkerPathCommand,r as createRefreshCompletionCommand,c as generateBundledCompletionWorker}from"./completion-CKXI6y7R.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./command-BXsTrIgI.js";import{_ as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,p as u,s as d,t as f,u as p,v as m,y as h}from"./dynamic-D5fSE6ha.js";import{a as g,c as _,n as v}from"./schema-extractor-Cwg_WAC-.js";import{c as y}from"./subcommand-router-40vA6Mka.js";import{a as b,i as ee,n as x,o as te,r as ne,s as re}from"./with-completion-command-CBdFyo7i.js";import{existsSync as S,mkdirSync as ie,readFileSync as C,realpathSync as w,renameSync as ae,rmSync as oe,statSync as T,writeFileSync as se}from"node:fs";import{dirname as E,extname as ce,isAbsolute as le,join as ue,relative as de,resolve as fe}from"node:path";import{promisify as pe}from"node:util";import{execFile as me}from"node:child_process";function he(e,t,n=[],r=!1){if(t.length===0)return;let i=ge(e,n);for(let e of t)e.set(_e(e,i,r))}function ge(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function _e(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ye(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=ve(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function ve(e){let t=[],n=/* @__PURE__ */ new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ye(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function be(e,t,n,r){let i=d(e);i?.type===`pending-expand`?t.push({name:e.name,describe:n,set:r,spec:i.spec}):i!==void 0&&r(i)}function D(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function O(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function k(e,t,n){return`__${e}_expand_${t}__${D(n)}`}function xe(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${O(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function A(e){return e.filter(e=>!e.name.startsWith(`__`))}function j(e){let t=[];for(let n of A(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function Se(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return be(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function Ce(e){return e.args?_(v(e.args)):[]}function we(e,t){return e.filter(e=>e.named).map(e=>Se(e,t))}function Te(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return be(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ee(e,t,n=[],r=!1){let i=[];if(t.subCommands)for(let[e,a]of Object.entries(t.subCommands)){let t=y(a);t?i.push(Ee(e,t,n,r)):i.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let a=[],o=t.args?v(t.args):void 0,s={name:e,description:t.description,aliases:t.aliases,subcommands:i,options:we(o?g(o):[],a),positionals:Te(o?_(o):[],a)};return he(s,a,n,r),s}function M(e,t,n){return e?`${e}${n}${t}`:t}function De(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>M(e,t,`:`)))}function Oe(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of A(e.subcommands))n(t,De(r,t))};return n(e,[``]),t}function N(e,t){let n=[],r=A(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?c(i.cliName,i.alias):F(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of A(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...N(r,M(t,e,`:`)));return n}function ke(e,t){return N(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function P(e,t=``,n=``){let r=[];for(let i of A(e.subcommands)){let e=M(n,D(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=M(t,n,`:`);r.push(...P(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function Ae(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function je(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function Me(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${D(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ne(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${Me(r,t)} ;;`)}return n}function Pe(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${Me(r,t)} ;;`)}return n}function Fe(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=D(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function F(e,t){let n=c(e.cliName,e.alias);if(e.isGlobal===!0){let e=/* @__PURE__ */ new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of r(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let i=p(t);return i.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!i.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function Ie(e){let t=[];return Le(e,[],[``],[],`root`,t),t}function Le(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?F(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of A(e.subcommands))Le(o,[...t,o.name],De(n,o),[...r,...n],i===`root`?D(o.name):`${i}_${D(o.name)}`,a)}function Re(e,t,n=[]){let i=ze(e),a=/* @__PURE__ */ new Map,o=(e,t,n)=>{let r=a.get(e);r||(r={ref:t,pathStrs:[],seen:/* @__PURE__ */ new Set},a.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},s=(e,t,n)=>{let a=/* @__PURE__ */ new Map,o=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=a.get(n);r||(r={tokens:t,paths:[]},a.set(n,r)),r.paths.push(e)};for(let n of t){let t=i.get(n);if(!t)continue;let a=/* @__PURE__ */ new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of r(e.cliName,e.alias))a.add(t);o(n,e.filter(e=>!a.has(e)))}for(let t of n)o(t,e);return a},l=(e,t,n)=>{let r=c(t.cliName,t.alias),i=s(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)o(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=i.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;l(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&o(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let a=t.options.find(e=>e.name===r);a&&(a.isGlobal===!0?l(r,a,e):o(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:F(a,t.options)},e.pathStrs))}}let u=[];for(let e of a.values())e.pathStrs.length!==0&&u.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return u}function ze(e){let t=/* @__PURE__ */ new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of A(e.subcommands))n(t,De(r,t))};return n(e,[``]),t}function I(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(I(t))return!0;return!1}function Be(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Be(n,t)}function L(e,t,n,r=!1){let i=[];if(n){let e=[];i=we(v(n).fields,e).map(e=>(e.isGlobal=!0,e)),he({name:t,subcommands:[],options:i,positionals:[]},e,[],r)}let a=Ee(t,e,i,r);return n?Be(a,i):i=a.options,{command:a,programName:t,globalOptions:i}}function R(e){try{return Math.floor(T(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ve(e){return e.replace(/\r?\n/g,` `)}function He(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=ue(n,e);try{if(T(t).isFile())return t}catch{}}return null}function z(e,t){return t||process.env[O(D(e))]||(He(e)??process.argv[1]??``)}function B(e){let t=z(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${R(t)}`,`# politty-bin-path: ${Ve(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Ue(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=z(t,n),o=R(a),s=m(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${h(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function We(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=`_${t}`,o=z(t,n),s=R(o),c=m(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${h(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Ge(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ke(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function qe(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=k(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=D(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${D(r.fieldName)}:-}`:`\${_used_field_keys_${D(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Ge(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Je(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Je(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function V(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Je(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function Ye(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=qe(o.valueCompletion,n,r,{funcSuffix:i,...u(o,e,t)});if(s.length===0)continue;let c=F(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function H(e,t,n,r=[]){if(e.length===0)return[];let i=o(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of qe(o.valueCompletion,!1,t,{funcSuffix:n,...l(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Xe(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...H(t,n,r,i),`fi`]}function Ze(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=Ye(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=Ye(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function Qe(e,n){let r=[];for(let i of e){if(i.valueType===`array`){r.push(` _avail+=(--${i.cliName})`);continue}let a=t(i.cliName,i.alias,i.negation,{isGlobal:i.isGlobal===!0,frameOptions:e}),o=`__${n}_not_used ${a.join(` `)}`,s=i.negation?[i.cliName,i.negation]:[i.cliName];for(let e of s)a.includes(`"--${e}"`)&&r.push(` ${o} && _avail+=(--${e})`)}return r.push(` if (( ! _any_opt_used )); then`),r.push(` _avail+=(--help --help-all --help-json)`),r.push(` fi`),r}function $e(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...$e(e,t,r));s.push(`${a}() {`),s.push(...Ze(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...H(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...Qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=j(e.subcommands).map(e=>e.name).join(` `);s.push(...Xe(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...H(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function et(e,t){let{programName:r}=t,i=L(e,r,t.globalArgsSchema),o=D(r),c=t.staticWorker?`${o}_${D(t.staticWorker.functionSuffix)}`:o,l=t.staticWorker!==void 0,u=i.command,d=A(u.subcommands),f=Ie(u),p=Re(u,f,i.globalOptions),m=[];m.push(...B({programName:r,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${l?`worker`:`static`}`),l&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),l||m.push(...Ue({programName:r,binPath:t.binPath}));let h=f.length>0,g=f.filter(e=>e.isArrayOption),_=g.length>0;h&&(m.push(`__${c}_enc() {`),m.push(` local LC_ALL=C`),m.push(` local _s=$1 _r='' _c _i`),m.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),m.push(" _c=${_s:_i:1}"),m.push(` case "$_c" in`),m.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),m.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),m.push(` esac`),m.push(` done`),m.push(` printf '%s' "$_r"`),m.push(`}`),m.push(``));for(let e of f){let t=k(c,e.funcSuffix,e.fieldName);for(let r of e.vc.table){let e=r.key.map(Ke).join(`_`),i=r.candidates.map(e=>e.value).join(`
|
|
1
|
+
import{n as e}from"./command-CCiN78NV.js";import{_ as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,p as u,s as d,t as f,u as p,v as m,y as h}from"./dynamic-D9Y4kkfj.js";import{a as g,c as _,n as v}from"./schema-extractor-Cwg_WAC-.js";import{c as y}from"./subcommand-router-CfCW9eG4.js";import{a as b,i as ee,n as x,o as te,r as ne,s as re}from"./with-completion-command-gytc9LNl.js";import{existsSync as S,mkdirSync as ie,readFileSync as C,realpathSync as w,renameSync as ae,rmSync as oe,statSync as T,writeFileSync as se}from"node:fs";import{dirname as E,extname as ce,isAbsolute as le,join as ue,relative as de,resolve as fe}from"node:path";import{promisify as pe}from"node:util";import{execFile as me}from"node:child_process";function he(e,t,n=[],r=!1){if(t.length===0)return;let i=ge(e,n);for(let e of t)e.set(_e(e,i,r))}function ge(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function _e(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ye(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=ve(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function ve(e){let t=[],n=/* @__PURE__ */ new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ye(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function be(e,t,n,r){let i=d(e);i?.type===`pending-expand`?t.push({name:e.name,describe:n,set:r,spec:i.spec}):i!==void 0&&r(i)}function D(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function O(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function k(e,t,n){return`__${e}_expand_${t}__${D(n)}`}function xe(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${O(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function A(e){return e.filter(e=>!e.name.startsWith(`__`))}function j(e){let t=[];for(let n of A(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function Se(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return be(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function Ce(e){return e.args?_(v(e.args)):[]}function we(e,t){return e.filter(e=>e.named).map(e=>Se(e,t))}function Te(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return be(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ee(e,t,n=[],r=!1){let i=[];if(t.subCommands)for(let[e,a]of Object.entries(t.subCommands)){let t=y(a);t?i.push(Ee(e,t,n,r)):i.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let a=[],o=t.args?v(t.args):void 0,s={name:e,description:t.description,aliases:t.aliases,subcommands:i,options:we(o?g(o):[],a),positionals:Te(o?_(o):[],a)};return he(s,a,n,r),s}function M(e,t,n){return e?`${e}${n}${t}`:t}function De(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>M(e,t,`:`)))}function Oe(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of A(e.subcommands))n(t,De(r,t))};return n(e,[``]),t}function N(e,t){let n=[],r=A(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?c(i.cliName,i.alias):F(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of A(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...N(r,M(t,e,`:`)));return n}function ke(e,t){return N(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function P(e,t=``,n=``){let r=[];for(let i of A(e.subcommands)){let e=M(n,D(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=M(t,n,`:`);r.push(...P(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function Ae(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function je(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function Me(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${D(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ne(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${Me(r,t)} ;;`)}return n}function Pe(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${Me(r,t)} ;;`)}return n}function Fe(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=D(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function F(e,t){let n=c(e.cliName,e.alias);if(e.isGlobal===!0){let e=/* @__PURE__ */ new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of r(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let i=p(t);return i.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!i.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function Ie(e){let t=[];return Le(e,[],[``],[],`root`,t),t}function Le(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?F(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of A(e.subcommands))Le(o,[...t,o.name],De(n,o),[...r,...n],i===`root`?D(o.name):`${i}_${D(o.name)}`,a)}function Re(e,t,n=[]){let i=ze(e),a=/* @__PURE__ */ new Map,o=(e,t,n)=>{let r=a.get(e);r||(r={ref:t,pathStrs:[],seen:/* @__PURE__ */ new Set},a.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},s=(e,t,n)=>{let a=/* @__PURE__ */ new Map,o=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=a.get(n);r||(r={tokens:t,paths:[]},a.set(n,r)),r.paths.push(e)};for(let n of t){let t=i.get(n);if(!t)continue;let a=/* @__PURE__ */ new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of r(e.cliName,e.alias))a.add(t);o(n,e.filter(e=>!a.has(e)))}for(let t of n)o(t,e);return a},l=(e,t,n)=>{let r=c(t.cliName,t.alias),i=s(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)o(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=i.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;l(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&o(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let a=t.options.find(e=>e.name===r);a&&(a.isGlobal===!0?l(r,a,e):o(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:F(a,t.options)},e.pathStrs))}}let u=[];for(let e of a.values())e.pathStrs.length!==0&&u.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return u}function ze(e){let t=/* @__PURE__ */ new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of A(e.subcommands))n(t,De(r,t))};return n(e,[``]),t}function I(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(I(t))return!0;return!1}function Be(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Be(n,t)}function L(e,t,n,r=!1){let i=[];if(n){let e=[];i=we(v(n).fields,e).map(e=>(e.isGlobal=!0,e)),he({name:t,subcommands:[],options:i,positionals:[]},e,[],r)}let a=Ee(t,e,i,r);return n?Be(a,i):i=a.options,{command:a,programName:t,globalOptions:i}}function R(e){try{return Math.floor(T(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ve(e){return e.replace(/\r?\n/g,` `)}function He(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=ue(n,e);try{if(T(t).isFile())return t}catch{}}return null}function z(e,t){return t||process.env[O(D(e))]||(He(e)??process.argv[1]??``)}function B(e){let t=z(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${R(t)}`,`# politty-bin-path: ${Ve(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Ue(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=z(t,n),o=R(a),s=m(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${h(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function We(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=`_${t}`,o=z(t,n),s=R(o),c=m(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${h(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Ge(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ke(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function qe(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=k(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=D(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${D(r.fieldName)}:-}`:`\${_used_field_keys_${D(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Ge(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Je(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Je(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function V(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Je(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function Ye(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=qe(o.valueCompletion,n,r,{funcSuffix:i,...u(o,e,t)});if(s.length===0)continue;let c=F(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function H(e,t,n,r=[]){if(e.length===0)return[];let i=o(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of qe(o.valueCompletion,!1,t,{funcSuffix:n,...l(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Xe(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...H(t,n,r,i),`fi`]}function Ze(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=Ye(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=Ye(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function Qe(e,n){let r=[];for(let i of e){if(i.valueType===`array`){r.push(` _avail+=(--${i.cliName})`);continue}let a=t(i.cliName,i.alias,i.negation,{isGlobal:i.isGlobal===!0,frameOptions:e}),o=`__${n}_not_used ${a.join(` `)}`,s=i.negation?[i.cliName,i.negation]:[i.cliName];for(let e of s)a.includes(`"--${e}"`)&&r.push(` ${o} && _avail+=(--${e})`)}return r.push(` if (( ! _any_opt_used )); then`),r.push(` _avail+=(--help --help-all --help-json)`),r.push(` fi`),r}function $e(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...$e(e,t,r));s.push(`${a}() {`),s.push(...Ze(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...H(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...Qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=j(e.subcommands).map(e=>e.name).join(` `);s.push(...Xe(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...H(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function et(e,t){let{programName:r}=t,i=L(e,r,t.globalArgsSchema),o=D(r),c=t.staticWorker?`${o}_${D(t.staticWorker.functionSuffix)}`:o,l=t.staticWorker!==void 0,u=i.command,d=A(u.subcommands),f=Ie(u),p=Re(u,f,i.globalOptions),m=[];m.push(...B({programName:r,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${l?`worker`:`static`}`),l&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),l||m.push(...Ue({programName:r,binPath:t.binPath}));let h=f.length>0,g=f.filter(e=>e.isArrayOption),_=g.length>0;h&&(m.push(`__${c}_enc() {`),m.push(` local LC_ALL=C`),m.push(` local _s=$1 _r='' _c _i`),m.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),m.push(" _c=${_s:_i:1}"),m.push(` case "$_c" in`),m.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),m.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),m.push(` esac`),m.push(` done`),m.push(` printf '%s' "$_r"`),m.push(`}`),m.push(``));for(let e of f){let t=k(c,e.funcSuffix,e.fieldName);for(let r of e.vc.table){let e=r.key.map(Ke).join(`_`),i=r.candidates.map(e=>e.value).join(`
|
|
2
2
|
`);m.push(`${t}__${e}=${n(i)}`)}m.push(``)}I(u)&&(m.push(...xe(c,r)),m.push(``),m.push(`__${c}_apply_dynamic_output() {`),m.push(` local _raw="$1"`),m.push(` COMPREPLY=()`),m.push(` local _directive=0`),m.push(` local -a _lines=()`),m.push(` local _line`),m.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),m.push(" local _last=$((${#_lines[@]} - 1))"),m.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),m.push(' _directive="${_lines[$_last]#:}"'),m.push(` unset '_lines[_last]'`),m.push(` fi`),m.push(' for _line in "${_lines[@]}"; do'),m.push(` [[ -z "$_line" ]] && continue`),m.push(` COMPREPLY+=("$_line")`),m.push(` done`),m.push(' local _ip="${_inline_prefix:-}"'),m.push(` if (( _directive & ${s.DirectoryCompletion} )); then`),m.push(` compopt +o default 2>/dev/null`),m.push(` compopt -o filenames 2>/dev/null`),m.push(` local _d`),m.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),m.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),m.push(` elif (( _directive & ${s.FileCompletion} )); then`),m.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),m.push(` compopt -o filenames 2>/dev/null`),m.push(` local _f`),m.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),m.push(` else`),m.push(` compopt -o default 2>/dev/null`),m.push(` fi`),m.push(` else`),m.push(` if (( _directive & ${s.NoFileCompletion} )); then`),m.push(` compopt +o default 2>/dev/null`),m.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),m.push(` fi`),m.push(` fi`),m.push(` if (( _directive & ${s.NoSpace} )); then`),m.push(` compopt -o nospace 2>/dev/null`),m.push(` fi`),m.push(`}`),m.push(``)),m.push(`__${c}_not_used() {`),m.push(' for _u in "${_used_opts[@]}"; do'),m.push(` for _chk in "$@"; do`),m.push(` [[ "$_u" == "$_chk" ]] && return 1`),m.push(` done`),m.push(` done`),m.push(` return 0`),m.push(`}`),m.push(``),m.push(`__${c}_opt_takes_value() {`),m.push(` case "$1:$2" in`),m.push(...ke(u,``)),m.push(` esac`),m.push(` return 1`),m.push(`}`),m.push(``),h&&(m.push(`__${c}_track_opt() {`),m.push(` case "$1:$2" in`),m.push(...Ne(p,`bash`)),m.push(` esac`),m.push(`}`),m.push(``),m.push(`__${c}_track_pos() {`),m.push(` case "$1:$2" in`),m.push(...Pe(p,`bash`)),m.push(` esac`),m.push(`}`),m.push(``),m.push(...a(c,Oe(u)))),_&&(m.push(`__${c}_track_array_expand() {`),m.push(` case "$1:$2" in`),m.push(...Fe(g,`bash`)),m.push(` esac`),m.push(`}`),m.push(``));let v=P(u);v.length>0&&(m.push(`__${c}_is_subcmd() {`),m.push(` case "$1:$2" in`),m.push(...Ae(v)),m.push(` esac`),m.push(` return 1`),m.push(`}`),m.push(``));for(let e of d)m.push(...$e(e,c,[]));if(m.push(`__${c}_complete_root() {`),m.push(...Ze(u.options,u.positionals,c,`root`)),m.push(` if [[ -z "$_inline_prefix" ]] && __${c}_opt_takes_value "" "$_prev"; then return; fi`),m.push(` if [[ -n "$_inline_prefix" ]] && __${c}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),u.positionals.length>0?(m.push(` if (( _after_dd )); then`),m.push(...H(u.positionals,c,`root`,u.options).map(e=>` ${e}`)),m.push(` return`),m.push(` fi`)):m.push(` if (( _after_dd )); then return; fi`),m.push(` if [[ "$_cur" == -* ]]; then`),m.push(` local -a _avail=()`),m.push(...Qe(u.options,c)),m.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),m.push(` compopt +o default 2>/dev/null`),d.length>0){m.push(` else`);let e=j(u.subcommands).map(e=>e.name).join(` `);m.push(...Xe(e,u.positionals,c,`root`,u.options).map(e=>` ${e}`))}else u.positionals.length>0&&(m.push(` else`),m.push(...H(u.positionals,c,`root`,u.options).map(e=>` ${e}`)));m.push(` fi`),m.push(`}`),m.push(``);let y=je(v,c).join(`
|
|
3
3
|
`);m.push(`_${c}_completions() {`),m.push(` COMPREPLY=()`),m.push(``),m.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),m.push(` local -a _words=()`),m.push(` local _i=1`),m.push(` while (( _i <= COMP_CWORD )); do`),m.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),m.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),m.push(` (( _i += 2 ))`),m.push(` else`),m.push(' _words+=("${COMP_WORDS[_i]}")'),m.push(` (( _i++ ))`),m.push(` fi`),m.push(` done`),m.push(``),m.push(` local _cur=""`),m.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),m.push(` local _inline_prefix=""`),m.push(``),m.push(` local _prev=""`),m.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),m.push(``),m.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),m.push(` local -a _used_opts=()`),h&&m.push(` local -a _pos_words=()`),m.push(` local _any_opt_used=0`),h&&(m.push(` ${V(`_arg_values_`)}`),m.push(` ${V(`_global_arg_values_`)}`)),_&&(m.push(` ${V(`_used_field_keys_`)}`),m.push(` ${V(`_global_used_field_keys_`)}`),m.push(` ${V(`_global_arr_seen_`)}`)),m.push(``),m.push(` local _j=0`),m.push(" while (( _j < ${#_words[@]} - 1 )); do"),m.push(' local _w="${_words[_j]}"'),m.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),m.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=h?`_pos_words+=("$_w"); `:``;m.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),m.push(` if [[ "$_w" == -*=* ]]; then`),m.push(' _used_opts+=("${_w%%=*}")'),m.push(` _any_opt_used=1`),h&&(m.push(` __${c}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),_&&m.push(` __${c}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),m.push(` (( _j++ )); continue`),m.push(` fi`),m.push(` if [[ "$_w" == -* ]]; then`),m.push(` _used_opts+=("$_w")`),m.push(` _any_opt_used=1`),m.push(` if __${c}_opt_takes_value "$_subcmd" "$_w"; then`),m.push(' local _next="${_words[_j+1]:-}"'),m.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),h&&(m.push(` if (( _skip_next )); then`),m.push(` __${c}_track_opt "$_subcmd" "$_w" "$_next"`),_&&(m.push(" if (( _j + 2 < ${#_words[@]} )); then"),m.push(` __${c}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` fi`)),m.push(` fi`)),m.push(` fi`),m.push(` (( _j++ )); continue`),m.push(` fi`);let ee=_?`; ${V(`_arg_values_`)}; ${V(`_used_field_keys_`)}; ${V(`_global_arr_seen_`)}`:h?`; ${V(`_arg_values_`)}`:``,x=h?`_pos_words+=("$_w"); `:``;return v.length>0?m.push(` if __${c}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${h?`; _pos_words=()`:``}${ee}; else ${x}(( _pos_count++ )); fi`):(h&&m.push(` _pos_words+=("$_w")`),m.push(` (( _pos_count++ ))`)),m.push(` (( _j++ ))`),m.push(` done`),h&&m.push(` __${c}_track_positionals`),m.push(``),m.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),m.push(' _inline_prefix="${_cur%%=*}="'),m.push(' _cur="${_cur#*=}"'),m.push(` fi`),m.push(``),m.push(` case "$_subcmd" in`),m.push(y),m.push(` *) __${c}_complete_root ;;`),m.push(` esac`),m.push(`}`),m.push(``),l||m.push(`complete -o default -F _${c}_completions ${r}`),m.push(``),{script:m.join(`
|
|
4
4
|
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
package/dist/completion.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as ResolvedFieldMeta, a as ArgsSchema, at as DynamicCompletionCandidate, c as Command, ct as DynamicCompletionResult, it as CompletionDirectiveMask, nt as ExpandCompletion, ot as DynamicCompletionContext, r as AnyCommand, st as DynamicCompletionResolver } from "./types-
|
|
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 { L as ResolvedFieldMeta, a as ArgsSchema, at as DynamicCompletionCandidate, c as Command, ct as DynamicCompletionResult, it as CompletionDirectiveMask, nt as ExpandCompletion, ot as DynamicCompletionContext, r as AnyCommand, st as DynamicCompletionResolver } from "./types-mJuR-rBV.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-Bq-S79VO.js";
|
|
3
3
|
/**
|
|
4
4
|
* Schema for the completion command arguments
|
|
5
5
|
*/
|
package/dist/completion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-ZdhcM-o7.js";import{s as e,t}from"./with-completion-command-
|
|
1
|
+
import"./register-ZdhcM-o7.js";import{s as e,t}from"./with-completion-command-gytc9LNl.js";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./dynamic-D9Y4kkfj.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-CKXI6y7R.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{t as e}from"./import-meta-resolve-DQM0bLBb.js";import*as t from"node:fs";import*as n from"node:path";import{fileURLToPath as r,pathToFileURL as i}from"node:url";import{createHash as a}from"node:crypto";const o=[`typescript`,`tsrs`],s=/* @__PURE__ */ new Map;function c(t,r){try{return e(r,i(n.join(t,`package.json`)).href)}catch{return}}async function l(e,t){let n=c(t,`${e}/sync`),r=c(t,`${e}/ast`);if(!n||!r)return;let i=`${n}\0${t}`,a=s.get(i);if(a)return a;let o=await import(n),l=await import(r),u={packageName:e,api:new o.API({cwd:t}),ast:l};return s.set(i,u),u}async function u(e,t){for(let n of t?[t]:o){let t=await l(n,e);if(t)return t}}function d(){for(let{api:e}of s.values())e.close();s.clear()}const f=`runMain`,p=`globalArgs`,m=/^export\s+(default\s+)?/;function h(e,t,n=[]){return t?e.isIdentifier(t)?(n.push(t.text),n):(t.forEachChild(t=>{e.isBindingElement(t)&&h(e,t.name,n)}),n):n}var g=class{ast;sourceFile;imports=/* @__PURE__ */ new Map;declarations=/* @__PURE__ */ new Map;constructor(e,t){this.ast=e,this.sourceFile=t;for(let e of t.statements)this.readStatement(e)}code(e){let{ast:t,sourceFile:n}=this,r=[],i=e=>{t.isImportTypeNode(e)&&t.isLiteralTypeNode(e.argument)&&t.isStringLiteral(e.argument.literal)?r.push({literal:e.argument.literal,dynamic:!1}):t.isCallExpression(e)&&e.expression.kind===t.SyntaxKind.ImportKeyword&&e.arguments[0]!==void 0&&t.isStringLiteral(e.arguments[0])&&r.push({literal:e.arguments[0],dynamic:!0}),e.forEachChild(i)};i(e);let a=[],o=e.getStart(n);for(let{literal:e,dynamic:t}of r.sort((e,t)=>e.literal.pos-t.literal.pos)){let r=e.getStart(n);a.push(n.text.slice(o,r),{specifier:e.text,dynamic:t}),o=e.end}return a.push(n.text.slice(o,e.end)),a}addDeclaration(e,t){for(let n of e)this.declarations.set(n,[...this.declarations.get(n)??[],t])}readStatement(e){let{ast:t,sourceFile:n}=this;if(t.isImportDeclaration(e))this.readImport(e);else if(t.isVariableStatement(e)){let r=e.modifiers?.some(e=>e.kind===t.SyntaxKind.DeclareKeyword),i=e.declarationList,a=i.declarations[0];if(!a)return;let o=n.text.slice(i.getStart(n),a.getStart(n)).trim();for(let e of i.declarations)this.addDeclaration(h(t,e.name),{start:e.getStart(n),code:[`export ${r?`declare `:``}${o} `,...this.code(e),`;`],references:[e.name,e.type,e.initializer].filter(e=>e!==void 0),initializer:t.isIdentifier(e.name)?e.initializer:void 0})}else if(t.isFunctionDeclaration(e)||t.isClassDeclaration(e)||t.isEnumDeclaration(e)||t.isInterfaceDeclaration(e)||t.isTypeAliasDeclaration(e)){let r=e.name;if(!r||!t.isIdentifier(r))return;let[i,...a]=this.code(e);this.addDeclaration([r.text],{start:e.getStart(n),code:[typeof i==`string`?`export ${i.replace(m,``)}`:i,...a],references:[e],initializer:void 0})}}readImport(e){let{ast:t}=this,n=e.importClause;if(!n||!t.isStringLiteral(e.moduleSpecifier))return;let r={specifier:e.moduleSpecifier.text,attributes:e.attributes?this.sourceFile.text.slice(e.attributes.getStart(this.sourceFile),e.attributes.end):void 0},i=n.phaseModifier===t.SyntaxKind.TypeKeyword;n.name&&this.imports.set(n.name.text,{...r,local:n.name.text,imported:`default`,typeOnly:i});let a=n.namedBindings;if(a){if(t.isNamespaceImport(a))this.imports.set(a.name.text,{...r,local:a.name.text,imported:`*`,typeOnly:i});else for(let e of a.elements)this.imports.set(e.name.text,{...r,local:e.name.text,imported:(e.propertyName??e.name).text,typeOnly:i||e.isTypeOnly})}}};function _(e,t){return e!==void 0&&e.pos===t.pos&&e.end===t.end}function v(e,t){let n=t.parent;return e.isShorthandPropertyAssignment(n)?!0:e.isQualifiedName(n)?!_(n.right,t):e.isPropertyAccessExpression(n)?!_(n.name,t):!_(n.name,t)&&!_(n.label,t)&&!_(n.propertyName,t)}function ee(e,t,n){let r=t=>{if(!(e.isFunctionLikeDeclaration(t)||e.isClassDeclaration(t)||e.isClassExpression(t))){if(e.isVariableDeclarationList(t)&&(t.flags&e.NodeFlags.BlockScoped)===0)for(let r of t.declarations)h(e,r.name,n);t.forEachChild(r)}};t.forEachChild(r)}function y(e,t){let n=[],{statements:r,parameters:i,typeParameters:a}=t,o=e.isCaseBlock(t)?t.clauses.flatMap(e=>[...e.statements]):r;e.isFunctionLikeDeclaration(t)&&t.body&&ee(e,t.body,n);for(let t of o??[])if(e.isVariableStatement(t))for(let r of t.declarationList.declarations)h(e,r.name,n);else(e.isFunctionDeclaration(t)||e.isClassDeclaration(t)||e.isEnumDeclaration(t)||e.isInterfaceDeclaration(t)||e.isTypeAliasDeclaration(t))&&t.name!==void 0&&e.isIdentifier(t.name)&&n.push(t.name.text);for(let t of i??[])h(e,t.name,n);for(let e of a??[])n.push(e.name.text);if((e.isFunctionExpression(t)||e.isClassExpression(t))&&t.name&&n.push(t.name.text),e.isMappedTypeNode(t)&&n.push(t.typeParameter.name.text),e.isCatchClause(t)&&t.variableDeclaration&&h(e,t.variableDeclaration.name,n),(e.isForStatement(t)||e.isForInStatement(t)||e.isForOfStatement(t))&&t.initializer!==void 0&&e.isVariableDeclarationList(t.initializer))for(let r of t.initializer.declarations)h(e,r.name,n);return new Set(n)}function te(e,t){let n=/* @__PURE__ */ new Set,r=t=>{e.isInferTypeNode(t)&&n.add(t.typeParameter.name.text),e.isConditionalTypeNode(t)||t.forEachChild(r)};return r(t),n}function b(e,t){let n=/* @__PURE__ */ new Set,r=(t,i)=>{if(e.isIdentifier(t)){v(e,t)&&!i.some(e=>e.has(t.text))&&n.add(t.text);return}if(e.isConditionalTypeNode(t)){let n=[...i,te(e,t.extendsType)];r(t.checkType,i),r(t.extendsType,n),r(t.trueType,n),r(t.falseType,i);return}if(e.isImportTypeNode(t)){r(t.argument,i),t.typeArguments?.forEach(e=>r(e,i));return}let a=y(e,t),o=a.size>0?[...i,a]:i;t.forEachChild(e=>r(e,o))};for(let e of t)r(e,[]);return n}function x(e,t){let n=t;for(;e.isParenthesizedExpression(n)||e.isAsExpression(n)||e.isSatisfiesExpression(n)||e.isNonNullExpression(n);)n=n.expression;return n}function S(e,t){let n=t.name;return n?e.isComputedPropertyName(n)?!0:(e.isIdentifier(n)||e.isStringLiteral(n))&&n.text===p:!1}function C(e,t,n=/* @__PURE__ */ new Set){let{ast:r}=e,i=x(r,t);if(r.isIdentifier(i)){if(n.has(i.text))return;n.add(i.text);let t=e.declarations.get(i.text)?.at(-1)?.initializer;return t&&C(e,t,n)}if(!r.isObjectLiteralExpression(i))return;let a;for(let e of i.properties)r.isSpreadAssignment(e)?a=void 0:r.isShorthandPropertyAssignment(e)&&r.isIdentifier(e.name)&&e.name.text===p?a=e.name:r.isPropertyAssignment(e)&&(r.isIdentifier(e.name)||r.isStringLiteral(e.name))&&e.name.text===p?a=e.initializer:S(r,e)&&(a=void 0);return a}function w(e){let{ast:t}=e,n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set;for(let t of e.imports.values())t.typeOnly||(t.imported===f&&n.add(t.local),t.imported===`*`&&r.add(t.local));let i,a=(o,s)=>{if(i)return;if(t.isCallExpression(o)){let a=o.expression,c=t.isIdentifier(a)&&n.has(a.text)||t.isPropertyAccessExpression(a)&&t.isIdentifier(a.expression)&&r.has(a.expression.text)&&a.name.text===f,l=o.arguments[1]&&x(t,o.arguments[1]),u=l&&t.isIdentifier(l)?l.text:void 0,d=u!==void 0&&s.some(e=>e.has(u)),p=c&&l&&!d&&C(e,l);if(p){i={expression:p,scopes:u===void 0?s:[]};return}}let c=y(t,o),l=c.size>0?[...s,c]:s;o.forEachChild(e=>a(e,l))};return e.sourceFile.forEachChild(e=>a(e,[])),i}function T(e,t){let n=new g(e,t),r=w(n);if(!r)return;let{expression:i,scopes:a}=r,o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Set,l=[...b(e,[i])],u=l.filter(e=>a.some(t=>t.has(e))).sort(),d=l.filter(e=>!u.includes(e));for(;d.length>0;){let t=d.pop();if(!c.has(t)){if(c.add(t),n.imports.has(t))o.add(t);else for(let r of n.declarations.get(t)??[])s.has(r)||(s.add(r),d.push(...b(e,r.references)))}}return{expression:n.code(i),imports:[...n.imports.values()].filter(e=>o.has(e.local)),declarations:[...s].sort((e,t)=>e.start-t.start).map(({code:e})=>e),unresolved:u}}const E=`__polittyGlobalArgsSchema`,D=`__PolittyGlobalArgs`,O=[`type __PolittyKeys<U> = U extends unknown ? keyof U : never;`,`type __PolittyValue<U, K extends PropertyKey> = U extends unknown ? (K extends keyof U ? U[K] : never) : never;`,`type __PolittyIsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;`,`type __PolittyOptionalKeys<U> = U extends unknown ? { [K in keyof U]-?: {} extends Pick<U, K> ? K : never }[keyof U] : never;`,`type __PolittyRequiredKeys<T> = Exclude<keyof T, __PolittyOptionalKeys<T>>;`,`type __PolittyExtendable<T> = true extends __PolittyIsUnion<T>`,` ? { [K in Extract<__PolittyRequiredKeys<T>, PropertyKey>]: __PolittyValue<T, K> } & { [K in Exclude<__PolittyKeys<T>, __PolittyRequiredKeys<T>>]?: __PolittyValue<T, K> }`,` : T;`],k=/^[\p{ID_Start}$_][\p{ID_Continue}$]*$/u,A=/\.d(\.[^.]+)?\.([cm]?)ts$/,j=/\.([cm]?)tsx?$/,M=`export {};
|
|
2
|
+
`;function N(e){let t=e.split(n.sep).join(`/`);return A.test(t)?t.replace(A,(e,t,n)=>t||`.${n}js`):t.replace(j,(e,t)=>`.${t}js`)}function P(e,t,r,i,a){let o=a(e,n.dirname(r),t);return o?o.isExternalLibraryImport&&a(e,i,`esm`)?.resolvedFileName===o.resolvedFileName?e:N(o.resolvedFileName):e}function F(e,t){let n=/* @__PURE__ */ new Map;for(let t of e){let e=`${t.specifier}\0${t.attributes??``}`;n.set(e,[...n.get(e)??[],t])}let r=[];for(let e of n.values()){let{specifier:n,attributes:i}=e[0],a=`from ${JSON.stringify(t(n))}${i?` ${i}`:``};`,o=[],s=e.filter(e=>e.imported!==`*`&&e.imported!=="default"),c=s.length>0&&s.every(e=>e.typeOnly);for(let t of e){let e=t.typeOnly&&!(c&&s.includes(t))?`type `:``;if(t.imported===`*`)r.push(`import ${e}* as ${t.local} ${a}`);else if(t.imported==="default")r.push(`import ${e}${t.local} ${a}`);else{let n=k.test(t.imported)?t.imported:JSON.stringify(t.imported);o.push(`${e}${n===t.local?n:`${n} as ${t.local}`}`)}}o.length>0&&r.push(`import ${c?`type `:``}{ ${o.join(`, `)} } ${a}`)}return r}function I(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=(e,o=n)=>{let s=`${o}\0${e}`,c=a.get(s);return c===void 0&&(c=P(e,o,t,r,i),a.set(s,c)),c},s=e=>e.map(e=>typeof e==`string`?e:JSON.stringify(o(e.specifier,e.dynamic?`esm`:n))).join(``);return[...F(e.imports,e=>o(e)),...e.declarations.map(s),`const ${E} = ${s(e.expression)};`,...O,`type ${D} = __PolittyExtendable<NonNullable<(typeof ${E})["~standard"]["types"]>["output"]>;`,`declare module ${JSON.stringify(`./index.js`)} {`,` interface GlobalArgs extends ${D} {}`,`}`,M].join(`
|
|
3
|
+
`)}function L(e){try{return t.readFileSync(e,`utf8`)}catch{return}}const R=`entry`,z=`compiler`,B=`politty's content mapper needs the "${R}" option in tsconfig.json: the path of the module that calls runMain, relative to tsconfig.json`,V=n.dirname(r(import.meta.url));function H(e){return o.includes(e)}function U(e){let t=(e,t)=>({path:[e],messageText:t,code:2});return Object.entries(e??{}).flatMap(([e,n])=>e===R?typeof n==`string`?[]:[t(e,`"${R}" must be the path of the module that calls runMain, relative to tsconfig.json`)]:e===z?H(n)?[]:[t(e,`"${z}" must be one of ${o.map(e=>`"${e}"`).join(`, `)}`)]:[t(e,`politty's content mapper takes only the "${R}" and "${z}" options`)])}function W(e){let t=e?[e]:o;return`politty's content mapper reads the entry with the TypeScript 7.1 JavaScript API; install ${t.join(` or `)} in the project (${t.map(e=>`${e}/sync`).join(`, `)} was not found)`}const G={commonjs:1,esm:99},K=/* @__PURE__ */ new Set([3,99]),q=/* @__PURE__ */ new Set([100,101,102,199]);function J(e){let{moduleResolution:t,module:n}=e;return typeof t==`number`?K.has(t):typeof n==`number`&&q.has(n)}function Y(e){if(/\.m[jt]sx?$/.test(e))return`esm`;if(/\.c[jt]sx?$/.test(e))return`commonjs`;for(let t=n.dirname(e);;t=n.dirname(t)){let e=L(n.join(t,`package.json`));if(e!==void 0)try{return JSON.parse(e).type===`module`?`esm`:`commonjs`}catch{return`commonjs`}if(n.dirname(t)===t)return`commonjs`}}function X(e,t,n,r,i){let{api:a,ast:o}=e,s=n??a.parseConfigFile(t).options,c=J(s),l=a.createModuleResolver(s),u=a.createSourceFile(r,i);try{let e=T(o,u.sourceFile);if(!e)return{text:M,problem:`${r} has no runMain(command, { globalArgs }) call whose globalArgs the mapper can read; write globalArgs in the options object (or in a top-level const passed as options), with no spread, computed key, or method or accessor named globalArgs after it`,watchedFiles:[r]};if(e.unresolved.length>0){let t=e.unresolved.map(e=>`\`${e}\``).join(`, `);return{text:M,problem:`${r} passes a globalArgs that uses ${t}, which is declared inside a function or block; the mapper copies only top-level declarations, so declare ${e.unresolved.length===1?`it`:`them`} at the top level of the entry (or in a module the entry imports)`,watchedFiles:[r]}}return{text:I(e,r,Y(r),V,(e,t,n)=>l.resolveModuleName(e,t,c?G[n]:void 0).resolvedModule??void 0),problem:void 0,watchedFiles:[r]}}finally{u.dispose(),l.dispose()}}async function Z(e,t,r){let i=t?.[R];if(typeof i!=`string`)return{text:M,problem:B,watchedFiles:[]};let a=n.dirname(e),o=n.resolve(a,i),s=L(o);if(s===void 0)return{text:M,problem:`The entry ${o} cannot be read`,watchedFiles:[o]};let c=t?.[z],l=H(c)?c:void 0,d=await u(a,l);return d?X(d,e,r,o,s):{text:M,problem:W(l),watchedFiles:[o]}}function Q(e=Z){let t=`utf-16`,n=/* @__PURE__ */ new Map,r=(e,n)=>t===`utf-16`?n:Buffer.byteLength(e.slice(0,n));return{initialize(e){let{positionEncodings:n,protocolVersion:r}=e??{};return t=n&&!n.includes(`utf-16`)?`utf-8`:`utf-16`,{...r!==void 0&&{protocolVersion:r},positionEncoding:t,diagnosticSource:`politty`}},async openProject(t){let{configFileName:r,projectHandle:i,options:o,compilerOptions:s}=t,c=await e(r,o,s);return n.set(i,c),{configIdentity:a(`sha256`).update(JSON.stringify([c.text,c.problem??null])).digest(`hex`),watchedFiles:c.watchedFiles,optionDiagnostics:U(o)}},transform(e){let{content:t,projectHandle:i}=e,a=n.get(i),o=a?.text??`export {};
|
|
4
|
+
`,s=a?a.problem:`The project was not opened; restart the TypeScript server`;return{extension:`.ts`,text:o,diagnostics:s===void 0?[]:[{messageText:s,start:0,length:0,code:1}],mappings:[[0,r(o,o.length),0,r(t,t.length),1,24]]}},closeProject(e){return n.delete(e.projectHandle),{}}}}const $=`\r
|
|
5
|
+
\r
|
|
6
|
+
`;async function ne(e,t){let n=Object.hasOwn(e,t.method)?e[t.method]:void 0;if(!n)return{error:{code:-32601,message:`Unknown method: ${t.method}`}};try{let e=await n(t.params);return{result:e===void 0?{}:e}}catch(e){return{error:{code:-32603,message:e instanceof Error?e.message:String(e)}}}}async function re(e,t,n){let r=Buffer.alloc(0);for await(let i of t)for(r=Buffer.concat([r,i]);;){let t=r.indexOf($);if(t<0)break;let i=r.subarray(0,t).toString(`ascii`),a=/Content-Length:\s*(\d+)/i.exec(i)?.[1];if(a===void 0)throw Error(`Malformed JSON-RPC header: ${i}`);let o=t+4,s=o+Number(a);if(r.length<s)break;let c=JSON.parse(r.subarray(o,s).toString(`utf8`));r=r.subarray(s);let l=await ne(e,c);if(c.id===void 0)continue;let u=Buffer.from(JSON.stringify({jsonrpc:`2.0`,id:c.id,...l}));n(Buffer.concat([Buffer.from(`Content-Length: ${u.length}${$}`),u]))}}async function ie(){try{await re(Q(),process.stdin,e=>process.stdout.write(e))}finally{d()}}await ie();export{};
|
package/dist/docs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SubCommandValue, I as ExtractedFields, L as ResolvedFieldMeta, a as ArgsSchema, ft as SchemaLike, r as AnyCommand, u as Example } from "./types-
|
|
1
|
+
import { A as SubCommandValue, I as ExtractedFields, L as ResolvedFieldMeta, a as ArgsSchema, ft as SchemaLike, r as AnyCommand, u as Example } from "./types-mJuR-rBV.js";
|
|
2
2
|
import * as fs$1 from "node:fs";
|
|
3
3
|
/**
|
|
4
4
|
* Resolve a lazy-loaded command (sync or async)
|
package/dist/docs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"./register-ZdhcM-o7.js";import{c as e,n as t,o as n,r,s as i,t as a}from"./schema-extractor-Cwg_WAC-.js";import{t as o}from"./log-collector-uhRWYT-z.js";import{h as s,l as c}from"./unflatten-DVeO9OZ_.js";import{r as l}from"./subcommand-router-
|
|
1
|
+
import"./register-ZdhcM-o7.js";import{c as e,n as t,o as n,r,s as i,t as a}from"./schema-extractor-Cwg_WAC-.js";import{t as o}from"./log-collector-uhRWYT-z.js";import{h as s,l as c}from"./unflatten-DVeO9OZ_.js";import{r as l}from"./subcommand-router-CfCW9eG4.js";import*as u from"node:fs";import d,*as f from"node:path";import{isDeepStrictEqual as p}from"node:util";const m=[`option`,`alias`,`description`,`required`,`default`];function h(e){return`(↔ \`--${e.cliName}\`)`}function g(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function _(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${g(e)}>`}function v(e){let t=_(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:h(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function y(e){return e.map(v)}function b(e){return e.replace(/\r?\n/g,`<br>`)}function x(e){return b(e.replace(/\|/g,`\\|`))}function S(e){return`\`${e}\``}function C(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function ee(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function E(e,t){switch(t){case`option`:{let t=S(e.longFlag);return e.inlineNegation?`${t} / ${S(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(S).join(`, `):`-`;case`description`:return x(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return C(e);case`env`:return ee(e.env)}}function D(e,t){switch(t){case`option`:return S(e.flag);case`description`:return`${x(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function O(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...m,`env`]:m),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>E(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>D(t.negationRow,e)).join(` | `)} |`);return r.join(`
|
|
2
2
|
`)}function k(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.aliases.filter(e=>!e.startsWith(`--`)),r=n.aliases.filter(e=>e.startsWith(`--`)),i=[...e,n.longFlag,...r].map(S).join(`, `);n.inlineNegation&&(i+=` / ${S(n.inlineNegation)}`);let a=n.description?` - ${b(n.description)}`:``,o=n.required?` (required)`:``,s=n.hasDefault?` (default: ${JSON.stringify(n.defaultValue)})`:``,c=w(n.env);t.push(`- ${i}${a}${o}${s}${c}`),n.negationRow&&t.push(`- ${S(n.negationRow.flag)} - ${b(n.negationRow.description)} ${n.negationRow.relationMarker}`)}return t.join(`
|
|
3
3
|
`)}const A=`POLITTY_DOCS_UPDATE`,j=`POLITTY_DOCS_DOCTOR`,M=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],N=`politty:command`;function P(e,t){return`<!-- ${N}:${t}:${e}:start -->`}function F(e,t){return`<!-- ${N}:${t}:${e}:end -->`}const I=`politty:global-options`;function L(){return`<!-- ${I}:start -->`}function te(){return`<!-- ${I}:end -->`}const R=`politty:root-header`;function ne(){return`<!-- ${R}:start -->`}function re(){return`<!-- ${R}:end -->`}const z=`politty:root-footer`;function ie(){return`<!-- ${z}:start -->`}function ae(){return`<!-- ${z}:end -->`}const B=`politty:index`;function V(e){return`<!-- ${B}:${e}:start -->`}function oe(e){return`<!-- ${B}:${e}:end -->`}function se(e){return b(e.replace(/\|/g,`\\|`))}function ce(e){let t=[e.fullCommandPath];e.options.length>0&&t.push(`[options]`),e.subCommands.length>0&&(e.command.run||e.command.defaultSubCommand?t.push(`[command]`):t.push(`<command>`));for(let n of e.positionalArgs)n.required?t.push(`<${n.name}>`):t.push(`[${n.name}]`);return t.join(` `)}function le(e){return fe(e,Ce)}function ue(e){return e.named?`\`${e.name}\`, \`${_(e)}\``:`\`${e.name}\``}function de(e){return fe(e,we)}function fe(e,t,n=e.positionalArgs){let r=pe(e.extracted),i=r.length>0?a(r):void 0,o=new Set(n.map(e=>e.name)),s=[],c=n.filter(e=>i===void 0||i.has(e.name));c.length>0&&s.push(t(c));for(let e of r){let n=e.fields.filter(e=>e.positional&&!i?.has(e.name)&&o.has(e.name));n.length>0&&s.push(`${e.label}\n\n${t(n)}`)}return s.join(`
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ import"./register-ZdhcM-o7.js";import{c as e,n as t,o as n,r,s as i,t as a}from"
|
|
|
18
18
|
`}}const ke={command:e=>W(e),tableStyle:W({optionStyle:`table`}),listStyle:W({optionStyle:`list`})};function Ae(e,t){let n=f.resolve(t);if(!u.existsSync(n))return{match:!1,fileExists:!1};let r=u.readFileSync(n,`utf-8`);return e===r?{match:!0,fileExists:!0}:{match:!1,diff:G(r,e),fileExists:!0}}function G(e,t){let n=e.split(`
|
|
19
19
|
`),r=t.split(`
|
|
20
20
|
`),i=[];i.push(`--- existing`),i.push(`+++ generated`),i.push(``);let a=Math.max(n.length,r.length),o=!1,s=0,c=[],l=()=>{c.length>0&&(i.push(`@@ -${s+1},${c.length} @@`),i.push(...c),c.length=0),o=!1};for(let e=0;e<a;e++){let t=n[e],i=r[e];if(t===i){if(o){c.push(` ${t??``}`);let e=c.findIndex((e,t)=>(e.startsWith(`-`)||e.startsWith(`+`))&&c.slice(t+1).every(e=>e.startsWith(` `)));e!==-1&&c.length-e>3&&l()}}else{if(!o){o=!0,s=e;let t=Math.max(0,e-3);for(let r=t;r<e;r++)c.push(` ${n[r]??``}`)}t!==void 0&&(i===void 0||t!==i)&&c.push(`-${t}`),i!==void 0&&(t===void 0||t!==i)&&c.push(`+${i}`)}}return l(),i.join(`
|
|
21
|
-
`)}function K(e,t){let n=f.resolve(e),r=f.dirname(n);u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(n,t,`utf-8`)}function je(e){let t=f.resolve(e);return u.existsSync(t)?u.readFileSync(t,`utf-8`):null}function Me(e,t=u){let n=f.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,t,n=[]){return Pe(e,t,n,!1)}async function Pe(t,n,a,o){let s=r(t),c=s?e(s):[],u=s?i(s):[],d=[];if(t.subCommands)for(let[e,n]of Object.entries(t.subCommands)){let r=await l(n,e=>o||!!t.requiredPackages?.length||!!e.requiredPackages?.length),i=[...a,e];d.push({name:e,description:r.description,aliases:r.aliases,fullPath:i})}return{name:t.name??``,description:t.description,aliases:t.aliases,fullCommandPath:a.length>0?`${n} ${a.join(` `)}`:n,commandPath:a.join(` `),depth:a.length+1,positionalArgs:c,options:u,subCommands:d,extracted:s,command:t,notes:t.notes,examples:t.examples}}async function Fe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t,a){a||=!!e.requiredPackages?.length;let o=await Pe(e,n,t,a),s=t.join(` `);if(r.set(s,o),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await l(r,e=>a||!!e.requiredPackages?.length),[...t,n],a)}return await i(e,[],!1),r}async function Ie(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Le(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Le(e,t,n){let r=Re(e.cmd),i=[...n,...r],a=o({passthrough:!1});a.start();let s=!0;try{let{runCommand:e}=await import(`./runner-
|
|
21
|
+
`)}function K(e,t){let n=f.resolve(e),r=f.dirname(n);u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(n,t,`utf-8`)}function je(e){let t=f.resolve(e);return u.existsSync(t)?u.readFileSync(t,`utf-8`):null}function Me(e,t=u){let n=f.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,t,n=[]){return Pe(e,t,n,!1)}async function Pe(t,n,a,o){let s=r(t),c=s?e(s):[],u=s?i(s):[],d=[];if(t.subCommands)for(let[e,n]of Object.entries(t.subCommands)){let r=await l(n,e=>o||!!t.requiredPackages?.length||!!e.requiredPackages?.length),i=[...a,e];d.push({name:e,description:r.description,aliases:r.aliases,fullPath:i})}return{name:t.name??``,description:t.description,aliases:t.aliases,fullCommandPath:a.length>0?`${n} ${a.join(` `)}`:n,commandPath:a.join(` `),depth:a.length+1,positionalArgs:c,options:u,subCommands:d,extracted:s,command:t,notes:t.notes,examples:t.examples}}async function Fe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t,a){a||=!!e.requiredPackages?.length;let o=await Pe(e,n,t,a),s=t.join(` `);if(r.set(s,o),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await l(r,e=>a||!!e.requiredPackages?.length),[...t,n],a)}return await i(e,[],!1),r}async function Ie(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Le(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Le(e,t,n){let r=Re(e.cmd),i=[...n,...r],a=o({passthrough:!1});a.start();let s=!0;try{let{runCommand:e}=await import(`./runner-ysBTWTf6.js`),n=await e(t,i);s=n.success,!n.success&&n.error&&console.error(n.error.message)}catch(e){s=!1,console.error(e instanceof Error?e.message:String(e))}finally{a.stop()}let c=a.getLogs(),l=c.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
|
|
22
22
|
`),u=c.entries.filter(e=>e.stream===`stderr`).map(e=>e.message).join(`
|
|
23
23
|
`);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:l,stderr:u,success:s}}function Re(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function ze(e){let t=s();return Object.entries(e).map(([e,n])=>t.resolveFieldMeta(e,n))}function Be(e,t){let n=ze(e).filter(e=>!e.positional);return n.length===0?``:O(y(n),t?.columns)}function Ve(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function He(e){return e.replace(/\s+/g,`-`).toLowerCase()}function Ue(e){return e.subCommands.length===0}function We(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function Ge(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(Ue(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(Ue(a)||!n)&&r.push(e)}}return r}function Ke(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:Ge(e.commands,t,r),s=o,c=/* @__PURE__ */ new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>We(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!Ue(i))continue;let o=n||i.name,s=He(o),l=Ve(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
|
|
24
24
|
`)}async function qe(e,t,n){let r=n?.headingLevel??3,i=n?.leafOnly??!0,a=await Fe(e),o=[];for(let e of t){let t=Ke(e,a,r,i);o.push(t)}return o.join(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as createDynamicCompleteCommand}from"./dynamic-D9Y4kkfj.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./command-
|
|
1
|
+
import{n as e}from"./command-CCiN78NV.js";import{c as t,i as n}from"./subcommand-router-CfCW9eG4.js";import{a as r,n as i,u as a}from"./schema-extractor-Cwg_WAC-.js";import{n as o,o as s,r as c,s as l,u}from"./argv-parser-bI3e6XXA.js";import{d,p as f}from"./unflatten-DVeO9OZ_.js";import{t as p}from"./schema-BF9YOHU0.js";import{execSync as m}from"node:child_process";function h(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:_(e.valueCompletion,e.isGlobal===!0,t,n)}}function g(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:_(e.valueCompletion,!1,t,n)}}function _(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function v(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
|
|
2
2
|
`?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function y(e){return`'${e.replace(/'/g,`'\\''`)}'`}function b(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function x(e){return e.length===1?`-${e}`:`--${e}`}function S(e,t){C(e,x(t)),t.length===1?C(e,`--${t}`):t.includes(`-`)&&C(e,`--${f(t)}`)}function C(e,t){e.includes(t)||e.push(t)}function w(e,t){let n=[`--${e}`];e.length===1&&n.push(`-${e}`),e.includes(`-`)&&n.push(`--${f(e)}`);for(let e of t??[])S(n,e);return n}function T(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function E(e,t,n,r){let i=new Set(w(e,t));if(n&&(i.add(`--${n}`),n.includes(`-`)&&i.add(`--${f(n)}`)),r?.frameOptions){if(r.isGlobal===!0){for(let e of r.frameOptions)if(e.isGlobal!==!0)for(let t of A(e.cliName,e.alias))i.delete(t)}else{let e=T(r.frameOptions);if(e.size>0){let n=new Set((t??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let t of e)n.has(t)||i.delete(t)}}}return[...i].map(e=>`"${e}"`)}function D(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&E(n.cliName,n.alias,n.negation,{frameOptions:t})})}function O(e,t,n,r=`$_pos_count`){let i=D(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function k(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of O(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function A(e,t){let n=[`--${e}`];e.includes(`-`)&&n.push(`--${f(e)}`);for(let e of t??[])S(n,e);return n}function j(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function M(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?N(e.args):[]}function N(e){return r(i(e)).map(P)}function P(e){let t=d(e);return{name:e.name,cliName:e.cliName,alias:t.length>0?t:void 0,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:e.type===`boolean`&&e.negation===!0,valueCompletion:M(j(e))}}function F(e){return new Set(w(e.cliName,e.alias))}function te(e,t){let n=F(t);for(let t of e)for(let e of F(t))if(n.has(e))return t}function ne(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{G(n,e,t,i),r.add(e.name)},s=0;for(;s<e.length;){let i=e[s];if(i===`--`||!i.startsWith(`-`))break;if(c(i)){let{isGlobal:c,flags:l,valueOption:u}=z(i,t);if(!c)break;for(let{opt:e}of l)n[e.name]=!0,r.add(e.name);if(u?.value!==void 0)a(u.opt,u.value);else if(u){let t=e[s+1];if(t===void 0)break;o(t)&&(a(u.opt,t),s++)}s++;continue}if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let l=R(i),u=q(t,l);if(!u){if(de(t,l)){s++;continue}break}if(u.takesValue){if(B(i)){let e=i.indexOf(`=`);a(u,i.slice(e+1)),s++}else if(s+1<e.length){let t=e[s+1];if(!o(t)){s++;continue}a(u,t),s+=2}else break}else{let e=V(u,l,i);e!==void 0&&(n[u.name]=e),r.add(u.name),s++}}return r}function re(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function ie(e,t){return t.length===0?e:[...e,...t]}function ae(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function I(e,t){return n=>{let r={...e};return s(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function oe(e,t,n){if(!e.args)return;let r=i(e.args),o=a(r,I(t,n));if(o!==r)return o.fields.filter(e=>e.named).map(P)}function se(e,t,n){if(!e.args)return[];let r=a(i(e.args),I(t,n));return s(r,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:M(j(e))}))}function ce(e){if(!e.subCommands)return[];let n=[];for(let[r,i]of Object.entries(e.subCommands)){if(r.startsWith(`__`))continue;n.push(r);let e=t(i);e?.aliases&&n.push(...e.aliases)}return n}function le(e,r){if(!e.subCommands)return null;let i=Object.hasOwn(e.subCommands,r)?e.subCommands[r]:void 0;if(i)return t(i);let a=n(e,r);return a?t(e.subCommands[a]):null}function L(e){return e.startsWith(`-`)}function R(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function z(e,t){let n=(e,t)=>q(e,{name:t,isLong:!1}),r=t.filter(e=>e.isGlobal!==!0),i=t.filter(e=>e.isGlobal===!0),a=e=>!n(r,e)&&n(i,e)!==void 0,o=l(e.slice(1),e=>a(e)&&n(i,e).takesValue),s=o.flags.every(a),c=s?i:r,{flags:u,valueOption:d}=s?o:l(e.slice(1),e=>n(r,e)?.takesValue===!0);return{isGlobal:s,flags:u.flatMap(e=>{let t=n(c,e);return t?[{opt:t,name:e}]:[]}),valueOption:d&&{opt:n(c,d.name),value:d.value}}}function ue(e,t){let{valueOption:n}=z(e,t);return n?.value===void 0?n?.opt:void 0}function B(e){return e.includes(`=`)}function V(e,t,n){let r=fe(e,t);return B(n)?r?void 0:u(n.slice(n.indexOf(`=`)+1)):!r}function H(e,t,n){if(!n||e.valueType!==`boolean`)return!1;let r=[e.cliName,...e.alias??[]];for(let e of r){let n=`no-${e}`;if(t===n||t===f(n))return!0}return!1}function U(e,t,n){return e.defaultNegationAccepted===!0&&H(e,t,n)}function de(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&H(e,t.name,t.isLong))}function W(e,t){return e!==void 0&&e.includes(`-`)&&f(e)===t}function G(e,t,n,r){if(t.valueType!==`array`)e[t.name]=n;else if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function fe(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||W(e.negation,t.name))?!0:U(e,t.name,t.isLong):!1}function K(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:W(e.cliName,t)||e.alias?.some(e=>W(e,t))?!0:W(e.negation,t)}function q(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&K(e,t.name,t.isLong));if(r)return r}return e.find(e=>K(e,t.name,t.isLong))||e.find(e=>U(e,t.name,t.isLong))}function J(e,t,n){let r=Y(e,t,n);return r.variantOptions?Y(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function Y(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,s=[],l=n?N(n).map(e=>({...e,isGlobal:!0})):[],u=/* @__PURE__ */ new Set,d=!1,f=0,p={},m=[],h={},g=/* @__PURE__ */ new Set,_=0,v=/* @__PURE__ */ new Set,y=e=>{u.add(e.cliName);for(let t of e.alias??[])u.add(t);e.negation&&u.add(e.negation),d=!0},b=(e,t)=>{G(e.isGlobal===!0?h:p,e,t,v)},x=(e,t,n=``)=>{let r=e.isGlobal===!0?h:p,i=V(e,t,n);i!==void 0&&(r[e.name]=i)},S=0,C=ie(i(a),l),w=!1;for(;S<e.length-1;){let t=e[S];if(!w&&t===`--`){w=!0,S++;continue}if(!w&&c(t)){d=!0;let{flags:n,valueOption:r}=z(t,C);for(let{opt:e,name:t}of n)y(e),x(e,{name:t,isLong:!1});r&&(y(r.opt),r.value===void 0?S+1<e.length-1&&o(e[S+1])&&(b(r.opt,e[S+1]),S++):b(r.opt,r.value)),S++;continue}if(!w&&L(t)){d=!0;let n=R(t),r=q(C,n);if(r){if(y(r),r.takesValue){if(B(t)){let e=t.indexOf(`=`);b(r,t.slice(e+1))}else if(S+1<e.length-1){let t=e[S+1];o(t)&&(b(r,t),S++)}}else x(r,n,t)}S++;continue}let n=w?null:le(a,t);if(n){s.push(t);let r=i(a),o=e.slice(_,S);for(let e of ne(o,l,h))g.add(e);a=n,C=ie(i(a),l);for(let e of Object.keys(p)){let t=r.find(t=>t.name===e),n=l.find(t=>t.name===e)??(t?te(l,t):void 0);n&&(g.has(n.name)||(h[n.name]=re(p[e],n)))}u.clear(),f=0,p={},m=[],v=/* @__PURE__ */ new Set,_=S+1,S++}else m.push(t),f++,S++}let T=e[e.length-1]??``,E=e[e.length-2]??``,D=oe(a,p,m),O=se(a,p,m),k=ce(a);for(let e=0;e<O.length;e++){let t=O[e];if(t.variadic){p[t.name]=m.slice(e);break}e<m.length&&(p[t.name]=m[e])}let A,j,M;if(!w&&E&&L(E)&&!B(E)){let e=c(E)?ue(E,C):q(C,R(E));e&&e.takesValue?(A=`option-value`,j=e):T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f),A===`positional`&&(M=f))}else if(!w&&T.startsWith(`-`)&&B(T)){let e=q(C,R(T));e&&e.takesValue?(A=`option-value`,j=e):A=`option-name`}else!w&&T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f,w),A===`positional`&&(M=f));let P=[];if(j){if(j.valueType===`array`){let e=(j.isGlobal===!0?h:p)[j.name];P=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(A===`positional`&&M!==void 0){let e=ae(M,O);e!==void 0&&O[e]?.variadic&&(P=m.slice(e))}let F={...h,...p};return{context:{subcommandPath:s,currentCommand:a,currentWord:T,previousWord:E,completionType:A,targetOption:j,positionalIndex:M,options:C,subcommands:k,positionals:O,usedOptions:u,hasAnyOptionBeenUsed:d,providedPositionalCount:f,parsedArgs:F,previousValues:P},variantOptions:D}}function X(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const Z={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function pe(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function me(e,t){switch(e.completionType){case`subcommand`:return we(e);case`option-name`:return Te(e);case`option-value`:{let n=e.targetOption,r=n?pe(e.currentWord):void 0;return Q(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=he(e);return n?Q(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:Z.NoFileCompletion}}}}function he(e){let t=e.positionalIndex??0,n=ae(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function ge(e){try{return m(e,{encoding:`utf-8`,timeout:5e3}).split(`
|
|
3
3
|
`).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function _e(e){return e?.type===`choices`?e.choices:void 0}function ve(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return _e(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return _e(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function ye(e,t){let n=!t.includes(`=`),r=n?be(e):xe(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function be(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function xe(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function Se(e,t,n,r,i){let a=[],o=Z.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=Z.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=Z.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=Z.FileCompletion)):o|=Z.FileCompletion;break;case`directory`:o|=Z.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...ge(e.shellCommand)),o|=Z.NoFileCompletion;break;case`none`:o|=Z.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??Z.FilterPrefix|Z.NoFileCompletion}catch{o=Z.NoFileCompletion|Z.Error}break;case`expand`:o|=Z.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=ve(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=/* @__PURE__ */ new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=Z.NoFileCompletion|Z.Error;break}o|=Z.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=ye(e.type===`runtime-expand`&&i===!0?Ce(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=Z.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function Ce(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function we(e){let r=[];for(let i of e.subcommands){let a=e.currentCommand.subCommands,o=a?.[i],s=o?void 0:n(e.currentCommand,i),c=o??(s?a?.[s]:void 0),l=c?t(c)?.description:void 0;r.push({value:i,description:l,type:`subcommand`})}if(r.length===0||e.currentWord.startsWith(`-`)){let t=Te(e);r.push(...t.candidates)}return{candidates:r,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Te(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Ee(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:De(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function De(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function Q(e,t,n,r,i,a){return r?Se(r,Ee(e,t,n),e,i,a):{candidates:[],directive:Z.FilterPrefix}}function Oe(e,t){switch(t.shell){case`bash`:return ke(e,t);case`zsh`:return Ae(e,t);case`fish`:return je(e,t)}}function $(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function ke(e,t){let n=((e.directive&Z.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return $(n,e),n.join(`
|
|
4
4
|
`)}function Ae(e,t){let n=e.candidates.map(e=>{let t=e.value.replace(/:/g,`\\:`);return e.description?`${t}:${e.description.replace(/:/g,`\\:`)}`:t});return $(n,e),n.join(`
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// TypeScript does not read this file. politty's content mapper derives GlobalArgs from the
|
|
2
|
+
// globalArgs schema your entry passes to runMain, so commands get typed global args without
|
|
3
|
+
// createDefineCommand or a hand-written `declare module` augmentation.
|
|
4
|
+
// Enable it in tsconfig.json: "contentMappers": [{ "package": "<this package>", "extensions": [".politty"] }]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as resolve}from"./import-meta-resolve-DQM0bLBb.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{builtinModules as e}from"node:module";import t,{realpathSync as n,statSync as r}from"node:fs";import i from"node:path";import{fileURLToPath as a,pathToFileURL as o}from"node:url";import{format as s,inspect as c}from"node:util";import l from"node:assert";import u from"node:process";import d from"node:v8";const f={}.hasOwnProperty,ee=/^([A-Z][a-z\d]*)+$/,te=/* @__PURE__ */ new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),p={};function m(e,t=`and`){return e.length<3?e.join(` ${t} `):`${e.slice(0,-1).join(`, `)}, ${t} ${e[e.length-1]}`}const h=/* @__PURE__ */ new Map;let g;p.ERR_INVALID_ARG_TYPE=_(`ERR_INVALID_ARG_TYPE`,(e,t,n)=>{l.ok(typeof e==`string`,`'name' must be a string`),Array.isArray(t)||(t=[t]);let r=`The `;if(e.endsWith(` argument`))r+=`${e} `;else{let t=e.includes(`.`)?`property`:`argument`;r+=`"${e}" ${t} `}r+=`must be `;let i=[],a=[],o=[];for(let e of t)l.ok(typeof e==`string`,`All expected entries have to be of type string`),te.has(e)?i.push(e.toLowerCase()):ee.exec(e)===null?(l.ok(e!==`object`,`The value "object" should be written as "Object"`),o.push(e)):a.push(e);if(a.length>0){let e=i.indexOf(`object`);e!==-1&&(i.slice(e,1),a.push(`Object`))}return i.length>0&&(r+=`${i.length>1?`one of type`:`of type`} ${m(i,`or`)}`,(a.length>0||o.length>0)&&(r+=` or `)),a.length>0&&(r+=`an instance of ${m(a,`or`)}`,o.length>0&&(r+=` or `)),o.length>0&&(o.length>1?r+=`one of ${m(o,`or`)}`:(o[0].toLowerCase()!==o[0]&&(r+=`an `),r+=`${o[0]}`)),r+=`. Received ${y(n)}`,r},TypeError),p.ERR_INVALID_MODULE_SPECIFIER=_(`ERR_INVALID_MODULE_SPECIFIER`,(e,t,n=void 0)=>`Invalid module "${e}" ${t}${n?` imported from ${n}`:``}`,TypeError),p.ERR_INVALID_PACKAGE_CONFIG=_(`ERR_INVALID_PACKAGE_CONFIG`,(e,t,n)=>`Invalid package config ${e}${t?` while importing ${t}`:``}${n?`. ${n}`:``}`,Error),p.ERR_INVALID_PACKAGE_TARGET=_(`ERR_INVALID_PACKAGE_TARGET`,(e,t,n,r=!1,i=void 0)=>{let a=typeof n==`string`&&!r&&n.length>0&&!n.startsWith(`./`);return t===`.`?(l.ok(r===!1),`Invalid "exports" main target ${JSON.stringify(n)} defined in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`):`Invalid "${r?`imports`:`exports`}" target ${JSON.stringify(n)} defined for '${t}' in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`},Error),p.ERR_MODULE_NOT_FOUND=_(`ERR_MODULE_NOT_FOUND`,(e,t,n=!1)=>`Cannot find ${n?`module`:`package`} '${e}' imported from ${t}`,Error),p.ERR_NETWORK_IMPORT_DISALLOWED=_(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error),p.ERR_PACKAGE_IMPORT_NOT_DEFINED=_(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(e,t,n)=>`Package import specifier "${e}" is not defined${t?` in package ${t}package.json`:``} imported from ${n}`,TypeError),p.ERR_PACKAGE_PATH_NOT_EXPORTED=_(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(e,t,n=void 0)=>t===`.`?`No "exports" main defined in ${e}package.json${n?` imported from ${n}`:``}`:`Package subpath '${t}' is not defined by "exports" in ${e}package.json${n?` imported from ${n}`:``}`,Error),p.ERR_UNSUPPORTED_DIR_IMPORT=_(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),p.ERR_UNSUPPORTED_RESOLVE_REQUEST=_(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),p.ERR_UNKNOWN_FILE_EXTENSION=_(`ERR_UNKNOWN_FILE_EXTENSION`,(e,t)=>`Unknown file extension "${e}" for ${t}`,TypeError),p.ERR_INVALID_ARG_VALUE=_(`ERR_INVALID_ARG_VALUE`,(e,t,n=`is invalid`)=>{let r=c(t);return r.length>128&&(r=`${r.slice(0,128)}...`),`The ${e.includes(`.`)?`property`:`argument`} '${e}' ${n}. Received ${r}`},TypeError);function _(e,t,n){return h.set(e,t),ne(n,e)}function ne(e,t){return n;function n(...n){let r=Error.stackTraceLimit;v()&&(Error.stackTraceLimit=0);let i=new e;v()&&(Error.stackTraceLimit=r);let a=ae(t,n,i);return Object.defineProperties(i,{message:{value:a,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),ie(i),i.code=t,i}}function v(){try{if(d.startupSnapshot.isBuildingSnapshot())return!1}catch{}let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):f.call(e,`writable`)&&e.writable!==void 0?e.writable:e.set!==void 0}function re(e){let t=`__node_internal_`+e.name;return Object.defineProperty(e,"name",{value:t}),e}const ie=re(function(e){let t=v();return t&&(g=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(e),t&&(Error.stackTraceLimit=g),e});function ae(e,t,n){let r=h.get(e);if(l.ok(r!==void 0,"expected `message` to be found"),typeof r==`function`)return l.ok(r.length<=t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${r.length}).`),Reflect.apply(r,n,t);let i=/%[dfijoOs]/g,a=0;for(;i.exec(r)!==null;)a++;return l.ok(a===t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${a}).`),t.length===0?r:(t.unshift(r),Reflect.apply(s,null,t))}function y(e){if(e==null)return String(e);if(typeof e==`function`&&e.name)return`function ${e.name}`;if(typeof e==`object`)return e.constructor&&e.constructor.name?`an instance of ${e.constructor.name}`:`${c(e,{depth:-1})}`;let t=c(e,{colors:!1});return t.length>28&&(t=`${t.slice(0,25)}...`),`type ${typeof e} (${t})`}const b={}.hasOwnProperty,{ERR_INVALID_PACKAGE_CONFIG:oe}=p,x=/* @__PURE__ */ new Map;function S(e,{base:n,specifier:r}){let o=x.get(e);if(o)return o;let s;try{s=t.readFileSync(i.toNamespacedPath(e),`utf8`)}catch(e){let t=e;if(t.code!==`ENOENT`)throw t}let c={exists:!1,pjsonPath:e,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(s!==void 0){let t;try{t=JSON.parse(s)}catch(t){let i=t,o=new oe(e,(n?`"${r}" from `:``)+a(n||r),i.message);throw o.cause=i,o}c.exists=!0,b.call(t,`name`)&&typeof t.name==`string`&&(c.name=t.name),b.call(t,`main`)&&typeof t.main==`string`&&(c.main=t.main),b.call(t,`exports`)&&(c.exports=t.exports),b.call(t,`imports`)&&(c.imports=t.imports),b.call(t,`type`)&&(t.type===`commonjs`||t.type===`module`)&&(c.type=t.type)}return x.set(e,c),c}function C(e){let t=new URL(`package.json`,e);for(;!t.pathname.endsWith(`node_modules/package.json`);){let n=S(a(t),{specifier:e});if(n.exists)return n;let r=t;if(t=new URL(`../package.json`,t),t.pathname===r.pathname)break}return{pjsonPath:a(t),exists:!1,type:`none`}}function w(e){return C(e).type}const{ERR_UNKNOWN_FILE_EXTENSION:se}=p,ce={}.hasOwnProperty,le={__proto__:null,".cjs":`commonjs`,".js":`module`,".json":`json`,".mjs":`module`};function ue(e){return e&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(e)?`module`:e===`application/json`?`json`:null}const T={__proto__:null,"data:":de,"file:":pe,"http:":E,"https:":E,"node:"(){return`builtin`}};function de(e){let{1:t}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(e.pathname)||[null,null,null];return ue(t)}function fe(e){let t=e.pathname,n=t.length;for(;n--;){let e=t.codePointAt(n);if(e===47)return``;if(e===46)return t.codePointAt(n-1)===47?``:t.slice(n)}return``}function pe(e,t,n){let r=fe(e);if(r===`.js`){let t=w(e);return t===`none`?`commonjs`:t}if(r===``){let t=w(e);return t===`none`||t===`commonjs`?`commonjs`:`module`}let i=le[r];if(i)return i;if(n)return;let o=a(e);throw new se(r,o)}function E(){}function D(e,t){let n=e.protocol;return ce.call(T,n)&&T[n](e,t,!0)||null}const{ERR_INVALID_ARG_VALUE:me}=p,O=Object.freeze([`node`,`import`]),he=new Set(O);function ge(){return O}function _e(){return he}function k(e){if(e!==void 0&&e!==ge()){if(!Array.isArray(e))throw new me(`conditions`,e,`expected an array`);return new Set(e)}return _e()}const A=RegExp.prototype[Symbol.replace],{ERR_NETWORK_IMPORT_DISALLOWED:j,ERR_INVALID_MODULE_SPECIFIER:M,ERR_INVALID_PACKAGE_CONFIG:N,ERR_INVALID_PACKAGE_TARGET:ve,ERR_MODULE_NOT_FOUND:P,ERR_PACKAGE_IMPORT_NOT_DEFINED:F,ERR_PACKAGE_PATH_NOT_EXPORTED:ye,ERR_UNSUPPORTED_DIR_IMPORT:be,ERR_UNSUPPORTED_RESOLVE_REQUEST:I}=p,L={}.hasOwnProperty,R=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,z=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,xe=/^\.|%|\\/,B=/\*/g,Se=/%2f|%5c/i,V=/* @__PURE__ */ new Set,Ce=/[/\\]{2}/;function H(e,t,n,r,i,o,s){if(u.noDeprecation)return;let c=a(r),l=Ce.exec(s?e:t)!==null;u.emitWarning(`Use of deprecated ${l?`double slash`:`leading or trailing slash matching`} resolving "${e}" for module request "${t}" ${t===n?``:`matched to "${n}" `}in the "${i?`imports`:`exports`}" field module resolution of the package at ${c}${o?` imported from ${a(o)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function U(e,t,n,r){if(u.noDeprecation||D(e,{parentURL:n.href})!==`module`)return;let o=a(e.href),s=a(new URL(`.`,t)),c=a(n);r?i.resolve(s,r)!==o&&u.emitWarning(`Package ${s} has a "main" field set to "${r}", excluding the full filename and extension to the resolved file at "${o.slice(s.length)}", imported from ${c}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):u.emitWarning(`No "main" or "exports" field defined in the package.json for ${s} resolving the main entry point "${o.slice(s.length)}", imported from ${c}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function W(e){try{return r(e)}catch{}}function G(e){let t=r(e,{throwIfNoEntry:!1});return(t?t.isFile():void 0)??!1}function we(e,t,n){let r;if(t.main!==void 0){if(r=new URL(t.main,e),G(r))return r;let i=[`./${t.main}.js`,`./${t.main}.json`,`./${t.main}.node`,`./${t.main}/index.js`,`./${t.main}/index.json`,`./${t.main}/index.node`],a=-1;for(;++a<i.length&&(r=new URL(i[a],e),!G(r));)r=void 0;if(r)return U(r,e,n,t.main),r}let i=[`./index.js`,`./index.json`,`./index.node`],o=-1;for(;++o<i.length&&(r=new URL(i[o],e),!G(r));)r=void 0;if(r)return U(r,e,n,t.main),r;throw new P(a(new URL(`.`,e)),a(n))}function Te(e,t,r){if(Se.exec(e.pathname)!==null)throw new M(e.pathname,`must not include encoded "/" or "\\" characters`,a(t));let s;try{s=a(e)}catch(n){let r=n;throw Object.defineProperty(r,"input",{value:String(e)}),Object.defineProperty(r,"module",{value:String(t)}),r}let c=W(s.endsWith(`/`)?s.slice(-1):s);if(c&&c.isDirectory()){let n=new be(s,a(t));throw n.url=String(e),n}if(!c||!c.isFile()){let n=new P(s||e.pathname,t&&a(t),!0);throw n.url=String(e),n}if(!r){let t=n(s),{search:r,hash:a}=e;e=o(t+(s.endsWith(i.sep)?`/`:``)),e.search=r,e.hash=a}return e}function Ee(e,t,n){return new F(e,t&&a(new URL(`.`,t)),a(n))}function K(e,t,n){return new ye(a(new URL(`.`,t)),e,n&&a(n))}function De(e,t,n,r,i){let o=`request is not a valid match in pattern "${t}" for the "${r?`imports`:`exports`}" resolution of ${a(n)}`;throw new M(e,o,i&&a(i))}function q(e,t,n,r,i){return t=typeof t==`object`&&t?JSON.stringify(t,null,``):`${t}`,new ve(a(new URL(`.`,n)),e,t,r,i&&a(i))}function Oe(e,t,n,r,i,a,o,s,c){if(t!==``&&!a&&e[e.length-1]!==`/`)throw q(n,e,r,o,i);if(!e.startsWith(`./`)){if(o&&!e.startsWith(`../`)&&!e.startsWith(`/`)){let n=!1;try{new URL(e),n=!0}catch{}if(!n)return Z(a?A.call(B,e,()=>t):e+t,r,c)}throw q(n,e,r,o,i)}if(R.exec(e.slice(2))!==null){if(z.exec(e.slice(2))===null){if(!s){let s=a?n.replace(`*`,()=>t):n+t;H(a?A.call(B,e,()=>t):e,s,n,r,o,i,!0)}}else throw q(n,e,r,o,i)}let l=new URL(e,r),u=l.pathname,d=new URL(`.`,r).pathname;if(!u.startsWith(d))throw q(n,e,r,o,i);if(t===``)return l;if(R.exec(t)!==null){let c=a?n.replace(`*`,()=>t):n+t;z.exec(t)===null?s||H(a?A.call(B,e,()=>t):e,c,n,r,o,i,!1):De(c,n,r,o,i)}return a?new URL(A.call(B,l.href,()=>t)):new URL(t,l)}function ke(e){let t=Number(e);return`${t}`===e&&t>=0&&t<4294967295}function J(e,t,n,r,i,o,s,c,l){if(typeof t==`string`)return Oe(t,n,r,e,i,o,s,c,l);if(Array.isArray(t)){let a=t;if(a.length===0)return null;let u,d=-1;for(;++d<a.length;){let t=a[d],f;try{f=J(e,t,n,r,i,o,s,c,l)}catch(e){let t=e;if(u=t,t.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw e}if(f!==void 0){if(f===null)u=null;else return f}}if(u==null)return null;throw u}if(typeof t==`object`&&t){let u=Object.getOwnPropertyNames(t),d=-1;for(;++d<u.length;){let t=u[d];if(ke(t))throw new N(a(e),i,`"exports" cannot contain numeric property keys.`)}for(d=-1;++d<u.length;){let a=u[d];if(a==="default"||l&&l.has(a)){let u=t[a],d=J(e,u,n,r,i,o,s,c,l);if(d===void 0)continue;return d}}return null}if(t===null)return null;throw q(r,t,e,s,i)}function Ae(e,t,n){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let r=Object.getOwnPropertyNames(e),i=!1,o=0,s=-1;for(;++s<r.length;){let e=r[s],c=e===``||e[0]!==`.`;if(o++===0)i=c;else if(i!==c)throw new N(a(t),n,`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return i}function je(e,t,n){if(u.noDeprecation)return;let r=a(t);V.has(r+`|`+e)||(V.add(r+`|`+e),u.emitWarning(`Use of deprecated trailing slash pattern mapping "${e}" in the "exports" field module resolution of the package at ${r}${n?` imported from ${a(n)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function Y(e,t,n,r,i){let a=n.exports;if(Ae(a,e,r)&&(a={".":a}),L.call(a,t)&&!t.includes(`*`)&&!t.endsWith(`/`)){let n=a[t],o=J(e,n,``,t,r,!1,!1,!1,i);if(o==null)throw K(t,e,r);return o}let o=``,s=``,c=Object.getOwnPropertyNames(a),l=-1;for(;++l<c.length;){let n=c[l],i=n.indexOf(`*`);if(i!==-1&&t.startsWith(n.slice(0,i))){t.endsWith(`/`)&&je(t,e,r);let a=n.slice(i+1);t.length>=n.length&&t.endsWith(a)&&X(o,n)===1&&n.lastIndexOf(`*`)===i&&(o=n,s=t.slice(i,t.length-a.length))}}if(o){let n=a[o],c=J(e,n,s,o,r,!0,!1,t.endsWith(`/`),i);if(c==null)throw K(t,e,r);return c}throw K(t,e,r)}function X(e,t){let n=e.indexOf(`*`),r=t.indexOf(`*`),i=n===-1?e.length:n+1,a=r===-1?t.length:r+1;return i>a?-1:a>i||n===-1?1:r===-1||e.length>t.length?-1:+(t.length>e.length)}function Me(e,t,n){if(e===`#`||e.startsWith(`#/`)||e.endsWith(`/`))throw new M(e,`is not a valid internal imports specifier name`,a(t));let r,i=C(t);if(i.exists){r=o(i.pjsonPath);let a=i.imports;if(a){if(L.call(a,e)&&!e.includes(`*`)){let i=J(r,a[e],``,e,t,!1,!0,!1,n);if(i!=null)return i}else{let i=``,o=``,s=Object.getOwnPropertyNames(a),c=-1;for(;++c<s.length;){let t=s[c],n=t.indexOf(`*`);if(n!==-1&&e.startsWith(t.slice(0,-1))){let r=t.slice(n+1);e.length>=t.length&&e.endsWith(r)&&X(i,t)===1&&t.lastIndexOf(`*`)===n&&(i=t,o=e.slice(n,e.length-r.length))}}if(i){let e=a[i],s=J(r,e,o,i,t,!0,!0,!1,n);if(s!=null)return s}}}}throw Ee(e,r,t)}function Ne(e,t){let n=e.indexOf(`/`),r=!0,i=!1;e[0]===`@`&&(i=!0,n===-1||e.length===0?r=!1:n=e.indexOf(`/`,n+1));let o=n===-1?e:e.slice(0,n);if(xe.exec(o)!==null&&(r=!1),!r)throw new M(e,`is not a valid package name`,a(t));return{packageName:o,packageSubpath:`.`+(n===-1?``:e.slice(n)),isScoped:i}}function Z(t,n,r){if(e.includes(t))return new URL(`node:`+t);let{packageName:i,packageSubpath:s,isScoped:c}=Ne(t,n),l=C(n);
|
|
2
|
+
/* c8 ignore next 16 */
|
|
3
|
+
if(l.exists){let e=o(l.pjsonPath);if(l.name===i&&l.exports!==void 0&&l.exports!==null)return Y(e,s,l,n,r)}let u=new URL(`./node_modules/`+i+`/package.json`,n),d=a(u),f;do{let e=W(d.slice(0,-13));if(!e||!e.isDirectory()){f=d,u=new URL((c?`../../../../node_modules/`:`../../../node_modules/`)+i+`/package.json`,u),d=a(u);continue}let o=S(d,{base:n,specifier:t});return o.exports!==void 0&&o.exports!==null?Y(u,s,o,n,r):s===`.`?we(u,o,n):new URL(s,u)}while(d.length!==f.length);throw new P(i,a(n),!1)}function Pe(e){return!(e[0]!==`.`||e.length!==1&&e[1]!==`/`&&(e[1]!==`.`||e.length!==2&&e[2]!==`/`))}function Q(e){return e===``?!1:e[0]===`/`||Pe(e)}function $(t,n,r,i){r===void 0&&(r=k());let a=n.protocol,o=a===`data:`||a===`http:`||a===`https:`,s;if(Q(t))try{s=new URL(t,n)}catch(e){let r=new I(t,n);throw r.cause=e,r}else if(a===`file:`&&t[0]===`#`)s=Me(t,n,r);else try{s=new URL(t)}catch(i){if(o&&!e.includes(t)){let e=new I(t,n);throw e.cause=i,e}s=Z(t,n,r)}return l.ok(s!==void 0,`expected to be defined`),s.protocol===`file:`?Te(s,n,i):s}function Fe(t,n,r){if(r){let i=r.protocol;if(i===`http:`||i===`https:`){if(Q(t)){let e=n?.protocol;if(e&&e!==`https:`&&e!==`http:`)throw new j(t,r,`remote imports cannot import from a local location.`);return{url:n?.href||``}}throw e.includes(t)?new j(t,r,`remote imports cannot import from a local location.`):new j(t,r,`only relative and absolute specifiers are supported.`)}}}function Ie(e){return!!(e&&typeof e==`object`&&`href`in e&&typeof e.href==`string`&&`protocol`in e&&typeof e.protocol==`string`&&e.href&&e.protocol)}function Le(e){if(e!==void 0&&typeof e!=`string`&&!Ie(e))throw new p.ERR_INVALID_ARG_TYPE(`parentURL`,[`string`,`URL`],e)}function Re(e,t={}){let{parentURL:n}=t;l.ok(n!==void 0,"expected `parentURL` to be defined"),Le(n);let r;if(n)try{r=new URL(n)}catch{}let i,a;try{if(i=Q(e)?new URL(e,r):new URL(e),a=i.protocol,a===`data:`)return{url:i.href,format:null}}catch{}let o=Fe(e,i,r);if(o)return o;if(a===void 0&&i&&(a=i.protocol),a===`node:`||i&&i.protocol===`node:`)return{url:e};let s=k(t.conditions),c=$(e,new URL(n),s,!1);return{url:c.href,format:D(c,{parentURL:n})}}function ze(e,t){if(!t)throw Error("Please pass `parent`: `import-meta-resolve` cannot ponyfill that");try{return Re(e,{parentURL:t}).url}catch(e){let t=e;if((t.code===`ERR_UNSUPPORTED_DIR_IMPORT`||t.code===`ERR_MODULE_NOT_FOUND`)&&typeof t.url==`string`)return t.url;throw e}}export{$ as n,ze as t};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import "./global-args.politty";
|
|
3
|
+
/**
|
|
4
|
+
* @politty/valibot - politty with valibot schemas
|
|
5
|
+
*
|
|
6
|
+
* The user-facing entry point for building politty CLIs with valibot:
|
|
7
|
+
* installs the valibot validator adapter into `@politty/core` and
|
|
8
|
+
* re-exports the core API, with the schema-taking functions re-pinned to
|
|
9
|
+
* valibot's `GenericSchema` so a schema from another Standard Schema
|
|
10
|
+
* library is rejected at the type level instead of failing at runtime in
|
|
11
|
+
* the registered adapter.
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import { $ as PromptType, A as SubCommandValue, B as toKebabCase, C as RunCommandOptions, D as RunResultSuccess, E as RunResultFailure, F as lazy, G as CompletionMeta, H as UnflattenOptions, I as ExtractedFields, J as EffectContext, K as CompletionType, L as ResolvedFieldMeta, M as UnknownSubcommandHandler, N as LazyCommand, O as RunnableCommand, P as isLazyCommand, Q as PromptMeta, R as UnknownKeysMode, S as PromptResolverContext, T as RunResult, U as ArgFn, V as Unflatten, W as ArgMeta, X as PromptChoicesContext, Y as PromptChoices, Z as PromptChoicesResolver, _ as LogStream, a as ArgsSchema$1, at as DynamicCompletionCandidate, b as NonRunnableCommand, c as Command, ct as DynamicCompletionResult, d as GlobalArgs, dt as InferSchemaOutput, et as ValidateArgMeta, f as GlobalCleanupContext, ft as SchemaLike, g as LogLevel, h as LogEntry, i as ArgSource, it as CompletionDirectiveMask, j as SubCommandsRecord, k as SetupContext, l as CommandBase, lt as PackageRequirement, m as IsEmpty, n as AgentHelpContext, nt as ExpandCompletion, o as CleanupContext, ot as DynamicCompletionContext, p as GlobalSetupContext, q as CustomCompletion, r as AnyCommand, rt as ResolvedExpandCandidate, s as CollectedLogs, st as DynamicCompletionResolver, t as AgentHelp, tt as ExpandCandidate, u as Example, ut as loadPackage, v as Logger, w as RunInvocation, x as PromptResolver, y as MainOptions, z as toCamelCase } from "./types-mJuR-rBV.js";
|
|
16
|
+
import { _ as CompletionResult, g as CompletionOptions, i as GenerateBundledCompletionWorkerResult, n as withCompletionCommand, r as GenerateBundledCompletionWorkerOptions, t as WithCompletionOptions, x as InternalArgsSchema } from "./with-completion-command-Bq-S79VO.js";
|
|
3
17
|
import { r as KnownAgentId, t as AgentInfo } from "./detect-agent-hU93hctO.js";
|
|
4
18
|
import * as v from "valibot";
|
|
5
19
|
import { GenericSchema } from "valibot";
|
|
@@ -232,7 +246,7 @@ type InferArgs<TArgsSchema> = TArgsSchema extends InternalArgsSchema<infer TInte
|
|
|
232
246
|
*/
|
|
233
247
|
type MergedArgs<TLocalArgs, TGlobalArgs> = IsEmpty<TGlobalArgs> extends true ? TLocalArgs : TLocalArgs & WithCaseVariants<TGlobalArgs>;
|
|
234
248
|
/**
|
|
235
|
-
* Add the `$source`, `$invocation` and `$
|
|
249
|
+
* Add the `$source`, `$invocation`, `$agent` and `$signal` run-time metadata helpers.
|
|
236
250
|
*
|
|
237
251
|
* `$source` reports whether a given field's final value came from an
|
|
238
252
|
* explicit CLI token, a `field.env` fallback, a `prompt` resolver answer, or
|
|
@@ -249,11 +263,15 @@ type MergedArgs<TLocalArgs, TGlobalArgs> = IsEmpty<TGlobalArgs> extends true ? T
|
|
|
249
263
|
*
|
|
250
264
|
* `$agent` reports the AI coding agent running the CLI (see `detectAgent`),
|
|
251
265
|
* or `undefined` when none is detected.
|
|
266
|
+
*
|
|
267
|
+
* `$signal` is aborted when `runMain` receives SIGINT or SIGTERM before `run`
|
|
268
|
+
* settles, with or without `gracefulShutdown`. `runCommand` never aborts it.
|
|
252
269
|
*/
|
|
253
270
|
type WithRunMeta<T> = T & {
|
|
254
271
|
$source?: (name: string) => ArgSource;
|
|
255
272
|
$invocation?: RunInvocation;
|
|
256
273
|
$agent?: AgentInfo | undefined;
|
|
274
|
+
$signal?: AbortSignal;
|
|
257
275
|
};
|
|
258
276
|
/**
|
|
259
277
|
* Resolve merged args from schema and global args type
|
|
@@ -324,6 +342,8 @@ interface CreateDefineCommandFn<TArgsBase extends ArgsSchema$1 = ArgsSchema$1> {
|
|
|
324
342
|
*/
|
|
325
343
|
interface RunnableConfig<TArgsSchema extends ArgsSchema$1 | undefined, TResult, TGlobalArgs, TSubCommands extends SubCommandsRecord | undefined = undefined> extends DefineCommandConfig<TArgsSchema, TResult, TGlobalArgs, TSubCommands> {
|
|
326
344
|
run: (args: ResolvedArgs<TArgsSchema, TGlobalArgs>) => TResult;
|
|
345
|
+
/** See `RunnableCommand.gracefulShutdown` */
|
|
346
|
+
gracefulShutdown?: boolean;
|
|
327
347
|
/** Not settable alongside `run` (see `NonRunnableConfig.defaultSubCommand`) */
|
|
328
348
|
defaultSubCommand?: undefined;
|
|
329
349
|
}
|
|
@@ -332,6 +352,8 @@ interface RunnableConfig<TArgsSchema extends ArgsSchema$1 | undefined, TResult,
|
|
|
332
352
|
*/
|
|
333
353
|
interface NonRunnableConfig<TArgsSchema extends ArgsSchema$1 | undefined, TGlobalArgs, TSubCommands extends SubCommandsRecord | undefined = undefined> extends Omit<DefineCommandConfig<TArgsSchema, void, TGlobalArgs, TSubCommands>, "run"> {
|
|
334
354
|
run?: undefined;
|
|
355
|
+
/** Not settable without `run` (see `RunnableConfig.gracefulShutdown`) */
|
|
356
|
+
gracefulShutdown?: undefined;
|
|
335
357
|
/**
|
|
336
358
|
* Name of a `subCommands` entry to run when this command is invoked with
|
|
337
359
|
* no subcommand specified, instead of showing help. Must be a key of
|
|
@@ -936,7 +958,7 @@ interface CommandValidationError {
|
|
|
936
958
|
/** Path to the command (e.g., ["cli", "build", "watch"]) */
|
|
937
959
|
commandPath: string[];
|
|
938
960
|
/** Error type */
|
|
939
|
-
type: "duplicate_field" | "duplicate_alias" | "invalid_alias" | "positional_config" | "reserved_alias" | "reserved_field_name" | "case_variant_collision" | "duplicate_negation" | "field_type_conflict" | "subcommand_key_name_mismatch" | "default_subcommand_conflict" | "default_subcommand_not_found";
|
|
961
|
+
type: "duplicate_field" | "duplicate_alias" | "invalid_alias" | "positional_config" | "reserved_alias" | "reserved_field_name" | "case_variant_collision" | "duplicate_negation" | "field_type_conflict" | "subcommand_key_name_mismatch" | "default_subcommand_conflict" | "default_subcommand_not_found" | "graceful_shutdown_without_run";
|
|
940
962
|
/** Error message */
|
|
941
963
|
message: string;
|
|
942
964
|
/** Related field name (if applicable) */
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./register-ZdhcM-o7.js";import{n as t,t as n}from"./cli-main-
|
|
1
|
+
import{t as e}from"./register-ZdhcM-o7.js";import{n as t,t as n}from"./cli-main-BOiqNyRU.js";import{i as r,n as i}from"./schema-extractor-Cwg_WAC-.js";import{t as a}from"./with-completion-command-gytc9LNl.js";import{n as o,t as s}from"./command-CCiN78NV.js";import{d as c,o as l,s as u}from"./subcommand-router-CfCW9eG4.js";import{A as d,C as f,D as p,E as m,O as h,S as g,T as _,_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,i as E,k as D,l as O,m as k,n as A,o as ee,p as j,r as M,s as N,t as P,u as F,v as I,w as L,x as R,y as z}from"./runner-C0PI1zBE.js";import{a as B,i as V,n as H,r as U,t as W}from"./logger-CoeDrmRr.js";import{a as G}from"./argv-parser-bI3e6XXA.js";import{a as K,c as q,m as J,o as Y,p as X,t as Z}from"./unflatten-DVeO9OZ_.js";import*as Q from"valibot";function $(e,t={}){let n=K(t);Z(Object.keys(e.entries),t);let r=Q.pipe(e,Q.rawTransform(({dataset:e,addIssue:t,NEVER:r})=>{let i=q(e.value,n);if(!i.issues)return i.value;for(let n of i.issues){let r=n.path[0];t({message:n.message,path:[{type:`object`,origin:`value`,input:e.value,key:r,value:e.value[r]}]})}return r}));return Y(r,t)}const te=t(`@politty/valibot`),ne=o,re=s,ie=e;export{I as CaseVariantCollisionError,z as DefaultSubCommandError,b as DuplicateAliasError,R as DuplicateFieldError,g as DuplicateNegationError,M as EnvFileNotFoundError,f as FieldTypeConflictError,L as PositionalConfigError,_ as ReservedAliasError,m as ReservedFieldNameError,ie as arg,t as createCompileCacheShimGenerator,re as createDefineCommand,y as createDualCaseProxy,ne as defineCommand,i as extractFields,N as formatCommandValidationErrors,ee as formatValidationErrors,te as generateCompileCacheShim,p as generateHelp,h as generateHelpData,r as getUnknownKeysMode,W as isColorEnabled,l as isLazyCommand,u as lazy,E as loadEnvFiles,c as loadPackage,H as logger,G as parseArgv,D as renderInline,d as renderMarkdown,P as runCommand,A as runMain,n as runPolittyCli,U as setColorEnabled,V as styles,B as symbols,X as toCamelCase,J as toKebabCase,$ as unflatten,x as validateCaseVariantCollisions,O as validateCommand,F as validateCrossSchemaCollisions,S as validateDefaultSubCommand,C as validateDuplicateAliases,j as validateDuplicateFields,k as validateDuplicateNegations,T as validatePositionalConfig,w as validateReservedAliases,v as validateReservedFieldNames,a as withCompletionCommand};
|
package/dist/prompt-clack.d.ts
CHANGED
package/dist/prompt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as ExtractedFields, L as ResolvedFieldMeta, S as PromptResolverContext } from "./types-
|
|
1
|
+
import { I as ExtractedFields, L as ResolvedFieldMeta, S as PromptResolverContext } from "./types-mJuR-rBV.js";
|
|
2
2
|
/**
|
|
3
3
|
* Resolved prompt configuration for a single field
|
|
4
4
|
*/
|