@politty/zod 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -2
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +1 -0
- package/dist/{arg-registry-Dvi0co21.d.ts → arg-registry-vcm6uTB1.d.ts} +37 -2
- package/dist/argv-parser-CawJSYjw.js +1 -0
- package/dist/augment.d.ts +1 -1
- package/dist/cli-main-DcB9Slb7.js +2 -0
- package/dist/cli-main-Dp25rn4L.js +1 -0
- package/dist/cli-run-C-K9FeKJ.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/completion-CizQSJgq.js +1 -0
- package/dist/{completion-OvSe3W9y.js → completion-nNzHfI1i.js} +3 -3
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +1 -1
- package/dist/detect-agent-D7KSeWMh.js +3 -0
- package/dist/detect-agent-EHaSY1KW.d.ts +49 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +12 -12
- package/dist/dynamic-DG-l9V-y.js +1 -0
- package/dist/dynamic-DbvYJg3o.js +6 -0
- package/dist/field-meta-D9ySul7J.js +1 -0
- package/dist/index.d.ts +15 -4
- package/dist/index.js +1 -1
- package/dist/log-collector-uhRWYT-z.js +1 -0
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/register-TbOCQNeI.js +1 -0
- package/dist/runner-CqslNxyn.js +30 -0
- package/dist/runner-DD6DzZky.js +1 -0
- package/dist/schema-extractor-fZZ2_WAZ.js +1 -0
- package/dist/{schema-DhMPssIJ.js → schema-tWeEQULd.js} +1 -1
- package/dist/skill.d.ts +1 -1
- package/dist/skill.js +1 -1
- package/dist/{subcommand-router-D8GTMXYL.js → subcommand-router-DR2KBQAt.js} +1 -1
- package/dist/{with-completion-command-CQcqFHq8.js → with-completion-command-DG-C9_0Z.js} +2 -2
- package/dist/{with-completion-command-BKHwbzEc.d.ts → with-completion-command-DR98pkpR.d.ts} +1 -1
- package/package.json +5 -1
- package/dist/argv-parser-DZQ0qnXG.js +0 -1
- package/dist/cli-main-BX5IVgNq.js +0 -1
- package/dist/cli-main-uRzr666k.js +0 -2
- package/dist/cli-run-DtG5fM18.js +0 -1
- package/dist/completion-8frPuaX8.js +0 -1
- package/dist/dynamic-4uRohypH.js +0 -6
- package/dist/dynamic-C5e2NuDv.js +0 -1
- package/dist/field-meta-_l-FHbh7.js +0 -1
- package/dist/log-collector-DICKib75.js +0 -1
- package/dist/register-BXOytPt7.js +0 -1
- package/dist/runner-BTD1-gUd.js +0 -30
- package/dist/runner-BTF0HIGj.js +0 -1
- package/dist/schema-extractor-Du9ipDD4.js +0 -1
package/README.md
CHANGED
|
@@ -148,11 +148,11 @@ Arguments:
|
|
|
148
148
|
<name> Name of the person to greet
|
|
149
149
|
|
|
150
150
|
Options:
|
|
151
|
+
-g, --greeting <GREETING> Greeting phrase (default: "Hello")
|
|
152
|
+
-l, --loud Output in uppercase (default: false)
|
|
151
153
|
-h, --help Show help
|
|
152
154
|
-H, --help-all Show help with all subcommand options
|
|
153
155
|
--help-json Show help as JSON
|
|
154
|
-
-g, --greeting <GREETING> Greeting phrase (default: "Hello")
|
|
155
|
-
-l, --loud Output in uppercase (default: false)
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Every command also accepts `--help-json`, which prints the same information as a single JSON object instead of formatted text — useful for tools that consume a CLI's help programmatically (e.g. generating docs or another UI) rather than parsing `--help`'s output:
|
|
@@ -531,6 +531,21 @@ politty integrates Node.js's on-disk compile cache (V8 code cache, Node >= 22.8.
|
|
|
531
531
|
|
|
532
532
|
`generate-shim` writes an executable shim that enables the cache and loads `--entry` (a specifier relative to the shim) with a dynamic import. The output path and program name come from `package.json` (the `bin` path and the `bin` name), and the shim imports the cache helper from the politty package whose `politty` bin you ran — the one you installed, so it resolves from your package. Packages with multiple bins pass `--entry` once per bin, and `--entry` itself can be omitted when the entry sits next to the shim under a conventional name (`./cli.js`, `./index.js`, ...). See [Faster Startup (Compile Cache)](./docs/recipes.md#faster-startup-compile-cache) for the flags, the opt-out (`compileCache: false`), and the hand-written shim variant.
|
|
533
533
|
|
|
534
|
+
## AI Coding Agents
|
|
535
|
+
|
|
536
|
+
politty detects AI coding agents (Claude Code, Codex, Cursor, Gemini CLI, ...) from the environment, following [vercel/detect-agent](https://github.com/vercel/detect-agent)'s spec. Give agents guidance humans never see, and branch on the detected agent at run time:
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
runMain(cli, {
|
|
540
|
+
agentHelp: "**AGENTS:** Pass `--json` and parse stdout instead of the table output.",
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
// In run/setup/cleanup: args.$agent // e.g. { id: "claude_code", rawId: "claude_code" }, or undefined
|
|
544
|
+
// Anywhere: import { detectAgent } from "politty/agent";
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Set `POLITTY_NO_AGENT=1` to opt out. See [AI Coding Agents](./docs/advanced-features.md#ai-coding-agents).
|
|
548
|
+
|
|
534
549
|
## Skill Management
|
|
535
550
|
|
|
536
551
|
politty manages SKILL.md-based agent skills distributed via npm packages.
|
package/dist/agent.d.ts
ADDED
package/dist/agent.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./detect-agent-D7KSeWMh.js";export{e as detectAgent};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as AgentInfo } from "./detect-agent-EHaSY1KW.js";
|
|
1
2
|
//#region ../core/src/adapter/standard-schema.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Type-level subset of the Standard Schema V1 interface
|
|
@@ -312,14 +313,34 @@ interface CleanupContext<TArgs = unknown> {
|
|
|
312
313
|
/**
|
|
313
314
|
* Context provided to global setup function (runMain/runCommand level)
|
|
314
315
|
*/
|
|
315
|
-
interface GlobalSetupContext {
|
|
316
|
+
interface GlobalSetupContext {
|
|
317
|
+
/** AI coding agent running the CLI (see `detectAgent`); undefined when none is detected */
|
|
318
|
+
agent?: AgentInfo | undefined;
|
|
319
|
+
}
|
|
316
320
|
/**
|
|
317
321
|
* Context provided to global cleanup function (runMain/runCommand level)
|
|
318
322
|
*/
|
|
319
323
|
interface GlobalCleanupContext {
|
|
324
|
+
/** AI coding agent running the CLI (see `detectAgent`); undefined when none is detected */
|
|
325
|
+
agent?: AgentInfo | undefined;
|
|
320
326
|
/** Error if command execution failed */
|
|
321
327
|
error?: Error | undefined;
|
|
322
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Context passed to a function-form {@link AgentHelp}
|
|
331
|
+
*/
|
|
332
|
+
interface AgentHelpContext {
|
|
333
|
+
/** The detected agent */
|
|
334
|
+
agent: AgentInfo;
|
|
335
|
+
/** Subcommand names from the root to the command whose help is shown (empty at the root) */
|
|
336
|
+
commandPath: readonly string[];
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Agent-only guidance prepended to help output (Markdown, rendered like
|
|
340
|
+
* `notes`). A function form can vary it per agent or command, and returns
|
|
341
|
+
* `undefined` to show nothing.
|
|
342
|
+
*/
|
|
343
|
+
type AgentHelp = string | ((context: AgentHelpContext) => string | undefined);
|
|
323
344
|
/**
|
|
324
345
|
* Base command interface (shared properties)
|
|
325
346
|
* @template TArgsSchema - The args schema type (from the CLI's schema library)
|
|
@@ -449,6 +470,13 @@ interface MainOptions {
|
|
|
449
470
|
displayErrors?: boolean;
|
|
450
471
|
/** Prompt resolver for interactive missing-arg prompts (e.g. from `politty/prompt/clack`). */
|
|
451
472
|
prompt?: PromptResolver | undefined;
|
|
473
|
+
/**
|
|
474
|
+
* Guidance for AI coding agents, shown above `--help`/`--help-all` output
|
|
475
|
+
* (and the help shown for a missing or unknown subcommand) only when
|
|
476
|
+
* `detectAgent()` detects one; humans never see it. `--help-json` carries
|
|
477
|
+
* it as the `agentHelp` field.
|
|
478
|
+
*/
|
|
479
|
+
agentHelp?: AgentHelp | undefined;
|
|
452
480
|
/**
|
|
453
481
|
* Fallback hook for CLI plugin dispatch, invoked when a positional is not a
|
|
454
482
|
* known subcommand at any level whose command exposes subcommands (e.g. exec
|
|
@@ -520,6 +548,13 @@ interface RunCommandOptions {
|
|
|
520
548
|
cleanup?: ((context: GlobalCleanupContext) => void | Promise<void>) | undefined;
|
|
521
549
|
/** Prompt resolver for interactive missing-arg prompts (e.g. from `politty/prompt/clack`). */
|
|
522
550
|
prompt?: PromptResolver | undefined;
|
|
551
|
+
/**
|
|
552
|
+
* Guidance for AI coding agents, shown above `--help`/`--help-all` output
|
|
553
|
+
* (and the help shown for a missing or unknown subcommand) only when
|
|
554
|
+
* `detectAgent()` detects one; humans never see it. `--help-json` carries
|
|
555
|
+
* it as the `agentHelp` field.
|
|
556
|
+
*/
|
|
557
|
+
agentHelp?: AgentHelp | undefined;
|
|
523
558
|
}
|
|
524
559
|
/**
|
|
525
560
|
* Log level type
|
|
@@ -1068,4 +1103,4 @@ interface ArgFn<TSchemaBase extends SchemaLike = SchemaLike> {
|
|
|
1068
1103
|
<T extends TSchemaBase, M extends ArgMeta<InferSchemaOutput<T>>>(schema: T, meta: ValidateArgMeta<M, InferSchemaOutput<T>>): T;
|
|
1069
1104
|
}
|
|
1070
1105
|
//#endregion
|
|
1071
|
-
export {
|
|
1106
|
+
export { ResolvedFieldMeta as $, GlobalSetupContext as A, RunInvocation as B, CleanupContext as C, Example as D, CommandBase as E, Logger as F, SetupContext as G, RunResultFailure as H, MainOptions as I, UnknownSubcommandHandler as J, SubCommandValue as K, NonRunnableCommand as L, LogEntry as M, LogLevel as N, GlobalArgs as O, LogStream as P, ExtractedFields as Q, PromptResolver as R, ArgsSchema as S, Command as T, RunResultSuccess as U, RunResult as V, RunnableCommand as W, isLazyCommand as X, LazyCommand as Y, lazy as Z, DynamicCompletionResult as _, CustomCompletion as a, AnyCommand as b, PromptType as c, ExpandCompletion as d, UnknownKeysMode as et, ResolvedExpandCandidate as f, DynamicCompletionResolver as g, DynamicCompletionContext as h, CompletionType as i, SchemaLike as it, IsEmpty as j, GlobalCleanupContext as k, ValidateArgMeta as l, DynamicCompletionCandidate as m, ArgMeta as n, toKebabCase as nt, EffectContext as o, CompletionDirectiveMask as p, SubCommandsRecord as q, CompletionMeta as r, InferSchemaOutput as rt, PromptMeta as s, ArgFn as t, toCamelCase as tt, ExpandCandidate as u, AgentHelp as v, CollectedLogs as w, ArgSource as x, AgentHelpContext as y, RunCommandOptions as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,n as t}from"./field-meta-D9ySul7J.js";const n=/* @__PURE__ */ new Set([`1`,`t`,`T`,`TRUE`,`true`,`True`]),r=/* @__PURE__ */ new Set([`0`,`f`,`F`,`FALSE`,`false`,`False`]);function i(e){return n.has(e)?!0:!r.has(e)&&e}function a(e,t){return t===`boolean`?i(e):e}function o(e){let t=e.indexOf(`=`);return t>=0?e.slice(2,t):e.slice(2)}function s(e,t){let n=o(e);if(!e.includes(`=`)){let e=t.negationMap.get(n);if(e&&t.booleanFlags.has(e))return{resolvedName:e,withoutDashes:n,isNegated:!0,isCustomNegation:!0,isSuppressedNegation:!1}}let r=e.includes(`=`);if(!r&&n.startsWith(`no-`)){let e=n.slice(3);if(e===e.toLowerCase()){let r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}}if(!r&&n.length>2&&n.startsWith(`no`)&&/[A-Z]/.test(n[2])){let e=n[2].toLowerCase()+n.slice(3),r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}return{resolvedName:t.aliasMap.get(n)??n,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!1}}const c=/^-\.?\d/;function l(e){return c.test(e)}function u(e,t={}){let{aliasMap:n=/* @__PURE__ */ new Map,booleanFlags:r=/* @__PURE__ */ new Set,arrayFlags:a=/* @__PURE__ */ new Set,definedNames:o=/* @__PURE__ */ new Set,negationMap:c=/* @__PURE__ */ new Map,defaultNegationDisabledFields:u}=t,d={aliasMap:n,booleanFlags:r,definedNames:o,negationMap:c,defaultNegationDisabledFields:u??new Set(r)},f={options:{},positionals:[],rest:[]},p=0,m=!1,h=(e,t)=>{let r=n.get(e)??e;if(a.has(r)){let e=f.options[r];Array.isArray(e)?e.push(t):e===void 0?f.options[r]=[t]:f.options[r]=[e,t]}else f.options[r]=t};for(;p<e.length;){let t=e[p];if(m){f.rest.push(t),p++;continue}if(t===`--`){m=!0,p++;continue}if(t.startsWith(`--`)){let a=t.slice(2),o=s(t,d);if(o.isSuppressedNegation){h(o.withoutDashes,!0),p++;continue}if(o.isNegated){h(o.resolvedName,!1),p++;continue}let c=a.indexOf(`=`);if(c!==-1){let e=a.slice(0,c),t=a.slice(c+1),o=n.get(e)??e;h(e,r.has(o)?i(t):t),p++}else{let t=a,i=n.get(t)??t;if(r.has(i))h(t,!0),p++;else{let n=e[p+1];n!==void 0&&(!n.startsWith(`-`)||l(n))?(h(t,n),p+=2):(h(t,!0),p++)}}continue}if(t.startsWith(`-`)&&t.length>1&&!t.startsWith(`--`)){let a=t.slice(1),o=a.indexOf(`=`);if(o!==-1){let e=a.slice(0,o),t=a.slice(o+1),s=n.get(e)??e;h(e,r.has(s)?i(t):t),p++}else if(a.length===1){let t=a,i=n.get(t)??t;if(r.has(i))h(t,!0),p++;else{let n=e[p+1];n!==void 0&&(!n.startsWith(`-`)||l(n))?(h(t,n),p+=2):(h(t,!0),p++)}}else{for(let e of a)h(e,!0);p++}continue}f.positionals.push(t),p++}return f}function d(n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set;for(let e of n.fields)o.add(e.name);for(let l of n.fields){if(!l.named)continue;l.cliName!==l.name&&r.set(l.cliName,l.name);for(let n of t(l))if(r.set(n,l.name),n.length>1&&n.includes(`-`)){let t=e(n);t!==n&&!o.has(t)&&!r.has(t)&&r.set(t,l.name)}let n=e(l.name);if(n!==l.name&&!o.has(n)&&!r.has(n)&&r.set(n,l.name),l.type===`boolean`&&i.add(l.name),l.type===`array`&&a.add(l.name),l.type===`boolean`&&l.negation!==!0&&(c.add(l.name),typeof l.negation==`string`&&(s.set(l.negation,l.name),l.negation.includes(`-`)))){let t=e(l.negation);t!==l.negation&&s.set(t,l.name)}}return{aliasMap:r,booleanFlags:i,arrayFlags:a,definedNames:o,negationMap:s,defaultNegationDisabledFields:c}}function f(e,t){return e.fields.filter(e=>e.positional&&!(e.named&&Object.hasOwn(t,e.name)))}function p(e,t){let n={...e.options},r=t.fields.filter(e=>e.positional),i=e.rest.length>0?[...e.positionals,...e.rest]:e.positionals;for(let e of r)e.named||delete n[e.name];let a=0;for(let r of f(t,e.options)){if(a>=i.length)break;if(r.type===`array`){n[r.name]=i.slice(a);break}n[r.name]=i[a],a++}return n}export{o as a,f as i,p as n,s as o,u as r,a as s,d as t};
|
package/dist/augment.d.ts
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as e,u as t}from"./schema-extractor-fZZ2_WAZ.js";import{n}from"./command-tLHaJHe6.js";import{n as r}from"./runner-CqslNxyn.js";import{chmodSync as i,existsSync as a,mkdirSync as o,readFileSync as s,writeFileSync as c}from"node:fs";import{basename as l,dirname as u,extname as d,isAbsolute as f,join as p,relative as m,resolve as h}from"node:path";import{fileURLToPath as g}from"node:url";const _=`Generated by politty: compile-cache bin shim`,v=[`./cli.js`,`./cli.mjs`,`./index.js`,`./index.mjs`];function y(e){let t=h(e);for(;;){let e=p(t,`package.json`);if(a(e))return{pkg:JSON.parse(s(e,`utf8`)),dir:t};let n=u(t);if(n===t)return;t=n}}function b(e){if(!e)return[];if(typeof e.bin==`string`&&e.bin){let t=x(e);return t?[[t,e.bin]]:[]}return typeof e.bin==`object`&&e.bin!==null?Object.entries(e.bin).filter(e=>typeof e[1]==`string`&&e[1]!==``):[]}function x(e){if(e){if(typeof e.bin==`object`&&e.bin!==null){let[t]=Object.keys(e.bin);if(t)return t}if(typeof e.name==`string`&&e.name){let t=e.name;return t.startsWith(`@`)?t.split(`/`)[1]??t:t}}}function S(e){let t=u(e),n=l(e);for(let e of v)if(l(e)!==n&&a(p(t,e)))return e}function C(e,t,n){return[`#!/usr/bin/env node`,``,`// ${_}.`,`// Enables the Node.js on-disk compile cache (V8 code cache) before the`,`// CLI module graph is compiled, so warm starts skip recompilation`,`// (Node >= 22.8.0; silent no-op otherwise).`,`try {`,` const { enableCompileCache } = await import(${JSON.stringify(n)});`,` enableCompileCache(${JSON.stringify(e)});`,`} catch {`,` // ${n} is not resolvable from here (e.g. a fully`,` // bundled CLI) — start without the compile cache rather than failing`,` // the CLI.`,`}`,`await import(${JSON.stringify(t)});`,``].join(`
|
|
2
|
+
`)}function w(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function T(e){return(t={})=>E(`${e}/compile-cache`,t)}function E(e,t){let n=t.cwd??process.cwd(),r=y(n),l=r?.pkg,p=w(t.entry),m=w(t.out),T=b(l),E;if(m.length>0){if(p.length>0&&p.length!==m.length)throw Error(`--entry count (${p.length}) does not match --out count (${m.length}); pass one --out per --entry or omit --out entirely.`);E=m.map(e=>f(e)?e:h(n,e))}else{if(T.length===0||r===void 0)throw Error(`Cannot derive the output path: no bin entry in package.json. Pass --out explicitly.`);if(p.length>0&&p.length!==T.length)throw Error(`--entry count (${p.length}) does not match the package's bin entries (${T.length}); pass one --entry per bin (in declaration order) or matching --out paths.`);E=T.map(([,e])=>h(r.dir,e))}if(new Set(E).size!==E.length)throw Error(`Duplicate output paths; each shim needs a distinct output file. Check the --out values (or the bin paths in package.json when --out is omitted).`);let O=/* @__PURE__ */ new Map;if(r)for(let[e,t]of T)O.set(h(r.dir,t),e);let k=[],A=t.compileCacheSpecifier??e;if(/[\r\n\u2028\u2029]/.test(A))throw Error(`Invalid compile-cache specifier ${JSON.stringify(A)}: a module specifier cannot contain a line terminator.`);let j=E.map((e,r)=>{let i=O.get(e),o=t.program??i??x(l);if(!o)throw Error(`Cannot derive a program name: no bin or name in package.json. Pass --program explicitly.`);if(t.program===void 0&&i===void 0&&m.length>0&&k.push(`Warning: ${D(e,n)} does not match any bin path in package.json, so its cache directory uses the program name ${JSON.stringify(o)}. Pass --program to override.`),e.endsWith(`.cjs`))throw Error(`The generated shim is an ES module and cannot be written to a .cjs file. Use a .mjs (or .js in a "type": "module" package) output path.`);if(d(e)===``)throw Error(`The generated shim is an ES module and cannot be written to an extensionless file (it would not load on every supported Node.js version). Use a .mjs (or .js in a "type": "module" package) output path.`);if(e.endsWith(`.js`)&&l?.type!==`module`)throw Error(l===void 0?`The generated shim is an ES module, and no package.json was found to confirm .js files are treated as ESM. Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`:`The generated shim is an ES module, but the package is not "type": "module". Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`);let c=p[r]??S(e);if(c===void 0)throw Error(`Cannot derive an entry: none of ${v.join(`, `)} exist next to ${e}. Pass --entry explicitly.`);if(!c.startsWith(`./`)&&!c.startsWith(`../`)&&!c.startsWith(`file:`))throw Error(`Invalid entry ${c}: pass a specifier relative to the shim file ("./..." or "../...") or a file: URL.`);let f;if(c.startsWith(`file:`))try{f=g(c)}catch{f=void 0}else f=h(u(e),c);if(f===e)throw Error(`The shim at ${e} would import itself (entry ${c}). Point bin at a separate shim path (e.g. dist/bin.js) or pass a different --entry.`);if(a(e)&&!s(e,`utf8`).includes(_))throw Error(`Refusing to overwrite ${e}: it exists and was not generated by politty. If bin currently points at your real CLI entry, point it at a separate shim path (e.g. dist/bin.js) or pass --out explicitly.`);return{outputPath:e,program:o,entry:c,compileCacheSpecifier:A}});for(let e of k)console.warn(e);for(let{outputPath:e,program:t,entry:n}of j)o(u(e),{recursive:!0}),c(e,C(t,n,A)),i(e,493);return j}function D(e,t){let n=m(t,e);return n&&!n.startsWith(`..`)?n:e}const O=t({bin:e.string({description:`CLI binary or built JS entry file to invoke`,placeholder:`PATH`}),program:e.string({description:`Program name embedded in worker metadata`,placeholder:`NAME`}),shell:e.enum([`bash`,`zsh`,`fish`],{description:`Shell worker to generate`,placeholder:`SHELL`}),out:e.optionalString({description:`Output worker path (defaults to dist/completion/<shell>-worker.<ext>)`,placeholder:`PATH`}),verify:e.boolean({description:`Verify __completion-worker-path resolves to the generated worker`})}),k=n({name:`generate-worker`,description:`Generate and verify a bundled shell completion worker`,args:O,async run(e){let{generateBundledCompletionWorker:t}=await import(`./completion-CizQSJgq.js`);await t({bin:e.bin,programName:e.program,shell:e.shell,...e.out!==void 0&&{outputPath:e.out},verify:e.verify})}}),A=t({entry:e.optionalStringArray({description:`Module specifier the shim imports, relative to the shim file; repeatable, one per bin/--out (defaults to ./cli.js, ./cli.mjs, ./index.js, or ./index.mjs next to each shim)`,placeholder:`SPECIFIER`}),out:e.optionalStringArray({description:`Output path for the generated shim; repeatable, one per --entry (defaults to the bin paths in package.json)`,placeholder:`PATH`}),program:e.optionalString({description:`Program name for the cache directory, applied to all shims (defaults per shim to its bin name)`,placeholder:`NAME`}),compileCacheSpecifier:e.optionalString({description:`Module specifier the shim imports enableCompileCache from (defaults to the compile-cache subpath of the politty package running this command)`,placeholder:`SPECIFIER`})});function j(e){let t=T(e),i=n({name:`generate-shim`,description:`Generate a compile-cache bin shim that loads the real CLI via dynamic import`,args:A,run(e){let n=process.cwd(),r=t({...e.entry!==void 0&&{entry:e.entry},...e.out!==void 0&&{out:e.out},...e.program!==void 0&&{program:e.program},...e.compileCacheSpecifier!==void 0&&{compileCacheSpecifier:e.compileCacheSpecifier},cwd:n});for(let e of r)console.log(`Generated compile-cache shim: ${D(e.outputPath,n)} (program: ${e.program}, entry: ${e.entry}, compile-cache: ${e.compileCacheSpecifier})`)}}),a=n({name:`politty`,description:`politty development utilities`,subCommands:{"generate-shim":i,"generate-worker":k}});return r(a).catch(e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)})}export{T as n,j as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./cli-main-DcB9Slb7.js";export{e as runPolittyCli};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./register-TbOCQNeI.js";const{runPolittyCli:e}=await import(`./cli-main-Dp25rn4L.js`);await e(`@politty/zod`);export{};
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as e}from"./compile-cache-6u9hgeWu.js";e(`politty`),await import(`./cli-run-
|
|
2
|
+
import{n as e}from"./compile-cache-6u9hgeWu.js";e(`politty`),await import(`./cli-run-C-K9FeKJ.js`);export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./with-completion-command-DG-C9_0Z.js";import"./dynamic-DbvYJg3o.js";import{c as e,n as t,r as n,t as r}from"./completion-nNzHfI1i.js";export{r as createCompletionCommand,t as createCompletionWorkerPathCommand,n as createRefreshCompletionCommand,e as generateBundledCompletionWorker};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,c as t,n}from"./schema-extractor-Du9ipDD4.js";import{n as r}from"./command-tLHaJHe6.js";import{c as i}from"./subcommand-router-D8GTMXYL.js";import{a,i as o,n as s,o as c,r as l,s as u}from"./with-completion-command-CQcqFHq8.js";import{_ as d,c as f,d as p,f as m,g as h,h as g,i as _,l as v,m as y,p as b,s as ee,t as te,u as ne,v as x,y as S}from"./dynamic-4uRohypH.js";import{existsSync as C,mkdirSync as re,readFileSync as w,realpathSync as T,renameSync as ie,rmSync as ae,statSync as E,writeFileSync as oe}from"node:fs";import{dirname as D,extname as se,isAbsolute as O,join as k,relative as ce,resolve as le}from"node:path";import{promisify as ue}from"node:util";import{execFile as de}from"node:child_process";function fe(e,t,n=[],r=!1){if(t.length===0)return;let i=pe(e,n);for(let e of t)e.set(me(e,i,r))}function pe(e,t){let n=new Map,r=new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function me(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ge(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=he(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function he(e){let t=[],n=new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ge(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function _e(e,t,n,r){let i=ee(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function A(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function j(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function M(e,t,n){return`__${e}_expand_${t}__${A(n)}`}function ve(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${j(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function N(e){return e.filter(e=>!e.name.startsWith(`__`))}function P(e){let t=[];for(let n of N(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function ye(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return _e(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function be(e){return e.args?t(n(e.args)):[]}function xe(e,t){return e.filter(e=>e.named).map(e=>ye(e,t))}function Se(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return _e(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ce(r,a,o=[],s=!1){let c=[];if(a.subCommands)for(let[e,t]of Object.entries(a.subCommands)){let n=i(t);n?c.push(Ce(e,n,o,s)):c.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let l=[],u=a.args?n(a.args):void 0,d={name:r,description:a.description,aliases:a.aliases,subcommands:c,options:xe(u?e(u):[],l),positionals:Se(u?t(u):[],l)};return fe(d,l,o,s),d}function F(e,t,n){return e?`${e}${n}${t}`:t}function we(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>F(e,t,`:`)))}function Te(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function I(e,t){let n=[],r=N(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?v(i.cliName,i.alias):R(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of N(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...I(r,F(t,e,`:`)));return n}function Ee(e,t){return I(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function L(e,t=``,n=``){let r=[];for(let i of N(e.subcommands)){let e=F(n,A(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=F(t,n,`:`);r.push(...L(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function De(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Oe(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function ke(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${A(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ae(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function je(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function Me(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=A(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function R(e,t){let n=v(e.cliName,e.alias);if(e.isGlobal===!0){let e=new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of p(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ne(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function z(e){let t=[];return Ne(e,[],[``],[],`root`,t),t}function Ne(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?R(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of N(e.subcommands))Ne(o,[...t,o.name],we(n,o),[...r,...n],i===`root`?A(o.name):`${i}_${A(o.name)}`,a)}function B(e,t,n=[]){let r=Pe(e),i=new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of p(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=v(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:R(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function V(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(V(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function H(e,t,r,i=!1){let a=[];if(r){let e=[];a=xe(n(r).fields,e).map(e=>(e.isGlobal=!0,e)),fe({name:t,subcommands:[],options:a,positionals:[]},e,[],i)}let o=Ce(t,e,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:t,globalOptions:a}}function U(e){try{return Math.floor(E(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=k(n,e);try{if(E(t).isFile())return t}catch{}}return null}function W(e,t){return t||process.env[j(A(e))]||(Le(e)??process.argv[1]??``)}function G(e){let t=W(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${U(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=W(t,n),o=U(a),s=x(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=`_${t}`,o=W(t,n),s=U(o),c=x(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=M(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=A(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${A(r.fieldName)}:-}`:`\${_used_field_keys_${A(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function K(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...b(o,e,t)});if(s.length===0)continue;let c=R(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function q(e,t,n,r=[]){if(e.length===0)return[];let i=g(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of He(o.valueCompletion,!1,t,{funcSuffix:n,...y(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...q(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _avail+=(--help --help-all --help-json)`),n.push(` fi`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(A).join(`_`),a=`__${t}_complete_${i}`,o=N(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...q(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=P(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...q(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=[];d.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),d.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&d.push(`# politty-completion-worker: true`),d.push(`# Generated by politty`),d.push(``),o||d.push(...Re({programName:n,binPath:t.binPath}));let p=l.length>0,m=l.filter(e=>e.isArrayOption),g=m.length>0;p&&(d.push(`__${a}_enc() {`),d.push(` local LC_ALL=C`),d.push(` local _s=$1 _r='' _c _i`),d.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),d.push(" _c=${_s:_i:1}"),d.push(` case "$_c" in`),d.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),d.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),d.push(` esac`),d.push(` done`),d.push(` printf '%s' "$_r"`),d.push(`}`),d.push(``));for(let e of l){let t=M(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
1
|
+
import{a as e,c as t,n}from"./schema-extractor-fZZ2_WAZ.js";import{n as r}from"./command-tLHaJHe6.js";import{c as i}from"./subcommand-router-DR2KBQAt.js";import{a,i as o,n as s,o as c,r as l,s as u}from"./with-completion-command-DG-C9_0Z.js";import{_ as d,c as f,d as p,f as m,g as h,h as g,i as _,l as v,m as y,p as b,s as ee,t as te,u as ne,v as x,y as S}from"./dynamic-DbvYJg3o.js";import{existsSync as C,mkdirSync as re,readFileSync as w,realpathSync as T,renameSync as ie,rmSync as ae,statSync as E,writeFileSync as oe}from"node:fs";import{dirname as D,extname as se,isAbsolute as O,join as k,relative as ce,resolve as le}from"node:path";import{promisify as ue}from"node:util";import{execFile as de}from"node:child_process";function fe(e,t,n=[],r=!1){if(t.length===0)return;let i=pe(e,n);for(let e of t)e.set(me(e,i,r))}function pe(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function me(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of ge(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=he(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function he(e){let t=[],n=/* @__PURE__ */ new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*ge(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function _e(e,t,n,r){let i=ee(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function A(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function j(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function M(e,t,n){return`__${e}_expand_${t}__${A(n)}`}function ve(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${j(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function N(e){return e.filter(e=>!e.name.startsWith(`__`))}function P(e){let t=[];for(let n of N(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function ye(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return _e(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function be(e){return e.args?t(n(e.args)):[]}function xe(e,t){return e.filter(e=>e.named).map(e=>ye(e,t))}function Se(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return _e(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function Ce(r,a,o=[],s=!1){let c=[];if(a.subCommands)for(let[e,t]of Object.entries(a.subCommands)){let n=i(t);n?c.push(Ce(e,n,o,s)):c.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let l=[],u=a.args?n(a.args):void 0,d={name:r,description:a.description,aliases:a.aliases,subcommands:c,options:xe(u?e(u):[],l),positionals:Se(u?t(u):[],l)};return fe(d,l,o,s),d}function F(e,t,n){return e?`${e}${n}${t}`:t}function we(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>F(e,t,`:`)))}function Te(e){let t=[],n=(e,r)=>{let i=new Set(e.options.filter(e=>e.isGlobal!==!0).map(e=>e.name));e.positionals.some(e=>i.has(e.name))&&t.push({pathStrs:r,positionals:e.positionals,options:e.options});for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function I(e,t){let n=[],r=N(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?v(i.cliName,i.alias):R(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of N(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...I(r,F(t,e,`:`)));return n}function Ee(e,t){return I(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function L(e,t=``,n=``){let r=[];for(let i of N(e.subcommands)){let e=F(n,A(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=F(t,n,`:`);r.push(...L(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function De(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Oe(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function ke(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${A(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Ae(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function je(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${ke(r,t)} ;;`)}return n}function Me(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=A(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function R(e,t){let n=v(e.cliName,e.alias);if(e.isGlobal===!0){let e=/* @__PURE__ */ new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of p(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ne(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function z(e){let t=[];return Ne(e,[],[``],[],`root`,t),t}function Ne(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?R(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of N(e.subcommands))Ne(o,[...t,o.name],we(n,o),[...r,...n],i===`root`?A(o.name):`${i}_${A(o.name)}`,a)}function B(e,t,n=[]){let r=Pe(e),i=/* @__PURE__ */ new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:/* @__PURE__ */ new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=/* @__PURE__ */ new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=/* @__PURE__ */ new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of p(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=v(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);i>=0&&a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:R(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=/* @__PURE__ */ new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of N(e.subcommands))n(t,we(r,t))};return n(e,[``]),t}function V(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(V(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function H(e,t,r,i=!1){let a=[];if(r){let e=[];a=xe(n(r).fields,e).map(e=>(e.isGlobal=!0,e)),fe({name:t,subcommands:[],options:a,positionals:[]},e,[],i)}let o=Ce(t,e,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:t,globalOptions:a}}function U(e){try{return Math.floor(E(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=k(n,e);try{if(E(t).isFile())return t}catch{}}return null}function W(e,t){return t||process.env[j(A(e))]||(Le(e)??process.argv[1]??``)}function G(e){let t=W(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${U(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=W(t,n),o=U(a),s=x(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=A(t),i=j(r),a=`_${t}`,o=W(t,n),s=U(o),c=x(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=M(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=A(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${A(r.fieldName)}:-}`:`\${_used_field_keys_${A(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function K(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...b(o,e,t)});if(s.length===0)continue;let c=R(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function q(e,t,n,r=[]){if(e.length===0)return[];let i=g(e,r,t),a=[...i??[]];a.push(` case "${i?`$_slot`:`$_pos_count`}" in`);for(let o of e){o.variadic&&!i?a.push(` ${o.position}|*)`):a.push(` ${o.position})`);for(let i of He(o.valueCompletion,!1,t,{funcSuffix:n,...y(o,r,e)}))a.push(` ${i}`);a.push(` ;;`)}return a.push(` esac`),a}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...q(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _avail+=(--help --help-all --help-json)`),n.push(` fi`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(A).join(`_`),a=`__${t}_complete_${i}`,o=N(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...q(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=P(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...q(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=[];d.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),d.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&d.push(`# politty-completion-worker: true`),d.push(`# Generated by politty`),d.push(``),o||d.push(...Re({programName:n,binPath:t.binPath}));let p=l.length>0,m=l.filter(e=>e.isArrayOption),g=m.length>0;p&&(d.push(`__${a}_enc() {`),d.push(` local LC_ALL=C`),d.push(` local _s=$1 _r='' _c _i`),d.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),d.push(" _c=${_s:_i:1}"),d.push(` case "$_c" in`),d.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),d.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),d.push(` esac`),d.push(` done`),d.push(` printf '%s' "$_r"`),d.push(`}`),d.push(``));for(let e of l){let t=M(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
2
2
|
`);d.push(`${t}__${e}=${f(r)}`)}d.push(``)}V(s)&&(d.push(...ve(a,n)),d.push(``),d.push(`__${a}_apply_dynamic_output() {`),d.push(` local _raw="$1"`),d.push(` COMPREPLY=()`),d.push(` local _directive=0`),d.push(` local -a _lines=()`),d.push(` local _line`),d.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),d.push(" local _last=$((${#_lines[@]} - 1))"),d.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),d.push(' _directive="${_lines[$_last]#:}"'),d.push(` unset '_lines[_last]'`),d.push(` fi`),d.push(' for _line in "${_lines[@]}"; do'),d.push(` [[ -z "$_line" ]] && continue`),d.push(` COMPREPLY+=("$_line")`),d.push(` done`),d.push(' local _ip="${_inline_prefix:-}"'),d.push(` if (( _directive & ${_.DirectoryCompletion} )); then`),d.push(` compopt +o default 2>/dev/null`),d.push(` compopt -o filenames 2>/dev/null`),d.push(` local _d`),d.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),d.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),d.push(` elif (( _directive & ${_.FileCompletion} )); then`),d.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),d.push(` compopt -o filenames 2>/dev/null`),d.push(` local _f`),d.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),d.push(` else`),d.push(` compopt -o default 2>/dev/null`),d.push(` fi`),d.push(` else`),d.push(` if (( _directive & ${_.NoFileCompletion} )); then`),d.push(` compopt +o default 2>/dev/null`),d.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),d.push(` fi`),d.push(` fi`),d.push(` if (( _directive & ${_.NoSpace} )); then`),d.push(` compopt -o nospace 2>/dev/null`),d.push(` fi`),d.push(`}`),d.push(``)),d.push(`__${a}_not_used() {`),d.push(' for _u in "${_used_opts[@]}"; do'),d.push(` for _chk in "$@"; do`),d.push(` [[ "$_u" == "$_chk" ]] && return 1`),d.push(` done`),d.push(` done`),d.push(` return 0`),d.push(`}`),d.push(``),d.push(`__${a}_opt_takes_value() {`),d.push(` case "$1:$2" in`),d.push(...Ee(s,``)),d.push(` esac`),d.push(` return 1`),d.push(`}`),d.push(``),p&&(d.push(`__${a}_track_opt() {`),d.push(` case "$1:$2" in`),d.push(...Ae(u,`bash`)),d.push(` esac`),d.push(`}`),d.push(``),d.push(`__${a}_track_pos() {`),d.push(` case "$1:$2" in`),d.push(...je(u,`bash`)),d.push(` esac`),d.push(`}`),d.push(``),d.push(...h(a,Te(s)))),g&&(d.push(`__${a}_track_array_expand() {`),d.push(` case "$1:$2" in`),d.push(...Me(m,`bash`)),d.push(` esac`),d.push(`}`),d.push(``));let v=L(s);v.length>0&&(d.push(`__${a}_is_subcmd() {`),d.push(` case "$1:$2" in`),d.push(...De(v)),d.push(` esac`),d.push(` return 1`),d.push(`}`),d.push(``));for(let e of c)d.push(...Je(e,a,[]));if(d.push(`__${a}_complete_root() {`),d.push(...Ke(s.options,s.positionals,a,`root`)),d.push(` if [[ -z "$_inline_prefix" ]] && __${a}_opt_takes_value "" "$_prev"; then return; fi`),d.push(` if [[ -n "$_inline_prefix" ]] && __${a}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),s.positionals.length>0?(d.push(` if (( _after_dd )); then`),d.push(...q(s.positionals,a,`root`,s.options).map(e=>` ${e}`)),d.push(` return`),d.push(` fi`)):d.push(` if (( _after_dd )); then return; fi`),d.push(` if [[ "$_cur" == -* ]]; then`),d.push(` local -a _avail=()`),d.push(...qe(s.options,a)),d.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),d.push(` compopt +o default 2>/dev/null`),c.length>0){d.push(` else`);let e=P(s.subcommands).map(e=>e.name).join(` `);d.push(...Ge(e,s.positionals,a,`root`,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(d.push(` else`),d.push(...q(s.positionals,a,`root`,s.options).map(e=>` ${e}`)));d.push(` fi`),d.push(`}`),d.push(``);let y=Oe(v,a).join(`
|
|
3
3
|
`);d.push(`_${a}_completions() {`),d.push(` COMPREPLY=()`),d.push(``),d.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),d.push(` local -a _words=()`),d.push(` local _i=1`),d.push(` while (( _i <= COMP_CWORD )); do`),d.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),d.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),d.push(` (( _i += 2 ))`),d.push(` else`),d.push(' _words+=("${COMP_WORDS[_i]}")'),d.push(` (( _i++ ))`),d.push(` fi`),d.push(` done`),d.push(``),d.push(` local _cur=""`),d.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),d.push(` local _inline_prefix=""`),d.push(``),d.push(` local _prev=""`),d.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),d.push(``),d.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),d.push(` local -a _used_opts=()`),p&&d.push(` local -a _pos_words=()`),d.push(` local _any_opt_used=0`),p&&(d.push(` ${K(`_arg_values_`)}`),d.push(` ${K(`_global_arg_values_`)}`)),g&&(d.push(` ${K(`_used_field_keys_`)}`),d.push(` ${K(`_global_used_field_keys_`)}`),d.push(` ${K(`_global_arr_seen_`)}`)),d.push(``),d.push(` local _j=0`),d.push(" while (( _j < ${#_words[@]} - 1 )); do"),d.push(' local _w="${_words[_j]}"'),d.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),d.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=p?`_pos_words+=("$_w"); `:``;d.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),d.push(` if [[ "$_w" == -*=* ]]; then`),d.push(' _used_opts+=("${_w%%=*}")'),d.push(` _any_opt_used=1`),p&&(d.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),g&&d.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),d.push(` (( _j++ )); continue`),d.push(` fi`),d.push(` if [[ "$_w" == -* ]]; then`),d.push(` _used_opts+=("$_w")`),d.push(` _any_opt_used=1`),d.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),d.push(' local _next="${_words[_j+1]:-}"'),d.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),p&&(d.push(` if (( _skip_next )); then`),d.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),g&&(d.push(" if (( _j + 2 < ${#_words[@]} )); then"),d.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),d.push(` fi`)),d.push(` fi`)),d.push(` fi`),d.push(` (( _j++ )); continue`),d.push(` fi`);let ee=g?`; ${K(`_arg_values_`)}; ${K(`_used_field_keys_`)}; ${K(`_global_arr_seen_`)}`:p?`; ${K(`_arg_values_`)}`:``,te=p?`_pos_words+=("$_w"); `:``;return v.length>0?d.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${p?`; _pos_words=()`:``}${ee}; else ${te}(( _pos_count++ )); fi`):(p&&d.push(` _pos_words+=("$_w")`),d.push(` (( _pos_count++ ))`)),d.push(` (( _j++ ))`),d.push(` done`),p&&d.push(` __${a}_track_positionals`),d.push(``),d.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),d.push(' _inline_prefix="${_cur%%=*}="'),d.push(' _cur="${_cur#*=}"'),d.push(` fi`),d.push(``),d.push(` case "$_subcmd" in`),d.push(y),d.push(` *) __${a}_complete_root ;;`),d.push(` esac`),d.push(`}`),d.push(``),o||d.push(`complete -o default -F _${a}_completions ${n}`),d.push(``),{script:d.join(`
|
|
4
4
|
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
@@ -13,7 +13,7 @@ source ~/.bashrc`}}const Xe=ue(de),Ze={bash:`bash`,zsh:`zsh`,fish:`fish`},Qe=[`#
|
|
|
13
13
|
`)){let t=e.match(/^# cmd-shim-target=(.+)$/);t&&(n=t[1])}return n}catch{return null}}function J(e,t){if(!t)return;e.add(D(le(t)));try{e.add(D(T(t)))}catch{}let n=rt(t);n&&J(e,n)}function it(e){return w(e,`utf8`).split(`
|
|
14
14
|
`,24).join(`
|
|
15
15
|
`)}function at(e,t){return[...Qe,`# program: ${e}`,`# shell: ${t}`]}function ot(e,t,n){let r=e.split(`
|
|
16
|
-
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function st(e,t,n){if(!C(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function ct(e,t,n){try{return st(e,t,n),!0}catch{return!1}}function lt(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n
|
|
16
|
+
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function st(e,t,n){if(!C(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function ct(e,t,n){try{return st(e,t,n),!0}catch{return!1}}function lt(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n=/* @__PURE__ */ new Set;e.binPath!==void 0&&J(n,e.binPath),process.argv[1]&&J(n,process.argv[1]),J(n,W(e.programName,e.binPath));for(let n of t)if(O(n)&&ct(n,e.programName,e.shell))return n;for(let r of n)for(let n of t){if(O(n))continue;let t=k(r,n);if(ct(t,e.programName,e.shell))return t}return null}function ut(e,t){return O(e)?e:le(t,e)}function dt(e,t,n){let r=e.startsWith(`.`)||e.includes(`/`)||e.includes(`\\`)?ut(e,n):e,i=se(r).toLowerCase();return i===`.js`||i===`.mjs`||i===`.cjs`?{command:process.execPath,args:[r,...t]}:{command:r,args:[...t]}}async function ft(e,t,n){let r=dt(e,t,n.cwd);try{let{stdout:e,stderr:t}=await Xe(r.command,r.args,{cwd:n.cwd,env:{...process.env,...n.env},encoding:`utf8`,maxBuffer:10485760});return{stdout:e,stderr:t}}catch(e){let t=typeof e==`object`&&e&&`stderr`in e?String(e.stderr??``).trim():``,n=t?`\n${t}`:``;throw Error(`Command failed: ${r.command} ${r.args.join(` `)}${n}`,e instanceof Error?{cause:e}:void 0)}}function pt(e){let t=E(e);if(!t.isFile()||t.size===0)throw Error(`Generated bundled completion worker is empty: ${e}`);return t.size}function mt(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KiB`}function ht(e,t,n){let r=ce(n,e);console.log(`Generated bundled completion worker: ${r&&!r.startsWith(`..`)?r:e} (${mt(t)})`)}async function gt(e){let t=e.cwd??process.cwd(),n=ut(e.outputPath??et(e.shell),t);re(D(n),{recursive:!0}),ae(n,{force:!0}),await ft(e.bin,[`__refresh-completion`,e.shell,n,`--static`,`--worker`],{cwd:t,env:e.env});let r=pt(n);st(n,e.programName,e.shell);let i;if(e.verify){let r=(await ft(e.bin,[`__completion-worker-path`,e.shell],{cwd:t,env:e.env})).stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);if(r.length!==1)throw Error(`Expected __completion-worker-path ${e.shell} to print exactly one path, got ${r.length}.`);i=ut(r[0],t);let a=T(n),o=T(i);if(o!==a)throw Error(`Bundled completion worker path mismatch: generated ${a}, reported ${o}`)}return e.quiet||ht(n,r,t),{outputPath:n,size:r,...i!==void 0&&{reportedPath:i}}}function _t(e){return x(`/${e}/node-compile-cache`)}function vt(e){return e?x(`${e}/node-compile-cache`):void 0}function yt(e,t){return e?x(`${e}/completion-worker.${t}`):void 0}function bt(e,t){return x(`/${e}/completion-worker.${t}`)}function Y(e,t,n){return t?` ${e} ${t}`:` ${e} "\${XDG_CACHE_HOME:-$HOME/.cache}"${n}`}function xt(e,t){return e?` printf '%s\\n' ${e}`:[` set -l _cache_root "$XDG_CACHE_HOME"`,` test -n "$_cache_root"; or set _cache_root "$HOME/.cache"`,` printf '%s\\n' "$_cache_root"${t}`].join(`
|
|
17
17
|
`)}function St(e,t){return nt(e.programName,t,e.bundledWorker).map(x).join(` `)}function Ct(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}"`}function wt(e){return nt(e.programName,`fish`,e.bundledWorker).map(Ct).join(` `)}function Tt(e){return e.bundledWorker?.queryCommand===!0&&!e.bundledWorker.disabled}function Et(e,t){let{programName:n}=t,r=A(n),i=`${r}_worker`,a=j(i),o=j(r),s=x(n),c=Y(`printf '%s\\n'`,vt(t.cacheDir),_t(n)),l=Y(`printf '%s\\n'`,yt(t.cacheDir,`bash`),bt(n,`bash`)),u=St(t,`bash`),d=Tt(t),f=[];return f.push(...G({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),f.push(`# Generated by politty`),f.push(`# politty-completion-mode: dispatcher`),f.push(``),f.push(`__${r}_resolve_bin() {`),f.push(` if [[ -n "\${${o}:-}" ]]; then`),f.push(` printf '%s\\n' "\${${o}}"`),f.push(` return 0`),f.push(` fi`),f.push(` type -P ${s} 2>/dev/null`),f.push(`}`),f.push(``),f.push(`__${r}_node_compile_cache_dir() {`),f.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),f.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),f.push(` return 0`),f.push(` fi`),f.push(c),f.push(`}`),f.push(``),f.push(`__${r}_static_worker_path() {`),f.push(l),f.push(`}`),f.push(``),f.push(`__${r}_worker_file_sig() {`),f.push(` local _worker="$1" _sig`),f.push(` _sig=${S(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),f.push(` printf '%s\\n' "$_sig"`),f.push(`}`),f.push(``),f.push(`__${r}_is_worker_file() {`),f.push(` local _worker="$1" _head`),f.push(` [[ -f "$_worker" ]] || return 1`),f.push(` _head="$(head -n 24 "$_worker" 2>/dev/null)" || return 1`),f.push(` _head=$'\\n'"$_head"$'\\n'`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# shell: bash"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),f.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),f.push(`}`),f.push(``),f.push(`__${r}_load_worker() {`),f.push(` local _worker="$1" _sig _key`),f.push(` __${r}_is_worker_file "$_worker" || return 1`),f.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),f.push(` _key="$_worker:$_sig"`),f.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),f.push(` source "$_worker" 2>/dev/null || return 1`),f.push(` __${r}_loaded_worker_key="$_key"`),f.push(` fi`),f.push(` declare -F _${i}_completions >/dev/null 2>&1`),f.push(`}`),f.push(``),f.push(`__${r}_realpath() {`),f.push(` local _path="$1" _dir _target _limit=0`),f.push(` while [[ -L "$_path" && $_limit -lt 40 ]]; do`),f.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),f.push(` _target="$(readlink "$_path")" || return 1`),f.push(` if [[ "$_target" == /* ]]; then _path="$_target"; else _path="$_dir/$_target"; fi`),f.push(` (( _limit++ ))`),f.push(` done`),f.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),f.push(` printf '%s\\n' "$_dir/$(basename "$_path")"`),f.push(`}`),f.push(``),f.push(`__${r}_worker_from_dir() {`),f.push(` local _dir="$1" _rel _candidate`),u.length>0&&(f.push(` for _rel in ${u}; do`),f.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),f.push(` if __${r}_is_worker_file "$_candidate"; then`),f.push(` printf '%s\\n' "$_candidate"`),f.push(` return 0`),f.push(` fi`),f.push(` done`)),f.push(` return 1`),f.push(`}`),f.push(``),f.push(`__${r}_cmd_shim_target() {`),f.push(` sed -n 's/^# cmd-shim-target=//p' "$1" 2>/dev/null | tail -n 1`),f.push(`}`),f.push(``),f.push(`__${r}_bundled_worker_path() {`),f.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),f.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),f.push(` if [[ -n "$_real" ]]; then`),f.push(` _dir="$(dirname "$_real")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` fi`),f.push(` _dir="$(dirname "$_bin")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),f.push(` if [[ -n "$_target" ]]; then`),f.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),f.push(` _dir="$(dirname "$_real")"`),f.push(` __${r}_worker_from_dir "$_dir" && return 0`),f.push(` fi`),d&&(f.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),f.push(` printf '%s\\n' "\${__${r}_queried_worker}"`),f.push(` return 0`),f.push(` fi`),f.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path bash 2>/dev/null)" || _reported=""`),f.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),f.push(` __${r}_queried_bin="$_bin"`),f.push(` __${r}_queried_worker="$_reported"`),f.push(` printf '%s\\n' "$_reported"`),f.push(` return 0`),f.push(` fi`)),f.push(` return 1`),f.push(`}`),f.push(``),f.push(`__${r}_bin_sig() {`),f.push(` local _bin="$1" _sig`),f.push(` _sig=${S(`$_bin`,{shell:`posix`})} || return 1`),f.push(` printf '%s\\n' "$_sig"`),f.push(`}`),f.push(``),f.push(`__${r}_worker_matches_bin() {`),f.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),f.push(` [[ -f "$_worker" ]] || return 1`),f.push(` _head="$(head -n 12 "$_worker" 2>/dev/null)" || return 1`),f.push(` grep -qxF "# politty-bin-sig: $_sig" <<< "$_head" || return 1`),f.push(` grep -qxF "# politty-bin-path: $_bin" <<< "$_head" || return 1`),f.push(`}`),f.push(``),f.push(`__${r}_apply_dynamic_output() {`),f.push(` local _raw="$1" _cur="$2" _inline_prefix="$3"`),f.push(` COMPREPLY=()`),f.push(` local _directive=0`),f.push(` local -a _lines=() _exts=() _matchers=()`),f.push(` local _line`),f.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),f.push(" local _last=$((${#_lines[@]} - 1))"),f.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" == :[0-9]* ]]; then'),f.push(` local -a _meta=()`),f.push(` IFS=$'\\t' read -r -a _meta <<< "\${_lines[$_last]}"`),f.push(` unset '_lines[_last]'`),f.push(' _directive="${_meta[0]#:}"'),f.push(` local _m`),f.push(' for _m in "${_meta[@]:1}"; do'),f.push(` if [[ "$_m" == @ext:* ]]; then`),f.push(` IFS=',' read -r -a _exts <<< "\${_m#@ext:}"`),f.push(` elif [[ "$_m" == @matcher:* ]]; then`),f.push(` IFS=',' read -r -a _matchers <<< "\${_m#@matcher:}"`),f.push(` fi`),f.push(` done`),f.push(` fi`),f.push(' for _line in "${_lines[@]}"; do'),f.push(` [[ -z "$_line" ]] && continue`),f.push(` COMPREPLY+=("$_line")`),f.push(` done`),f.push(' local _ip="${_inline_prefix:-}"'),f.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _f _ext _pat _base _ok`),f.push(` while IFS= read -r _f; do`),f.push(` if [[ -d "$_f" ]]; then`),f.push(' COMPREPLY+=("${_ip}${_f}")'),f.push(` continue`),f.push(` fi`),f.push(` _ok=0`),f.push(" if (( ${#_exts[@]} > 0 )); then"),f.push(' for _ext in "${_exts[@]}"; do'),f.push(` [[ -n "$_ext" && "$_f" == *."$_ext" ]] && _ok=1`),f.push(` done`),f.push(` fi`),f.push(" if (( ${#_matchers[@]} > 0 )); then"),f.push(' _base="${_f##*/}"'),f.push(' for _pat in "${_matchers[@]}"; do'),f.push(` [[ -n "$_pat" && "$_base" == $_pat ]] && _ok=1`),f.push(` done`),f.push(` fi`),f.push(' (( _ok )) && COMPREPLY+=("${_ip}${_f}")'),f.push(` done < <(compgen -f -- "$_cur")`),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${_.DirectoryCompletion} )); then`),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _d`),f.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${_.FileCompletion} )); then`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _p`),f.push(' while IFS= read -r _p; do COMPREPLY+=("${_ip}${_p}"); done < <(compgen -f -- "$_cur")'),f.push(` elif (( _directive & ${_.NoFileCompletion} )); then`),f.push(` local _need_empty=0`),f.push(` compopt +o default 2>/dev/null || _need_empty=1`),f.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` fi`),f.push(` if (( _directive & ${_.NoSpace} )); then`),f.push(` compopt -o nospace 2>/dev/null`),f.push(` fi`),f.push(`}`),f.push(``),f.push(`_${r}_completions() {`),f.push(` COMPREPLY=()`),f.push(` local -a _words=()`),f.push(` local _i=1`),f.push(` while (( _i <= COMP_CWORD )); do`),f.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),f.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),f.push(` (( _i += 2 ))`),f.push(` else`),f.push(' _words+=("${COMP_WORDS[_i]}")'),f.push(` (( _i++ ))`),f.push(` fi`),f.push(` done`),f.push(` local _cur="" _inline_prefix=""`),f.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),f.push(` local _after_dd=0 _di=0`),f.push(" while (( _di < ${#_words[@]} - 1 )); do"),f.push(' [[ "${_words[_di]}" == "--" ]] && { _after_dd=1; break; }'),f.push(` (( _di++ ))`),f.push(` done`),f.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),f.push(' _inline_prefix="${_cur%%=*}="'),f.push(' _cur="${_cur#*=}"'),f.push(` fi`),f.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),f.push(` _bin="$(__${r}_resolve_bin)" || _bin=""`),f.push(` [[ -n "$_bin" ]] || return 0`),f.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)" || _node_compile_cache=""`),f.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")" || _bundled_worker=""`),f.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),f.push(` return 0`),f.push(` fi`),f.push(` _worker="$(__${r}_static_worker_path)" || _worker=""`),f.push(` _sig="$(__${r}_bin_sig "$_bin")" || _sig=""`),f.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),f.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),f.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion bash "$_worker" --static --worker 2>/dev/null`),f.push(` fi`),f.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),f.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),f.push(` return 0`),f.push(` fi`),f.push(` fi`),f.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell bash -- "${_words[@]}" 2>/dev/null) || return 0'),f.push(` __${r}_apply_dynamic_output "$_out" "$_cur" "$_inline_prefix"`),f.push(`}`),f.push(``),f.push(`complete -o default -F _${r}_completions ${n}`),f.push(``),{script:f.join(`
|
|
18
18
|
`),shell:`bash`,installInstructions:`# To enable dispatcher bash completions, add this to your ~/.bashrc:
|
|
19
19
|
eval "$(${n} completion bash)"
|
|
@@ -41,7 +41,7 @@ ${n} completion zsh --static`}}function Ot(e,t){let{programName:n}=t,r=A(n),i=`$
|
|
|
41
41
|
${n} completion fish --install
|
|
42
42
|
|
|
43
43
|
# To generate the older static script:
|
|
44
|
-
${n} completion fish --static`}}function kt(e,t){switch(H(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return Et(e,t);case`zsh`:return Dt(e,t);case`fish`:return Ot(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function At(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function jt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=A(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=A(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${At(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Mt(e.matcher):e.extensions?.length?Nt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Mt(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Nt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Pt(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=jt(i.valueCompletion,n,b(i,e,t));if(a.length===0)continue;let o=R(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Ft(e,t,n,r=`$_pos_count`){let i=m(e,t);if(i.every(e=>e===void 0))return;let a=[` set _slot -1; set _left ${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?`; and __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`set _slot ${e.position}`:`if test $_left -eq 0; set _slot ${e.position}; else; set _left (math $_left - 1); end`;a.push(` if test $_slot -lt 0${o}; ${s}; end`)}),a}function Z(e,t,n=[]){if(e.length===0)return[];let r=Ft(e,n,t),i=r!==void 0,a=i?[` set -l _slot; set -l _left`,...r]:[];for(let r of e){let o=jt(r.valueCompletion,t,y(r,n,e));if(o.length!==0){i?a.push(` if test $_slot -eq ${r.position}`):r.variadic?a.push(` if test $_pos_count -ge ${r.position}`):a.push(` if test $_pos_count -eq ${r.position}`);for(let e of o)a.push(` ${e}`);a.push(` return`),a.push(` end`)}}return a}function It(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function Lt(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` if test $_any_opt_used -eq 0`),n.push(` echo "--help Show help"`),n.push(` echo "--help-all Show help with all subcommand options"`),n.push(` echo "--help-json Show help as JSON"`),n.push(` end`),n}function Rt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(A).join(`_`)}`,a=N(e.subcommands),o=[];for(let e of a)o.push(...Rt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Pt(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...Lt(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=P(e.subcommands);o.push(...It(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function zt(e,t){let n=[];for(let r of I(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Bt(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=l.length>0,f=l.filter(e=>e.isArrayOption),p=f.length>0,m=[];if(m.push(...G({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),!o){let e=W(n,t.binPath),r=U(e),o=j(i),s=`__${a}_refresh_completion`;m.push(`function ${s} --no-scope-shadowing`),m.push(` set -l _bin $${o}`),m.push(` test -z "$_bin"; and set _bin (command -v ${n})`),m.push(` test -z "$_bin"; and return 1`),m.push(` set -l _sig ${S(`$_bin`,{shell:`fish`})}`),m.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),m.push(` set -l _target (status current-filename)`),m.push(` test -n "$_target"; and test -f "$_target"; or return 1`),m.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),m.push(` and source "$_target" 2>/dev/null`),m.push(` and return 0`),m.push(` return 1`),m.push(`end`),m.push(`${s}`),m.push(`set -l _politty_refreshed $status`),m.push(`functions -e ${s}`),m.push(`test $_politty_refreshed -eq 0; and return`),m.push(``)}if(V(s)&&(m.push(`function __${a}_invoke_complete`),m.push(` set -l _shell $argv[1]`),m.push(` set -l _argv $argv[2..]`),m.push(` set -l _bin ${n}`),m.push(` if set -q ${j(a)}`),m.push(` set _bin $${j(a)}`),m.push(` end`),m.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),m.push(`end`),m.push(``),m.push(`function __${a}_apply_dynamic_output`),m.push(` set -l _cur $argv[1]`),m.push(` set -l _directive 0`),m.push(` set -l _emitted 0`),m.push(` set -l _prev ""`),m.push(` set -l _has_prev 0`),m.push(` while read -l _l`),m.push(` if test $_has_prev -eq 1`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` set _prev $_l`),m.push(` set _has_prev 1`),m.push(` end`),m.push(` if test $_has_prev -eq 1`),m.push(` if string match -qr '^:[0-9]+$' -- $_prev`),m.push(` set _directive (string sub -s 2 -- $_prev)`),m.push(` else`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` end`),m.push(` if test (math "bitand($_directive, ${_.DirectoryCompletion})") -ne 0`),m.push(` __fish_complete_directories "$_cur"`),m.push(` else if test (math "bitand($_directive, ${_.FileCompletion})") -ne 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${_.NoFileCompletion})") -eq 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` end`),m.push(`end`),m.push(``)),m.push(`function __${a}_not_used --no-scope-shadowing`),m.push(` for _chk in $argv`),m.push(` if contains -- "$_chk" $_used_opts`),m.push(` return 1`),m.push(` end`),m.push(` end`),m.push(` return 0`),m.push(`end`),m.push(``),m.push(`function __${a}_opt_takes_value`),m.push(` switch "$argv[1]:$argv[2]"`),m.push(...zt(s,``)),m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${A(e.fieldName)}`;m.push(`function __${a}_track_opt --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_pos --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_positionals --no-scope-shadowing`),m.push(` set -l _k 0`),m.push(` for _w in $_pos_words`),m.push(` set -l _slot $_k; set -l _left`),m.push(` switch "$_subcmd"`);for(let e of Te(s)){m.push(` case ${e.pathStrs.map(e=>`"${e}"`).join(` `)}`);for(let t of Ft(e.positionals,e.options,a,`$_k`)??[])m.push(` ${t}`)}m.push(` end`),m.push(` __${a}_track_pos "$_subcmd" "$_slot" "$_w"`),m.push(` set _k (math $_k + 1)`),m.push(` end`),m.push(`end`),m.push(``)}if(p){m.push(`function __${a}_track_array_expand --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of f){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=A(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;m.push(` case ${t}`),m.push(` if string match -q '*=*' -- "$argv[3]"`),m.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),m.push(` if test -n "$_k"`),e.isGlobal?(m.push(` if not set -q _global_arr_seen_${n}`),m.push(` set -g ${r}${n} "$_k"`),m.push(` set -g _global_arr_seen_${n} 1`),m.push(` else if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)):(m.push(` if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)),m.push(` end`),m.push(` end`)}m.push(` end`),m.push(`end`),m.push(``)}let h=L(s);if(h.length>0){m.push(`function __${a}_is_subcmd`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of h)m.push(` case "${e.lookupPattern}"`),m.push(` return 0`);m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``)}for(let e of c)m.push(...Rt(e,a,[]));if(m.push(`function __${a}_complete_root --no-scope-shadowing`),m.push(...Pt(s.options,s.positionals,a)),m.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(m.push(` if test $_after_dd -eq 1`),m.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),m.push(` return`),m.push(` end`)):m.push(` if test $_after_dd -eq 1; return; end`),m.push(` if string match -q -- '-*' "$_cur"`),m.push(...Lt(s.options,a)),c.length>0){m.push(` else`);let e=P(s.subcommands);m.push(...It(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(m.push(` else`),m.push(...Z(s.positionals,a,s.options)));if(m.push(` end`),m.push(`end`),m.push(``),m.push(`function __fish_${a}_complete`),m.push(` set -l _args (commandline -opc)`),m.push(` set -e _args[1]`),m.push(``),m.push(` set -l _ct (commandline -ct)`),m.push(` if test (count $_ct) -eq 0`),m.push(` set -a _args ""`),m.push(` else`),m.push(` set -a _args $_ct`),m.push(` end`),m.push(``),m.push(` set -l _cur ""`),m.push(` if test (count $_args) -gt 0`),m.push(` set _cur "$_args[-1]"`),m.push(` end`),m.push(``),m.push(` set -l _prev ""`),m.push(` if test (count $_args) -gt 1`),m.push(` set _prev "$_args[-2]"`),m.push(` end`),m.push(``),m.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),m.push(` set -l _used_opts`),d&&m.push(` set -l _pos_words`),m.push(` set -l _any_opt_used 0`),m.push(``),d)for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`),m.push(` set -e _global_arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`);m.push(` set -l _j 1`),m.push(` set -l _limit (math (count $_args) - 1)`),m.push(` while test $_j -le $_limit`),m.push(` set -l _w "$_args[$_j]"`),m.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),m.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let g=d?`set -a _pos_words "$_w"; `:``;if(m.push(` if test $_after_dd -eq 1; ${g}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),m.push(` if string match -q -- '-*=*' "$_w"`),m.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),m.push(` set -a _used_opts "$_opt"`),m.push(` set _any_opt_used 1`),d&&(m.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),m.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),p&&m.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),m.push(` if string match -q -- '-*' "$_w"`),m.push(` set -a _used_opts "$_w"`),m.push(` set _any_opt_used 1`),m.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),m.push(` set -l _next ""`),m.push(` set -l _next_idx (math $_j + 1)`),m.push(` if test $_next_idx -le (count $_args)`),m.push(` set _next "$_args[$_next_idx]"`),m.push(` end`),m.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),m.push(` set _skip_next 1`),d&&(m.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),p&&(m.push(` if test $_j -lt $_limit`),m.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` end`))),m.push(` end`),m.push(` end`),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),h.length>0){if(m.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),m.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),m.push(` set _used_opts; set _pos_count 0`),d){m.push(` set _pos_words`);for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`)}m.push(` else`),d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`),m.push(` end`)}else d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`);m.push(` set _j (math $_j + 1)`),m.push(` end`),d&&m.push(` __${a}_track_positionals`),m.push(``),m.push(` switch "$_subcmd"`);for(let e of h)m.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return m.push(` case '*'; __${a}_complete_root`),m.push(` end`),m.push(`end`),m.push(``),o||(m.push(`# Clear existing completions`),m.push(`complete -e -c ${n}`),m.push(``),m.push(`# Register completion`),m.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),m.push(``),{script:m.join(`
|
|
44
|
+
${n} completion fish --static`}}function kt(e,t){switch(H(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return Et(e,t);case`zsh`:return Dt(e,t);case`fish`:return Ot(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function At(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function jt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=A(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=A(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${At(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=/* @__PURE__ */ new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Mt(e.matcher):e.extensions?.length?Nt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Mt(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Nt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Pt(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=jt(i.valueCompletion,n,b(i,e,t));if(a.length===0)continue;let o=R(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Ft(e,t,n,r=`$_pos_count`){let i=m(e,t);if(i.every(e=>e===void 0))return;let a=[` set _slot -1; set _left ${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?`; and __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`set _slot ${e.position}`:`if test $_left -eq 0; set _slot ${e.position}; else; set _left (math $_left - 1); end`;a.push(` if test $_slot -lt 0${o}; ${s}; end`)}),a}function Z(e,t,n=[]){if(e.length===0)return[];let r=Ft(e,n,t),i=r!==void 0,a=i?[` set -l _slot; set -l _left`,...r]:[];for(let r of e){let o=jt(r.valueCompletion,t,y(r,n,e));if(o.length!==0){i?a.push(` if test $_slot -eq ${r.position}`):r.variadic?a.push(` if test $_pos_count -ge ${r.position}`):a.push(` if test $_pos_count -eq ${r.position}`);for(let e of o)a.push(` ${e}`);a.push(` return`),a.push(` end`)}}return a}function It(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function Lt(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=d(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` if test $_any_opt_used -eq 0`),n.push(` echo "--help Show help"`),n.push(` echo "--help-all Show help with all subcommand options"`),n.push(` echo "--help-json Show help as JSON"`),n.push(` end`),n}function Rt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(A).join(`_`)}`,a=N(e.subcommands),o=[];for(let e of a)o.push(...Rt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Pt(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...Lt(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=P(e.subcommands);o.push(...It(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function zt(e,t){let n=[];for(let r of I(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Bt(e,t){let{programName:n}=t,r=H(e,n,t.globalArgsSchema),i=A(n),a=t.staticWorker?`${i}_${A(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=N(s.subcommands),l=z(s),u=B(s,l,r.globalOptions),d=l.length>0,f=l.filter(e=>e.isArrayOption),p=f.length>0,m=[];if(m.push(...G({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),m.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&m.push(`# politty-completion-worker: true`),m.push(`# Generated by politty`),m.push(``),!o){let e=W(n,t.binPath),r=U(e),o=j(i),s=`__${a}_refresh_completion`;m.push(`function ${s} --no-scope-shadowing`),m.push(` set -l _bin $${o}`),m.push(` test -z "$_bin"; and set _bin (command -v ${n})`),m.push(` test -z "$_bin"; and return 1`),m.push(` set -l _sig ${S(`$_bin`,{shell:`fish`})}`),m.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),m.push(` set -l _target (status current-filename)`),m.push(` test -n "$_target"; and test -f "$_target"; or return 1`),m.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),m.push(` and source "$_target" 2>/dev/null`),m.push(` and return 0`),m.push(` return 1`),m.push(`end`),m.push(`${s}`),m.push(`set -l _politty_refreshed $status`),m.push(`functions -e ${s}`),m.push(`test $_politty_refreshed -eq 0; and return`),m.push(``)}if(V(s)&&(m.push(`function __${a}_invoke_complete`),m.push(` set -l _shell $argv[1]`),m.push(` set -l _argv $argv[2..]`),m.push(` set -l _bin ${n}`),m.push(` if set -q ${j(a)}`),m.push(` set _bin $${j(a)}`),m.push(` end`),m.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),m.push(`end`),m.push(``),m.push(`function __${a}_apply_dynamic_output`),m.push(` set -l _cur $argv[1]`),m.push(` set -l _directive 0`),m.push(` set -l _emitted 0`),m.push(` set -l _prev ""`),m.push(` set -l _has_prev 0`),m.push(` while read -l _l`),m.push(` if test $_has_prev -eq 1`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` set _prev $_l`),m.push(` set _has_prev 1`),m.push(` end`),m.push(` if test $_has_prev -eq 1`),m.push(` if string match -qr '^:[0-9]+$' -- $_prev`),m.push(` set _directive (string sub -s 2 -- $_prev)`),m.push(` else`),m.push(` if test -n "$_prev"`),m.push(` printf '%s\\n' "$_prev"`),m.push(` set _emitted 1`),m.push(` end`),m.push(` end`),m.push(` end`),m.push(` if test (math "bitand($_directive, ${_.DirectoryCompletion})") -ne 0`),m.push(` __fish_complete_directories "$_cur"`),m.push(` else if test (math "bitand($_directive, ${_.FileCompletion})") -ne 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${_.NoFileCompletion})") -eq 0`),m.push(` __fish_complete_path "$_cur"`),m.push(` end`),m.push(`end`),m.push(``)),m.push(`function __${a}_not_used --no-scope-shadowing`),m.push(` for _chk in $argv`),m.push(` if contains -- "$_chk" $_used_opts`),m.push(` return 1`),m.push(` end`),m.push(` end`),m.push(` return 0`),m.push(`end`),m.push(``),m.push(`function __${a}_opt_takes_value`),m.push(` switch "$argv[1]:$argv[2]"`),m.push(...zt(s,``)),m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${A(e.fieldName)}`;m.push(`function __${a}_track_opt --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_pos --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);m.push(` case ${n}`),m.push(` set -g ${e(t)} "$argv[3]"`)}m.push(` end`),m.push(`end`),m.push(``),m.push(`function __${a}_track_positionals --no-scope-shadowing`),m.push(` set -l _k 0`),m.push(` for _w in $_pos_words`),m.push(` set -l _slot $_k; set -l _left`),m.push(` switch "$_subcmd"`);for(let e of Te(s)){m.push(` case ${e.pathStrs.map(e=>`"${e}"`).join(` `)}`);for(let t of Ft(e.positionals,e.options,a,`$_k`)??[])m.push(` ${t}`)}m.push(` end`),m.push(` __${a}_track_pos "$_subcmd" "$_slot" "$_w"`),m.push(` set _k (math $_k + 1)`),m.push(` end`),m.push(`end`),m.push(``)}if(p){m.push(`function __${a}_track_array_expand --no-scope-shadowing`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of f){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=A(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;m.push(` case ${t}`),m.push(` if string match -q '*=*' -- "$argv[3]"`),m.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),m.push(` if test -n "$_k"`),e.isGlobal?(m.push(` if not set -q _global_arr_seen_${n}`),m.push(` set -g ${r}${n} "$_k"`),m.push(` set -g _global_arr_seen_${n} 1`),m.push(` else if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)):(m.push(` if not contains -- "$_k" $${r}${n}`),m.push(` set -ga ${r}${n} "$_k"`),m.push(` end`)),m.push(` end`),m.push(` end`)}m.push(` end`),m.push(`end`),m.push(``)}let h=L(s);if(h.length>0){m.push(`function __${a}_is_subcmd`),m.push(` switch "$argv[1]:$argv[2]"`);for(let e of h)m.push(` case "${e.lookupPattern}"`),m.push(` return 0`);m.push(` end`),m.push(` return 1`),m.push(`end`),m.push(``)}for(let e of c)m.push(...Rt(e,a,[]));if(m.push(`function __${a}_complete_root --no-scope-shadowing`),m.push(...Pt(s.options,s.positionals,a)),m.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(m.push(` if test $_after_dd -eq 1`),m.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),m.push(` return`),m.push(` end`)):m.push(` if test $_after_dd -eq 1; return; end`),m.push(` if string match -q -- '-*' "$_cur"`),m.push(...Lt(s.options,a)),c.length>0){m.push(` else`);let e=P(s.subcommands);m.push(...It(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(m.push(` else`),m.push(...Z(s.positionals,a,s.options)));if(m.push(` end`),m.push(`end`),m.push(``),m.push(`function __fish_${a}_complete`),m.push(` set -l _args (commandline -opc)`),m.push(` set -e _args[1]`),m.push(``),m.push(` set -l _ct (commandline -ct)`),m.push(` if test (count $_ct) -eq 0`),m.push(` set -a _args ""`),m.push(` else`),m.push(` set -a _args $_ct`),m.push(` end`),m.push(``),m.push(` set -l _cur ""`),m.push(` if test (count $_args) -gt 0`),m.push(` set _cur "$_args[-1]"`),m.push(` end`),m.push(``),m.push(` set -l _prev ""`),m.push(` if test (count $_args) -gt 1`),m.push(` set _prev "$_args[-2]"`),m.push(` end`),m.push(``),m.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),m.push(` set -l _used_opts`),d&&m.push(` set -l _pos_words`),m.push(` set -l _any_opt_used 0`),m.push(``),d)for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`),m.push(` set -e _global_arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`);m.push(` set -l _j 1`),m.push(` set -l _limit (math (count $_args) - 1)`),m.push(` while test $_j -le $_limit`),m.push(` set -l _w "$_args[$_j]"`),m.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),m.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let g=d?`set -a _pos_words "$_w"; `:``;if(m.push(` if test $_after_dd -eq 1; ${g}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),m.push(` if string match -q -- '-*=*' "$_w"`),m.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),m.push(` set -a _used_opts "$_opt"`),m.push(` set _any_opt_used 1`),d&&(m.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),m.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),p&&m.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),m.push(` if string match -q -- '-*' "$_w"`),m.push(` set -a _used_opts "$_w"`),m.push(` set _any_opt_used 1`),m.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),m.push(` set -l _next ""`),m.push(` set -l _next_idx (math $_j + 1)`),m.push(` if test $_next_idx -le (count $_args)`),m.push(` set _next "$_args[$_next_idx]"`),m.push(` end`),m.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),m.push(` set _skip_next 1`),d&&(m.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),p&&(m.push(` if test $_j -lt $_limit`),m.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),m.push(` end`))),m.push(` end`),m.push(` end`),m.push(` set _j (math $_j + 1); continue`),m.push(` end`),h.length>0){if(m.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),m.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),m.push(` set _used_opts; set _pos_count 0`),d){m.push(` set _pos_words`);for(let e of u)m.push(` set -e _arg_values_${A(e.fieldName)}`);if(p)for(let e of f)m.push(` set -e _used_field_keys_${A(e.fieldName)}`),m.push(` set -e _global_arr_seen_${A(e.fieldName)}`)}m.push(` else`),d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`),m.push(` end`)}else d&&m.push(` set -a _pos_words "$_w"`),m.push(` set _pos_count (math $_pos_count + 1)`);m.push(` set _j (math $_j + 1)`),m.push(` end`),d&&m.push(` __${a}_track_positionals`),m.push(``),m.push(` switch "$_subcmd"`);for(let e of h)m.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return m.push(` case '*'; __${a}_complete_root`),m.push(` end`),m.push(`end`),m.push(``),o||(m.push(`# Clear existing completions`),m.push(`complete -e -c ${n}`),m.push(``),m.push(`# Register completion`),m.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),m.push(``),{script:m.join(`
|
|
45
45
|
`),shell:`fish`,installInstructions:`# To enable auto-refreshing fish completions, run:
|
|
46
46
|
${n} completion fish --install --static`}}function Vt(e,t){re(D(e),{recursive:!0});let n=`${e}.tmp.${process.pid}`;oe(n,t),ie(n,e)}function Ht(e,t){return un(e.rootCommand,{shell:t,programName:e.programName,mode:e.completionMode??`dispatcher`,includeDescriptions:!0,...e.programVersion!==void 0&&{programVersion:e.programVersion},...e.binPath!==void 0&&{binPath:e.binPath},...e.cacheDir!==void 0&&{cacheDir:e.cacheDir},...e.globalArgsSchema!==void 0&&{globalArgsSchema:e.globalArgsSchema},...e.bundledWorker!==void 0&&{bundledWorker:e.bundledWorker},...e.staticWorker!==void 0&&{staticWorker:e.staticWorker}}).script}function Ut(e,t){let n=a(e.programName,t,e.cacheDir);return Vt(n,Ht(e,t)),n}function Wt(e){try{if(!C(e))return;let t=w(e,`utf8`).split(`
|
|
47
47
|
`,10).join(`
|
package/dist/completion.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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 { $ as ResolvedFieldMeta, S as ArgsSchema, T as Command, _ as DynamicCompletionResult, b as AnyCommand, d as ExpandCompletion, g as DynamicCompletionResolver, h as DynamicCompletionContext, m as DynamicCompletionCandidate, p as CompletionDirectiveMask } from "./arg-registry-vcm6uTB1.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-DR98pkpR.js";
|
|
3
3
|
//#region ../core/src/completion/schemas.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Schema for the completion command arguments
|
package/dist/completion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-TbOCQNeI.js";import{s as e,t}from"./with-completion-command-DG-C9_0Z.js";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./dynamic-DbvYJg3o.js";import{a as l,c as u,d,i as f,l as p,n as m,o as h,r as g,s as _,t as v,u as y}from"./completion-nNzHfI1i.js";export{r as CompletionDirective,h as bundledWorkerShellExtension,v as createCompletionCommand,m as createCompletionWorkerPathCommand,c as createDynamicCompleteCommand,g as createRefreshCompletionCommand,_ as defaultBundledWorkerOutputPath,e as detectShell,y as extractCompletionData,d as extractPositionals,o as formatForShell,u as generateBundledCompletionWorker,n as generateCandidates,f as generateCompletion,l as getSupportedShells,i as hasCompleteCommand,a as parseCompletionContext,s as resolveValueCompletion,p as validateBundledWorkerFile,t as withCompletionCommand};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{existsSync as e}from"node:fs";const t=[`cursor`,`cursor-cli`,`kimi`,`grok`,`gemini_cli`,`cline`,`codex_cli`,`antigravity`,`augment-cli`,`open_code`,`goose`,`junie`,`pi`,`cowork`,`claude_code`,`replit`,`github-copilot`,`kiro`,`openclaw`,`devin`];var n=`AI_AGENT`;
|
|
2
|
+
/*! Agent detection data from vercel/detect-agent (https://github.com/vercel/detect-agent), Copyright Vercel, Inc., Apache-2.0 (http://www.apache.org/licenses/LICENSE-2.0) */
|
|
3
|
+
const r=[{key:`CURSOR`,name:`cursor`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`CURSOR_TRACE_ID`}]}},{key:`CURSOR_CLI`,name:`cursor-cli`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`CURSOR_AGENT`},{type:`env_value`,name:`CURSOR_EXTENSION_HOST_ROLE`,value:`agent-exec`}]}},{key:`KIMI`,name:`kimi`,description:`Kimi Code plugin hooks. KIMI_CODE_HOME may be configured outside an active Kimi session, so detection uses the plugin-scoped KIMI_PLUGIN_ROOT marker.`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`KIMI_PLUGIN_ROOT`}]}},{key:`GROK`,name:`grok`,description:`Grok Build plugin hooks. Evaluated before Claude Code because Grok supports Claude Code plugins and may expose compatibility markers.`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`GROK_PLUGIN_ROOT`},{type:`env_set`,name:`GROK_PLUGIN_DATA`}]}},{key:`GEMINI`,name:`gemini_cli`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`GEMINI_CLI`}]}},{key:`CLINE`,name:`cline`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`CLINE_ACTIVE`}]}},{key:`CODEX`,name:`codex_cli`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`CODEX_SANDBOX`},{type:`env_set`,name:`CODEX_CI`},{type:`env_set`,name:`CODEX_THREAD_ID`},{type:`env_set`,name:`CODEX_SANDBOX_NETWORK_DISABLED`}]}},{key:`ANTIGRAVITY`,name:`antigravity`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`ANTIGRAVITY_AGENT`},{type:`env_set`,name:`ANTIGRAVITY_CLI_ALIAS`}]}},{key:`AUGMENT_CLI`,name:`augment-cli`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`AUGMENT_AGENT`}]}},{key:`OPENCODE`,name:`open_code`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`OPENCODE_CLIENT`},{type:`env_set`,name:`OPENCODE`}]}},{key:`GOOSE`,name:`goose`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`GOOSE_PROVIDER`}]}},{key:`JUNIE`,name:`junie`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`JUNIE_DATA`},{type:`env_set`,name:`JUNIE_SHIM_PATH`}]}},{key:`PI`,name:`pi`,description:`Matches when the PATH contains a '.pi/agent' (or '.pi\\\\agent') segment.`,match:{type:`anyOf`,conditions:[{type:`env_matches`,name:`PATH`,pattern:`\\.pi[\\\\/]agent`}]}},{key:`COWORK`,name:`cowork`,description:"Claude Cowork. Evaluated before `claude_code` so the more specific COWORK marker wins. Requires CLAUDE_CODE_IS_COWORK plus a Claude Code marker.",match:{type:`allOf`,conditions:[{type:`env_set`,name:`CLAUDE_CODE_IS_COWORK`},{type:`anyOf`,conditions:[{type:`env_set`,name:`CLAUDECODE`},{type:`env_set`,name:`CLAUDE_CODE`}]}]}},{key:`CLAUDE`,name:`claude_code`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`CLAUDECODE`},{type:`env_set`,name:`CLAUDE_CODE`}]}},{key:`REPLIT`,name:`replit`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`REPL_ID`}]}},{key:`GITHUB_COPILOT`,name:`github-copilot`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`COPILOT_MODEL`},{type:`env_set`,name:`COPILOT_ALLOW_ALL`},{type:`env_set`,name:`COPILOT_GITHUB_TOKEN`}]}},{key:`KIRO`,name:`kiro`,description:`AWS Kiro. TERM_PROGRAM=kiro is set by both the IDE terminal and the CLI agent, so gate on no_tty to avoid misdetecting a human at the integrated terminal.`,match:{type:`allOf`,conditions:[{type:`env_matches`,name:`TERM_PROGRAM`,pattern:`kiro`},{type:`no_tty`}]}},{key:`OPENCLAW`,name:`openclaw`,match:{type:`anyOf`,conditions:[{type:`env_set`,name:`OPENCLAW_SHELL`}]}},{key:`DEVIN`,name:`devin`,match:{type:`anyOf`,conditions:[{type:`file_exists`,path:`/opt/.devin`}]}}],i=new Set(t);function a(e){return i.has(e)}function o(e,t,n){switch(e.type){case`env_set`:return!!t[e.name];case`env_value`:return t[e.name]===e.value;case`env_matches`:{let n=t[e.name];if(!n)return!1;try{return new RegExp(e.pattern).test(n)}catch{return!1}}case`no_tty`:return!n.isTTY;case`file_exists`:try{return n.fileExists(e.path)}catch{return!1}case`anyOf`:return e.conditions.some(e=>o(e,t,n));case`allOf`:return e.conditions.every(e=>o(e,t,n));default:return!1}}function s(t=process.env,i={}){try{if(t.POLITTY_NO_AGENT)return;let s=t[n]?.trim();if(s&&a(s))return{id:s,rawId:s};let c={isTTY:i.isTTY??process.stdout?.isTTY??!1,fileExists:i.fileExists??e},l=r.find(e=>o(e.match,t,c))?.name??s;return l?{id:l,rawId:s||l}:void 0}catch{return}}export{s as t};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region ../core/src/agent/known-agent-ids.d.ts
|
|
2
|
+
declare const KNOWN_AGENT_IDS: readonly ["cursor", "cursor-cli", "kimi", "grok", "gemini_cli", "cline", "codex_cli", "antigravity", "augment-cli", "open_code", "goose", "junie", "pi", "cowork", "claude_code", "replit", "github-copilot", "kiro", "openclaw", "devin"];
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region ../core/src/agent/detect-agent.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Agent name defined by the detect-agent spec (e.g. `"claude_code"`,
|
|
7
|
+
* `"codex_cli"`). Names follow upstream and may change with it.
|
|
8
|
+
*/
|
|
9
|
+
type KnownAgentId = (typeof KNOWN_AGENT_IDS)[number];
|
|
10
|
+
/**
|
|
11
|
+
* An AI coding agent detected from the environment.
|
|
12
|
+
*/
|
|
13
|
+
interface AgentInfo {
|
|
14
|
+
/**
|
|
15
|
+
* The spec's name for the agent: `AI_AGENT` when it is a known name,
|
|
16
|
+
* otherwise the first spec agent whose markers match, falling back to the
|
|
17
|
+
* custom `AI_AGENT` value when none does.
|
|
18
|
+
*/
|
|
19
|
+
id: KnownAgentId | (string & {});
|
|
20
|
+
/**
|
|
21
|
+
* The id as the detect-agent spec reports it: the trimmed `AI_AGENT` value
|
|
22
|
+
* when non-empty (e.g. `"claude-code_2-1-284_agent"`), otherwise the same as
|
|
23
|
+
* `id`.
|
|
24
|
+
*/
|
|
25
|
+
rawId: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Overrides for the non-env inputs of {@link detectAgent}, mainly for tests.
|
|
29
|
+
*/
|
|
30
|
+
interface DetectAgentOptions {
|
|
31
|
+
/** Whether stdout is a TTY (default: `process.stdout.isTTY`) */
|
|
32
|
+
isTTY?: boolean | undefined;
|
|
33
|
+
/** File existence check (default: `fs.existsSync`) */
|
|
34
|
+
fileExists?: ((path: string) => boolean) | undefined;
|
|
35
|
+
}
|
|
36
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
37
|
+
/**
|
|
38
|
+
* Detect whether the process runs under an AI coding agent, following the
|
|
39
|
+
* [detect-agent](https://github.com/vercel/detect-agent) spec: a non-empty
|
|
40
|
+
* `AI_AGENT` (trimmed) wins as `rawId`, then the spec's agents are checked in
|
|
41
|
+
* order. `id` normalizes the result to a spec name when possible.
|
|
42
|
+
* `POLITTY_NO_AGENT` (any non-empty value) disables detection. Never throws.
|
|
43
|
+
*
|
|
44
|
+
* @param env - Environment to inspect (default: `process.env`)
|
|
45
|
+
* @returns The detected agent, or `undefined`
|
|
46
|
+
*/
|
|
47
|
+
declare function detectAgent(env?: Env, options?: DetectAgentOptions): AgentInfo | undefined;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { detectAgent as i, DetectAgentOptions as n, KnownAgentId as r, AgentInfo as t };
|
package/dist/docs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as ResolvedFieldMeta, D as Example, K as SubCommandValue, Q as ExtractedFields, S as ArgsSchema, b as AnyCommand, it as SchemaLike } from "./arg-registry-vcm6uTB1.js";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
//#region ../core/src/executor/subcommand-router.d.ts
|
|
4
4
|
/**
|