@kjanat/dreamcli 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-CuhI1Ynv.d.mts → command-Cq6YZjEH.d.mts} +1693 -1591
- package/dist/completion-DCWRvQjQ.mjs +59 -0
- package/dist/completion.d.mts +1 -1
- package/dist/completion.mjs +1 -1
- package/dist/{config-DSh3QJpX.mjs → config-CANc4lsA.mjs} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/core-CPh0FcFg.mjs +25 -0
- package/dist/dynamic-xPNS3_vL.mjs +1 -0
- package/dist/{index-DIWRV_wp.d.mts → index-8EiEDJfX.d.mts} +33 -7
- package/dist/{index-DDhRLoTu.d.mts → index-BZ3jYjyh.d.mts} +12 -3
- package/dist/{index-Vjl2_m23.d.mts → index-Bkk86gFg.d.mts} +16 -11
- package/dist/{index-aTmg9yfl.d.mts → index-CLg6j-KJ.d.mts} +1 -1
- package/dist/{index-CLtWJqwn.d.mts → index-DBepo8jX.d.mts} +23 -4
- package/dist/index.d.mts +9 -9
- package/dist/index.mjs +1 -1
- package/dist/json-schema-DmFJR8c6.mjs +59 -0
- package/dist/json-schema.d.mts +1 -1
- package/dist/json-schema.mjs +1 -1
- package/dist/prompt.d.mts +1 -1
- package/dist/prompt.mjs +1 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +1 -1
- package/dist/{session-BEKj0yLA.mjs → session-BBRg9p2u.mjs} +1 -1
- package/dist/{terminal-Dws_b5UK.mjs → terminal-mINn5p7B.mjs} +1 -1
- package/dist/{test-prompter-euLYzWWO.mjs → test-prompter-BI9sA9n7.mjs} +1 -1
- package/dist/testkit.d.mts +3 -3
- package/dist/testkit.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/dreamcli.schema.json +175 -0
- package/package.json +9 -10
- package/dist/completion-B4oRc2Ae.mjs +0 -59
- package/dist/core-BZx351-p.mjs +0 -21
- package/dist/dynamic-BK2lQF2M.mjs +0 -1
- package/dist/json-schema-CYgq_hFu.mjs +0 -59
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{j as PromptCancelledError,n as prepareTextAnswer
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{_t as CLIError,j as PromptCancelledError,n as prepareTextAnswer}from"./core-CPh0FcFg.mjs";var terminal_exports=/* @__PURE__ */ __exportAll({createTerminalPrompter:()=>createTerminalPrompter});function createTerminalPrompter(e,t,n){return{promptOne(r){switch(r.kind){case`confirm`:return promptConfirm(r,e,t);case`input`:return promptInput(r,e,t);case`password`:{let e=n?.readSecret;return e===void 0?Promise.reject(new CLIError(`Hidden password input is unavailable`,{code:`PROMPT_UNSUPPORTED`,suggest:`Use a runtime adapter or prompt engine with hidden-input support`})):promptInput(r,async()=>{try{let t=await e();if(t===null)throw new PromptCancelledError(`eof`);return t}finally{t(`
|
|
2
2
|
`)}},t)}case`select`:return promptSelect(r,e,t);case`multiselect`:return promptMultiselect(r,e,t)}}}}async function promptConfirm(e,t,n){let r=e.default??!0,i=0;for(;i<10;){let a=e.sensitive?`(y/n)`:r?`(Y/n)`:`(y/N)`;n(`${e.message} ${a} `);let o=await t();if(o===null)return{answered:!1};let s=o.trim().toLowerCase();if(s===``)return{answered:!0,value:r};if(s===`y`||s===`yes`)return{answered:!0,value:!0};if(s===`n`||s===`no`)return{answered:!0,value:!1};n(`Please answer y or n.
|
|
3
3
|
`),i+=1}return n(`Too many invalid attempts.
|
|
4
4
|
`),{answered:!1,reason:`invalid`}}async function promptInput(e,t,n){let r=0,i=[];e.kind===`input`&&e.placeholder!==void 0&&i.push(e.placeholder),e.kind===`input`&&e.default!==void 0&&!e.sensitive&&i.push(`default: ${e.default}`);let a=i.length>0?` (${i.join(`, `)})`:``;for(;r<10;){n(`${e.message}${a}: `);let i=await t();if(i===null)return{answered:!1};let o=await prepareTextAnswer(e,i);if(o.ok)return{answered:!0,value:o.value};n(`${o.message}\n`),r+=1}if(e.kind===`password`)throw new CLIError(`Too many invalid prompt answers`,{code:`PROMPT_INVALID`,exitCode:2});return n(`Too many invalid attempts.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{j as PromptCancelledError,n as prepareTextAnswer
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{_t as CLIError,j as PromptCancelledError,n as prepareTextAnswer}from"./core-CPh0FcFg.mjs";var test_prompter_exports=/* @__PURE__ */ __exportAll({createTestPrompter:()=>createTestPrompter});const PROMPT_CANCEL=Symbol.for(`dreamcli.prompt.cancel`);function createTestPrompter(e,t){let n=0;return{async promptOne(r){for(let i=0;i<10;i++){if(n>=e.length)return t?.onExhausted===`cancel`?Promise.resolve({answered:!1}):Promise.reject(/* @__PURE__ */ Error(`Test prompter exhausted: expected at most ${e.length} prompts, got prompt #${n+1}`));let i=e[n];if(n+=1,i===PROMPT_CANCEL){if(r.kind===`password`)throw new PromptCancelledError;return Promise.resolve({answered:!1})}if((r.kind===`input`||r.kind===`password`)&&typeof i==`string`){let e=await prepareTextAnswer(r,i);if(!e.ok&&(r.kind===`password`||e.reason===`empty`))continue;return e.ok?{answered:!0,value:e.value}:{answered:!1}}return Promise.resolve({answered:!0,value:i})}if(r.kind!==`password`)return{answered:!1,reason:`invalid`};throw new CLIError(`Too many invalid prompt answers`,{code:`PROMPT_INVALID`,exitCode:2})}}}export{createTestPrompter as n,test_prompter_exports as r,PROMPT_CANCEL as t};
|
package/dist/testkit.d.mts
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module @kjanat/dreamcli/testkit
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
16
|
-
import { a as TestPrompterOptions, b as SkippedPathCheck, i as TestAnswer, j as BuiltinsConfig, n as RunResult, o as createTestPrompter, r as PROMPT_CANCEL, t as RunOptions } from "./index-
|
|
17
|
-
import "./index-
|
|
15
|
+
import { B as createTestAdapter, Gt as FlagBuilder, Kt as FlagConfig, Y as createCaptureOutput, a as CommandBuilder, nt as ArgBuilder, q as CapturedOutput, rt as ArgConfig, z as TestAdapterOptions } from "./command-Cq6YZjEH.mjs";
|
|
16
|
+
import { a as TestPrompterOptions, b as SkippedPathCheck, i as TestAnswer, j as BuiltinsConfig, n as RunResult, o as createTestPrompter, r as PROMPT_CANCEL, t as RunOptions } from "./index-BZ3jYjyh.mjs";
|
|
17
|
+
import "./index-CLg6j-KJ.mjs";
|
|
18
18
|
/**
|
|
19
19
|
* Options for {@linkcode runCommand}.
|
|
20
20
|
*
|
package/dist/testkit.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{M as createCaptureOutput,O as createTestAdapter,t as runCommand}from"./core-
|
|
1
|
+
import{M as createCaptureOutput,O as createTestAdapter,t as runCommand}from"./core-CPh0FcFg.mjs";import{n as createTestPrompter,t as PROMPT_CANCEL}from"./test-prompter-BI9sA9n7.mjs";export{PROMPT_CANCEL,createCaptureOutput,createTestAdapter,createTestPrompter,runCommand};
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const DREAMCLI_VERSION=`5.
|
|
1
|
+
const DREAMCLI_VERSION=`5.2.0`,DREAMCLI_REVISION=`ec4a86b`;export{DREAMCLI_REVISION,DREAMCLI_VERSION};
|
package/dreamcli.schema.json
CHANGED
|
@@ -74,6 +74,10 @@
|
|
|
74
74
|
"description": "Environment variable name for env resolution.\n\nWhen set and the CLI value is absent, the resolver reads this env var\nand coerces the string to the arg's declared kind.",
|
|
75
75
|
"type": "string"
|
|
76
76
|
},
|
|
77
|
+
"group": {
|
|
78
|
+
"description": "Named section in command help.",
|
|
79
|
+
"type": "string"
|
|
80
|
+
},
|
|
77
81
|
"kind": {
|
|
78
82
|
"description": "What kind of value this arg accepts.",
|
|
79
83
|
"enum": [
|
|
@@ -265,6 +269,63 @@
|
|
|
265
269
|
"$ref": "#/$defs/command"
|
|
266
270
|
}
|
|
267
271
|
},
|
|
272
|
+
"constraints": {
|
|
273
|
+
"description": "Relationships checked after input resolution.",
|
|
274
|
+
"type": "array",
|
|
275
|
+
"items": {
|
|
276
|
+
"type": "object",
|
|
277
|
+
"required": [
|
|
278
|
+
"inputs",
|
|
279
|
+
"kind"
|
|
280
|
+
],
|
|
281
|
+
"properties": {
|
|
282
|
+
"inputs": {
|
|
283
|
+
"type": "array",
|
|
284
|
+
"minItems": 2,
|
|
285
|
+
"uniqueItems": true,
|
|
286
|
+
"items": {
|
|
287
|
+
"$ref": "#/$defs/constraintInput"
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
"kind": {
|
|
291
|
+
"enum": [
|
|
292
|
+
"conflicts",
|
|
293
|
+
"requires",
|
|
294
|
+
"exactlyOne",
|
|
295
|
+
"atMostOne",
|
|
296
|
+
"allOrNone"
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
"additionalProperties": false,
|
|
301
|
+
"anyOf": [
|
|
302
|
+
{
|
|
303
|
+
"properties": {
|
|
304
|
+
"inputs": {
|
|
305
|
+
"maxItems": 2
|
|
306
|
+
},
|
|
307
|
+
"kind": {
|
|
308
|
+
"enum": [
|
|
309
|
+
"conflicts",
|
|
310
|
+
"requires"
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"properties": {
|
|
317
|
+
"kind": {
|
|
318
|
+
"enum": [
|
|
319
|
+
"exactlyOne",
|
|
320
|
+
"atMostOne",
|
|
321
|
+
"allOrNone"
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
},
|
|
268
329
|
"description": {
|
|
269
330
|
"description": "Human-readable description for help text.",
|
|
270
331
|
"type": "string"
|
|
@@ -280,6 +341,14 @@
|
|
|
280
341
|
"$ref": "#/$defs/example"
|
|
281
342
|
}
|
|
282
343
|
},
|
|
344
|
+
"flagDeclarationOrder": {
|
|
345
|
+
"description": "Flag declaration order when it differs from the flag record's key order.",
|
|
346
|
+
"type": "array",
|
|
347
|
+
"uniqueItems": true,
|
|
348
|
+
"items": {
|
|
349
|
+
"type": "string"
|
|
350
|
+
}
|
|
351
|
+
},
|
|
283
352
|
"flags": {
|
|
284
353
|
"description": "Named flag schemas, keyed by flag name.",
|
|
285
354
|
"type": "object",
|
|
@@ -330,6 +399,63 @@
|
|
|
330
399
|
"$ref": "#/$defs/command"
|
|
331
400
|
}
|
|
332
401
|
},
|
|
402
|
+
"constraints": {
|
|
403
|
+
"description": "Declarative relationships between the command's inputs.",
|
|
404
|
+
"type": "array",
|
|
405
|
+
"items": {
|
|
406
|
+
"type": "object",
|
|
407
|
+
"required": [
|
|
408
|
+
"inputs",
|
|
409
|
+
"kind"
|
|
410
|
+
],
|
|
411
|
+
"properties": {
|
|
412
|
+
"inputs": {
|
|
413
|
+
"type": "array",
|
|
414
|
+
"minItems": 2,
|
|
415
|
+
"uniqueItems": true,
|
|
416
|
+
"items": {
|
|
417
|
+
"$ref": "#/$defs/constraintInput"
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
"kind": {
|
|
421
|
+
"enum": [
|
|
422
|
+
"conflicts",
|
|
423
|
+
"requires",
|
|
424
|
+
"exactlyOne",
|
|
425
|
+
"atMostOne",
|
|
426
|
+
"allOrNone"
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
"additionalProperties": false,
|
|
431
|
+
"anyOf": [
|
|
432
|
+
{
|
|
433
|
+
"properties": {
|
|
434
|
+
"inputs": {
|
|
435
|
+
"maxItems": 2
|
|
436
|
+
},
|
|
437
|
+
"kind": {
|
|
438
|
+
"enum": [
|
|
439
|
+
"conflicts",
|
|
440
|
+
"requires"
|
|
441
|
+
]
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
"properties": {
|
|
447
|
+
"kind": {
|
|
448
|
+
"enum": [
|
|
449
|
+
"exactlyOne",
|
|
450
|
+
"atMostOne",
|
|
451
|
+
"allOrNone"
|
|
452
|
+
]
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
},
|
|
333
459
|
"description": {
|
|
334
460
|
"description": "Human-readable description for help text.",
|
|
335
461
|
"type": "string"
|
|
@@ -353,6 +479,14 @@
|
|
|
353
479
|
"$ref": "#/$defs/example"
|
|
354
480
|
}
|
|
355
481
|
},
|
|
482
|
+
"flagDeclarationOrder": {
|
|
483
|
+
"description": "Flag declaration order when it differs from the flag record's key order.",
|
|
484
|
+
"type": "array",
|
|
485
|
+
"uniqueItems": true,
|
|
486
|
+
"items": {
|
|
487
|
+
"type": "string"
|
|
488
|
+
}
|
|
489
|
+
},
|
|
356
490
|
"flags": {
|
|
357
491
|
"description": "Named flag definitions keyed by flag name.",
|
|
358
492
|
"type": "object",
|
|
@@ -360,6 +494,13 @@
|
|
|
360
494
|
"$ref": "#/$defs/flag"
|
|
361
495
|
}
|
|
362
496
|
},
|
|
497
|
+
"groupOrder": {
|
|
498
|
+
"description": "Named help groups to display first, in order.",
|
|
499
|
+
"type": "array",
|
|
500
|
+
"items": {
|
|
501
|
+
"type": "string"
|
|
502
|
+
}
|
|
503
|
+
},
|
|
363
504
|
"hidden": {
|
|
364
505
|
"description": "Whether the command is omitted from help listings.",
|
|
365
506
|
"const": true
|
|
@@ -375,6 +516,25 @@
|
|
|
375
516
|
},
|
|
376
517
|
"additionalProperties": false
|
|
377
518
|
},
|
|
519
|
+
"constraintInput": {
|
|
520
|
+
"type": "object",
|
|
521
|
+
"required": [
|
|
522
|
+
"kind",
|
|
523
|
+
"name"
|
|
524
|
+
],
|
|
525
|
+
"properties": {
|
|
526
|
+
"kind": {
|
|
527
|
+
"enum": [
|
|
528
|
+
"flag",
|
|
529
|
+
"arg"
|
|
530
|
+
]
|
|
531
|
+
},
|
|
532
|
+
"name": {
|
|
533
|
+
"type": "string"
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
"additionalProperties": false
|
|
537
|
+
},
|
|
378
538
|
"envBound": {
|
|
379
539
|
"anyOf": [
|
|
380
540
|
{
|
|
@@ -477,6 +637,10 @@
|
|
|
477
637
|
"presence"
|
|
478
638
|
],
|
|
479
639
|
"properties": {
|
|
640
|
+
"advanced": {
|
|
641
|
+
"description": "Whether the flag is shown only in full text help.",
|
|
642
|
+
"const": true
|
|
643
|
+
},
|
|
480
644
|
"aliases": {
|
|
481
645
|
"description": "Short/long aliases (e.g. `[{ name: 'f', hidden: false }]` for `--force`).",
|
|
482
646
|
"type": "array",
|
|
@@ -555,6 +719,10 @@
|
|
|
555
719
|
"description": "Environment variable name for v0.2+ resolution.",
|
|
556
720
|
"type": "string"
|
|
557
721
|
},
|
|
722
|
+
"group": {
|
|
723
|
+
"description": "Named section in command help.",
|
|
724
|
+
"type": "string"
|
|
725
|
+
},
|
|
558
726
|
"kind": {
|
|
559
727
|
"description": "What kind of value this flag accepts.",
|
|
560
728
|
"enum": [
|
|
@@ -1045,6 +1213,13 @@
|
|
|
1045
1213
|
"pattern": "[={}]"
|
|
1046
1214
|
}
|
|
1047
1215
|
},
|
|
1216
|
+
"groupOrder": {
|
|
1217
|
+
"description": "Named help groups to display first, in order.",
|
|
1218
|
+
"type": "array",
|
|
1219
|
+
"items": {
|
|
1220
|
+
"type": "string"
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1048
1223
|
"name": {
|
|
1049
1224
|
"description": "Program name (used in help text, usage lines, and completion scripts).",
|
|
1050
1225
|
"type": "string"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kjanat/dreamcli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Schema-first, fully typed TypeScript CLI framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dreamcli",
|
|
@@ -99,12 +99,11 @@
|
|
|
99
99
|
"docs:dev": "run --dir docs dev",
|
|
100
100
|
"docs:preview": "run --dir docs preview",
|
|
101
101
|
"docs:upload": "run --dir docs upload",
|
|
102
|
-
"fmt": "run -s lint:fix
|
|
103
|
-
"fmt:autofix": "
|
|
104
|
-
"fmt:
|
|
105
|
-
"
|
|
106
|
-
"format": "
|
|
107
|
-
"format:check": "dprint check",
|
|
102
|
+
"fmt": "run -s lint:fix format",
|
|
103
|
+
"fmt:autofix": "kprint fmt --allow-no-files --excludes .github",
|
|
104
|
+
"fmt:update": "kprint config update --yes --recursive",
|
|
105
|
+
"format": "bunx @kjanat/fmt",
|
|
106
|
+
"format:check": "kprint check",
|
|
108
107
|
"gh-project": "bun scripts/gh-project.ts",
|
|
109
108
|
"gh-project:finish": "bun gh-project finish",
|
|
110
109
|
"gh-project:list": "bun gh-project list",
|
|
@@ -140,13 +139,13 @@
|
|
|
140
139
|
"devDependencies": {
|
|
141
140
|
"@arethetypeswrong/core": "^0.18.5",
|
|
142
141
|
"@iarna/toml": "^2.2.5",
|
|
142
|
+
"@kprint/kprint": "0.63.0",
|
|
143
143
|
"@types/bun": "^1.4.3",
|
|
144
144
|
"@types/deno": "^2.7.0",
|
|
145
145
|
"@types/node": ">=26.6.5",
|
|
146
146
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
147
147
|
"@vitest/coverage-v8": "5.1.0",
|
|
148
|
-
"biome": "npm:@biomejs/biome@^2.6.
|
|
149
|
-
"dprint": "0.64.3",
|
|
148
|
+
"biome": "npm:@biomejs/biome@^2.6.8",
|
|
150
149
|
"importmapify": "1.7.0",
|
|
151
150
|
"knip": "^6.45.1",
|
|
152
151
|
"publint": "^0.3.25",
|
|
@@ -174,7 +173,7 @@
|
|
|
174
173
|
},
|
|
175
174
|
"volta": {
|
|
176
175
|
"node": "26.13.1",
|
|
177
|
-
"npm": "12.2.
|
|
176
|
+
"npm": "12.2.3"
|
|
178
177
|
},
|
|
179
178
|
"publishConfig": {
|
|
180
179
|
"access": "public"
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{F as resolvePlainHelpDescription,at as acceptsArgv,ct as flagValueSchema,ft as builtinEnabled,it as getFlagNegatedName,lt as valueEnumValues,p as resolveRootSurface,pt as CLIError,rt as getFlagAliasNames,tt as createFlagSchema,v as collectPropagatedFlags,z as flagExpectsValue}from"./core-BZx351-p.mjs";import{DREAMCLI_REVISION,DREAMCLI_VERSION}from"./version.mjs";function versionTag(){let e=` (${DREAMCLI_REVISION})`;return`@kjanat/dreamcli v${DREAMCLI_VERSION}${e}`}function programTag(e){return e.version===void 0?e.name:`${e.name} v${e.version}`}function resolveRootCompletionSurface(e,t=`subcommands`){let n=resolveRootSurface(e),r=createRootFlags(builtinEnabled(e.builtins,`help`),e.version!==void 0),i=n.visibleDefaultCommand?.flags??{},a=t===`surface`?n.hasVisibleDefault:n.hasVisibleDefault&&!n.hasVisibleSubcommands,o=n.visibleDefaultCommand,s=o!==void 0&&n.visibleCommands.some(e=>e.name===o.name);return{visibleCommands:n.defaultRouted&&o!==void 0&&!s?[o,...n.visibleCommands]:n.defaultRouted?n.visibleCommands:n.visibleSubcommands,visibleDefaultCommand:n.visibleDefaultCommand,rootFlags:r,defaultFlags:i,includeDefaultFlags:a}}function createRootFlags(e,t){return{...e?{help:createSyntheticRootFlag(`Show help text`)}:{},...t?{version:createSyntheticRootFlag(`Show version`)}:{}}}function createSyntheticRootFlag(e){return createFlagSchema(`boolean`,{description:e})}function walkCommandTree(e,t=[]){let n=[];for(let r of e){if(r.hidden)continue;let e=[...t,r],i=collectPropagatedFlags(e),a={...i,...r.flags},o=r.commands.filter(e=>!e.hidden);n.push({path:e.map(e=>e.name),schema:r,propagatedFlags:i,mergedFlags:a,children:o}),o.length>0&&n.push(...walkCommandTree(o,e))}return n}function getVisibleNegatedName(e,t){if(!(t.negation===void 0||t.negation.hidden))return getFlagNegatedName(e,t)}function sanitizeShellIdentifier(e){let t=e.replace(/[^a-zA-Z0-9_]/g,`_`);if(t===e)return t;let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return`${t}_${(n>>>0).toString(16).padStart(8,`0`)}`}function quoteShellArg(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function hasDynamicCompletion(e){let t=e=>Object.values(e.flags).some(e=>acceptsArgv(e)&&e.completion!==void 0)||e.args.some(e=>acceptsArgv(e.schema)&&e.schema.completion!==void 0)||e.commands.some(t);return e.commands.some(t)||e.defaultCommand!==void 0&&t(e.defaultCommand)}function generateBashCompletion(e,t){let n=`_${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=resolveRootCompletionSurface(e,t?.rootMode),i=r.visibleCommands,a=walkCommandTree(i),o=a.reduce((e,t)=>Math.max(e,t.path.length),0),s=[];if(s.push(`#!/usr/bin/env bash`),s.push(`# Bash completion for ${programTag(e)}`),s.push(`# Generated by ${versionTag()}`),s.push(`#`),s.push(`# Usage: source <(${e.name} completions bash)`),s.push(`#`),s.push(`# Install permanently:`),s.push(`# ${e.name} completions bash > /etc/bash_completion.d/${e.name} # Linux`),s.push(`# ${e.name} completions bash > $(brew --prefix)/etc/bash_completion.d/${e.name} # macOS`),s.push(`#`),s.push(`# Requires: bash-completion (provides _init_completion)`),s.push(``),hasDynamicCompletion(e)&&(s.push(`${n}_unquote() {`),s.push(` local text="$1" char escaped=0 i`),s.push(` unquoted="" quote=""`),s.push(" for ((i = 0; i < ${#text}; i++)); do"),s.push(' char="${text:i:1}"'),s.push(` if ((escaped)); then`),s.push(` [[ "$quote" == '"' && "$char" != [\\\\\\"\\$\\\`] ]] && unquoted+='\\'`),s.push(` unquoted+="$char"; escaped=0`),s.push(` elif [[ "$char" == '\\' && "$quote" != "'" ]]; then`),s.push(` escaped=1`),s.push(` elif [[ -n "$quote" ]]; then`),s.push(` if [[ "$char" == "$quote" ]]; then quote=""; else unquoted+="$char"; fi`),s.push(` elif [[ "$char" == "'" || "$char" == '"' ]]; then`),s.push(` quote="$char"`),s.push(` else`),s.push(` unquoted+="$char"`),s.push(` fi`),s.push(` done`),s.push(` ((escaped)) && unquoted+='\\'`),s.push(` return 0`),s.push(`}`),s.push(``)),s.push(`${n}() {`),s.push(` local cur prev words cword`),s.push(hasDynamicCompletion(e)?` _init_completion -n =: || return`:` _init_completion || return`),s.push(` local readline_prefix=""`),s.push(` if [[ $# -ge 2 && "$cur" == *"$2" ]]; then`),s.push(' readline_prefix="${cur%"$2"}"'),s.push(` fi`),hasDynamicCompletion(e)&&(s.push(` local dynamic candidate unquoted quote readline_quote word char i quoted`),s.push(`\t${n}_unquote "$readline_prefix"`),s.push(` readline_prefix="$unquoted" readline_quote="$quote"`),s.push(` local -a dynamic_words=()`),s.push(' for word in "${words[@]:1:cword-1}" "$cur"; do'),s.push(`\t\t${n}_unquote "$word"`),s.push(` dynamic_words+=("$unquoted")`),s.push(` done`),s.push(`\tif dynamic=$(command ${quoteShellArg(e.name)} __complete -- "\${dynamic_words[@]}" 2>/dev/null); then`),s.push(` compopt -o noquote 2>/dev/null`),s.push(` COMPREPLY=()`),s.push(` while IFS= read -r candidate; do`),s.push(` [[ -n "$candidate" ]] || continue`),s.push(' candidate="${candidate#"$readline_prefix"}"'),s.push(` if [[ -z "$readline_quote" ]]; then`),s.push(` printf -v candidate %q "$candidate"`),s.push(` else`),s.push(` quoted="$readline_quote"`),s.push(" for ((i = 0; i < ${#candidate}; i++)); do"),s.push(' char="${candidate:i:1}"'),s.push(` if [[ "$readline_quote" == '"' && "$char" == [\\\\\\"\\$\\\`] ]]; then quoted+='\\'; fi`),s.push(` if [[ "$readline_quote" == "'" && "$char" == "'" ]]; then quoted+="'\\\\''"; else quoted+="$char"; fi`),s.push(` done`),s.push(` candidate="$quoted"`),s.push(` fi`),s.push(` COMPREPLY+=("$candidate")`),s.push(` done <<< "$dynamic"`),s.push(` return`),s.push(` fi`)),s.push(``),i.length>0){let e=a.filter(e=>e.children.length>0),t=collectValueFlagPattern(a,r);s.push(` # Build subcommand path by scanning COMP_WORDS`),s.push(` local subcmd_path=""`),s.push(` local i`),s.push(` for ((i = 1; i < cword; i++)); do`),s.push(' case "${words[i]}" in'),s.push(` --) break ;;`),t.length>0&&s.push(`\t\t\t${t}) ((i++)); continue ;;`),s.push(` -*) continue ;;`),s.push(` esac`),emitBashPathDetection(s,i,e,o),s.push(` done`),s.push(``),s.push(` # Complete flags and subcommands for the active path`),s.push(` case "$subcmd_path" in`);for(let e of a){let t=e.path.join(` `),n=e.mergedFlags,r=collectEnumCasesFromFlags(n),i=collectFlagWords(n),a=dedupeWords(e.children.flatMap(e=>[e.name,...e.aliases])).map(escapeForSingleQuote).join(` `),o=i.split(` `).filter(Boolean).map(escapeForSingleQuote).join(` `),c=a.length>0?`${a} ${o}`:o;if(s.push(`\t\t${quoteShellCasePattern(t)})`),r.length>0){s.push(` local enum_flag=""`),s.push(` local enum_cur="$cur"`),s.push(` local enum_prefix=""`),s.push(` if [[ "$cur" == --*=* ]]; then`),s.push(' enum_flag="${cur%%=*}"'),s.push(' enum_cur="${cur#*=}"'),s.push(' enum_prefix="${cur%%=*}="'),s.push(` fi`),s.push(' case "${enum_flag:-$prev}" in');for(let e of r)s.push(`\t\t\t\t${e.flags})`),s.push(formatBashEnumCompletion(e.values,` `,`enum_cur`,`enum_prefix`)),s.push(` return`),s.push(` ;;`);s.push(` *)`),s.push(` ;;`),s.push(` esac`)}s.push(`\t\t\tCOMPREPLY=($(compgen -W '${c.trim()}' -- "$cur"))`),s.push(` return`),s.push(` ;;`)}s.push(` *)`),s.push(` ;;`),s.push(` esac`),s.push(``);let n=collectFlagWords(r.rootFlags).split(` `).filter(Boolean),c=r.includeDefaultFlags?collectFlagWords(r.defaultFlags).split(` `).filter(Boolean):[],l=dedupeWords([...i.flatMap(e=>[e.name,...e.aliases]),...n,...c]).map(escapeForSingleQuote).join(` `);s.push(` # Root-level completions: visible root surface`),s.push(`\tCOMPREPLY=($(compgen -W '${l}' -- "$cur"))`)}else{let e=collectFlagWords({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});s.push(`\tCOMPREPLY=($(compgen -W '${e}' -- "$cur"))`)}return s.push(`}`),s.push(``),s.push(`complete -F ${n} ${quoteShellArg(e.name)}`),s.push(``),s.join(`
|
|
2
|
-
`)}function emitBashPathDetection(e,t,n,r){e.push(` case "$subcmd_path" in`),e.push(` '')`),e.push(' case "${words[i]}" in');for(let n of t){let t=[n.name,...n.aliases].map(escapeBashCasePatternValue);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="${escapeBashDoubleQuotedValue(n.name)}"`),e.push(` ;;`)}if(e.push(` esac`),e.push(` ;;`),r>1)for(let t of n){let n=t.path.join(` `);e.push(`\t\t\t${quoteShellCasePattern(n)})`),e.push(' case "${words[i]}" in');for(let n of t.children){let t=[n.name,...n.aliases].map(escapeBashCasePatternValue);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="$subcmd_path ${escapeBashDoubleQuotedValue(n.name)}"`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`)}e.push(` esac`)}function quoteShellCasePattern(e){return e.includes(` `)?`"${escapeBashDoubleQuotedValue(e)}"`:escapeBashCasePatternValue(e)}function escapeBashCasePatternValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/"/g,`\\"`).replace(/\|/g,`\\|`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`).replace(/\{/g,`\\{`).replace(/\}/g,`\\}`).replace(/\+/g,`\\+`).replace(/!/g,`\\!`).replace(/@/g,`\\@`).replace(/#/g,`\\#`).replace(/~/g,`\\~`).replace(/\s/g,e=>e===` `?`\\ `:`\\${e}`)}function escapeBashDoubleQuotedValue(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function escapeForSingleQuote(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/'/g,`'\\''`)}function formatBashEnumCompletion(e,t,n=`cur`,r){let i=[];if(e.some(e=>!/^[a-zA-Z0-9_\-.]+$/.test(e))){let r=e.map(escapeBashDollarQuote).join(`\\n`);i.push(`${t}local IFS=$'\\n'`),i.push(`${t}COMPREPLY=($(compgen -W $'${r}' -- "$${n}"))`)}else i.push(`${t}COMPREPLY=($(compgen -W '${e.join(` `)}' -- "$${n}"))`);return r!==void 0&&(i.push(`${t}if [[ -n "$${r}" && "\${#COMPREPLY[@]}" -gt 0 ]]; then`),i.push(`${t}\tlocal i`),i.push(`${t}\tfor ((i = 0; i < \${#COMPREPLY[@]}; i++)); do`),i.push(`${t}\t\tCOMPREPLY[i]="$${r}\${COMPREPLY[i]}"`),i.push(`${t}\tdone`),i.push(`${t}fi`)),i.push(`${t}local reply`),i.push(`${t}for reply in "\${!COMPREPLY[@]}"; do`),i.push(`${t}\tCOMPREPLY[reply]="\${COMPREPLY[reply]#"$readline_prefix"}"`),i.push(`${t}done`),i.join(`
|
|
3
|
-
`)}function escapeBashDollarQuote(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\n/g,`\\n`)}function collectFlagWords(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;t.push(`--${n}`);for(let e of getFlagAliasNames(r))t.push(e.length===1?`-${e}`:`--${e}`);let e=getVisibleNegatedName(n,r);e!==void 0&&t.push(`--${e}`)}return t.join(` `)}function collectValueFlagPattern(e,t){let n=/* @__PURE__ */ new Set,r=e=>{for(let[t,r]of Object.entries(e))if(acceptsArgv(r)&&flagExpectsValue(r)){n.add(`--${t}`);for(let e of getFlagAliasNames(r,{includeHidden:!0}))n.add(e.length===1?`-${e}`:`--${e}`)}};for(let t of e)r(t.mergedFlags);return r(t.rootFlags),t.includeDefaultFlags&&r(t.defaultFlags),[...n].map(escapeBashCasePatternValue).join(`|`)}function dedupeWords(e){return[...new Set(e)]}function collectEnumCasesFromFlags(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;let e=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r));if(e===void 0)continue;let i=[`--${n}`,...getFlagAliasNames(r,{includeHidden:!0}).map(e=>e.length===1?`-${e}`:`--${e}`)].map(escapeBashCasePatternValue);t.push({flags:i.join(`|`),values:e})}return t}function generateFishCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_path`,i=`${n}_path_is`,a=resolveRootCompletionSurface(e,t?.rootMode),o=a.visibleCommands,s=walkCommandTree(o),c=quoteShellArg(e.name),l=[];l.push(`# Fish completion for ${programTag(e)}`),l.push(`# Generated by ${versionTag()}`),l.push(`#`),l.push(`# Usage: source (${e.name} completions fish | psub)`),l.push(`#`),l.push(`# Install permanently:`),l.push(`# ${e.name} completions fish > ~/.config/fish/completions/${e.name}.fish`),l.push(``),l.push(`complete -c ${c} -f`),l.push(``),hasDynamicCompletion(e)&&(l.push(`function ${n}_dynamic`),l.push(` set -l words (commandline -xpc)`),l.push(` set -l raw (commandline -ct)`),l.push(` set -l prefix (commandline --input "$raw" --tokens-expanded)`),l.push(`\tcommand ${c} __complete --value-only -- $words[2..-1] "$prefix" 2>/dev/null`),l.push(`end`),l.push(`complete -c ${c} -f -a '(${n}_dynamic)'`),l.push(``)),emitFishPathHelpers(l,r,i,o,s,a),appendFishCommandCompletions(l,c,i,``,o),appendFishFlagCompletions(l,c,i,``,a.rootFlags,`${n}_dynamic`),a.includeDefaultFlags&&appendFishFlagCompletions(l,c,i,``,a.defaultFlags,`${n}_dynamic`);for(let e of s){let t=e.path.join(` `);appendFishCommandCompletions(l,c,i,t,e.children),appendFishFlagCompletions(l,c,i,t,e.mergedFlags,`${n}_dynamic`)}return l.join(`
|
|
4
|
-
`)}function emitFishPathHelpers(e,t,n,r,i,a){let o=collectFishValueFlagPatterns(i,a);e.push(`function ${t}`),e.push(` set -l words (commandline -xpc)`),e.push(` if test (count $words) -gt 0`),e.push(` set -e words[1]`),e.push(` end`),e.push(` set -l subcmd_path ''`),e.push(` set -l expect_value 0`),e.push(` for word in $words`),e.push(` if test $expect_value -eq 1`),e.push(` set expect_value 0`),e.push(` continue`),e.push(` end`),e.push(` switch $word`),e.push(` case '--'`),e.push(` break`),o.exact.length>0&&(e.push(`\t\t\tcase ${o.exact.map(quoteShellArg).join(` `)}`),e.push(` set expect_value 1`),e.push(` continue`)),o.prefix.length>0&&(e.push(`\t\t\tcase ${o.prefix.map(quoteShellArg).join(` `)}`),e.push(` continue`)),e.push(` case '-*'`),e.push(` continue`),e.push(` end`),e.push(` switch "$subcmd_path|$word"`);for(let t of r)for(let n of[t.name,...t.aliases])e.push(`\t\t\tcase ${quoteShellArg(`|${n}`)}`),e.push(`\t\t\t\tset subcmd_path ${quoteShellArg(t.name)}`);for(let t of i)for(let n of t.children)for(let r of[n.name,...n.aliases])e.push(`\t\t\tcase ${quoteShellArg(`${t.path.join(` `)}|${r}`)}`),e.push(`\t\t\t\tset subcmd_path ${quoteShellArg(`${t.path.join(` `)} ${n.name}`)}`);e.push(` case '*'`),e.push(` break`),e.push(` end`),e.push(` end`),e.push(` printf '%s\\n' "$subcmd_path"`),e.push(`end`),e.push(``),e.push(`function ${n}`),e.push(` set -l expected "$argv[1]"`),e.push(`\ttest (${t}) = "$expected"`),e.push(`end`),e.push(``)}function appendFishCommandCompletions(e,t,n,r,i){let a=buildFishCondition(n,r);for(let n of i){let r=quoteShellArg(n.description??n.name);for(let i of[n.name,...n.aliases])e.push(`complete -c ${t} -n "${a}" -a ${quoteShellArg(i)} -d ${r}`)}i.length>0&&e.push(``)}function appendFishFlagCompletions(e,t,n,r,i,a){let o=buildFishCondition(n,r);for(let[n,r]of Object.entries(i)){if(!acceptsArgv(r))continue;let i=[`complete -c ${t}`,`-n "${o}"`];for(let e of getFlagAliasNames(r,{kind:`short`}))i.push(`-s ${quoteShellArg(e)}`);i.push(`-l ${quoteShellArg(n)}`);for(let e of getFlagAliasNames(r,{kind:`long`}))i.push(`-l ${quoteShellArg(e)}`);let s=getVisibleNegatedName(n,r);s!==void 0&&i.push(`-l ${quoteShellArg(s)}`),i.push(`-d ${quoteShellArg(r.description===void 0?n:resolvePlainHelpDescription(r.description))}`),flagExpectsValue(r)&&i.push(`-r`,`-f`),r.completion!==void 0&&i.push(`-a '(${a})'`);let c=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r));if(c!==void 0&&r.completion===void 0)for(let t of c)e.push([...i,`-a ${quoteShellArg(t)}`].join(` `));else e.push(i.join(` `))}Object.keys(i).length>0&&e.push(``)}function collectFishValueFlagPatterns(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=[t.rootFlags,...t.includeDefaultFlags?[t.defaultFlags]:[],...e.map(e=>e.mergedFlags)];for(let e of i)for(let[t,i]of Object.entries(e))if(acceptsArgv(i)&&flagExpectsValue(i)){n.add(`--${t}`),r.add(`--${t}=*`);for(let e of getFlagAliasNames(i,{kind:`short`,includeHidden:!0}))n.add(`-${e}`),r.add(`-${e}*`);for(let e of getFlagAliasNames(i,{kind:`long`,includeHidden:!0}))n.add(`--${e}`),r.add(`--${e}=*`)}return{exact:[...n],prefix:[...r]}}function buildFishCondition(e,t){return`${e} ${quoteShellArg(t)}`}function generatePowerShellCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_paths`,i=resolveRootCompletionSurface(e,t?.rootMode),a=i.visibleCommands,o=walkCommandTree(a),s=[];return s.push(`# PowerShell completion for ${programTag(e)}`),s.push(`# Generated by ${versionTag()}`),s.push(`#`),s.push(`# Install for the current session:`),s.push(`# ${e.name} completions powershell | Out-String | Invoke-Expression`),s.push(`#`),s.push(`# Install permanently:`),s.push(`# ${e.name} completions powershell > $PROFILE.CurrentUserCurrentHost`),s.push(``),s.push(`using namespace System.Management.Automation`),s.push(`using namespace System.Management.Automation.Language`),s.push(``),emitPowerShellPathTable(s,r,i,o),s.push(``),emitPowerShellHelpers(s,n,r),s.push(``),s.push(`Register-ArgumentCompleter -Native -CommandName ${quotePowerShellString(e.name)} -ScriptBlock {`),s.push(` param($wordToComplete, $commandAst, $cursorPosition)`),hasDynamicCompletion(e)&&(s.push(` $dynamicArgs = [System.Collections.Generic.List[string]]::new()`),s.push(` $dynamicArgs.Add('__complete')`),s.push(` $dynamicArgs.Add('--')`),s.push(` $currentText = $wordToComplete`),s.push(` foreach ($element in $commandAst.CommandElements | Select-Object -Skip 1) {`),s.push(` if ($element.Extent.StartOffset -gt $cursorPosition) { break }`),s.push(` if ($element.Extent.EndOffset -ge $cursorPosition) {`),s.push(` $currentText = $element.Extent.Text.Substring(0, $cursorPosition - $element.Extent.StartOffset)`),s.push(` break`),s.push(` }`),s.push(`\t\t$dynamicArgs.Add((${n}_UnquoteToken $element.Extent.Text))`),s.push(` }`),s.push(`\t$dynamicArgs.Add((${n}_UnquoteToken $currentText))`),s.push(`\t$dynamic = & ${quotePowerShellString(e.name)} @dynamicArgs 2>$null`),s.push(` if ($LASTEXITCODE -eq 0) {`),s.push(` foreach ($candidate in $dynamic) {`),s.push(`\t\t\t$text = ${n}_FormatCompletionValue -Value $candidate`),s.push(` [CompletionResult]::new($text, $candidate, [CompletionResultType]::ParameterValue, $candidate)`),s.push(` }`),s.push(` return`),s.push(` }`)),s.push(`\t$state = ${n}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`),s.push(` if ($null -eq $state.PathData) {`),s.push(` return`),s.push(` }`),s.push(``),s.push(` $results = [System.Collections.Generic.List[CompletionResult]]::new()`),s.push(` if ($state.AfterSeparator) {`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(` $wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`),s.push(``),s.push(` if ($state.ExpectingValue) {`),s.push(`\t\t${n}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(`\t$inlineValue = ${n}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` if ($null -ne $inlineValue) {`),s.push(`\t\t${n}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(` if ($wordPrefix.StartsWith('-')) {`),s.push(`\t\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(`\t${n}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(`\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(`}`),s.join(`
|
|
5
|
-
`)}function emitPowerShellPathTable(e,t,n,r){e.push(`$script:${t} = @{`),appendPowerShellPathEntry(e,``,n.visibleCommands,{...n.rootFlags,...n.includeDefaultFlags?n.defaultFlags:{}});for(let t of r)appendPowerShellPathEntry(e,t.path.join(` `),t.children,t.mergedFlags);e.push(`}`)}function appendPowerShellPathEntry(e,t,n,r){e.push(`\t${quotePowerShellString(t)} = @{`),e.push(` Commands = @(`);for(let t of n)e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t.name)}`),e.push(`\t\t\t\tNames = ${formatPowerShellArray([t.name,...t.aliases])}`),e.push(`\t\t\t\tDescription = ${quotePowerShellString(t.description??t.name)}`),e.push(` }`);e.push(` )`),e.push(` Flags = @(`);for(let[t,n]of Object.entries(r)){if(!acceptsArgv(n))continue;let r=getVisibleNegatedName(t,n),i=getFlagNegatedName(t,n),a=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`}).map(e=>`--${e}`),...r===void 0?[]:[`--${r}`]]),o=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`,includeHidden:!0}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`,includeHidden:!0}).map(e=>`--${e}`),...i===void 0?[]:[`--${i}`]]);e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t)}`),e.push(`\t\t\t\tForms = ${formatPowerShellArray(a)}`),e.push(`\t\t\t\tParseForms = ${formatPowerShellArray(o)}`),e.push(`\t\t\t\tRequiresValue = ${flagExpectsValue(n)?`$true`:`$false`}`),e.push(`\t\t\t\tDescription = ${quotePowerShellString(n.description===void 0?t:resolvePlainHelpDescription(n.description))}`),e.push(`\t\t\t\tEnumValues = ${formatPowerShellArray((n.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(n)))??[])}`),e.push(` }`)}e.push(` )`),e.push(` }`)}function emitPowerShellHelpers(e,t,n){e.push(`function ${t}_UnquoteToken {`),e.push(` param([string]$TokenText)`),e.push(...String.raw`
|
|
6
|
-
$result = [System.Text.StringBuilder]::new()
|
|
7
|
-
$quote = [char]0
|
|
8
|
-
for ($i = 0; $i -lt $TokenText.Length; $i++) {
|
|
9
|
-
$char = $TokenText[$i]
|
|
10
|
-
if ($quote -eq "'") {
|
|
11
|
-
if ($char -eq "'") {
|
|
12
|
-
if ($i + 1 -lt $TokenText.Length -and $TokenText[$i + 1] -eq "'") {
|
|
13
|
-
[void]$result.Append("'")
|
|
14
|
-
$i++
|
|
15
|
-
} else { $quote = [char]0 }
|
|
16
|
-
} else { [void]$result.Append($char) }
|
|
17
|
-
} elseif ($char -eq [char]96) {
|
|
18
|
-
if ($i + 1 -lt $TokenText.Length) {
|
|
19
|
-
$i++
|
|
20
|
-
$escaped = $TokenText[$i]
|
|
21
|
-
$decoded = switch -CaseSensitive ($escaped) {
|
|
22
|
-
'0' { [char]0 }
|
|
23
|
-
'a' { [char]7 }
|
|
24
|
-
'b' { [char]8 }
|
|
25
|
-
'e' { [char]27 }
|
|
26
|
-
'f' { [char]12 }
|
|
27
|
-
'n' { [char]10 }
|
|
28
|
-
'r' { [char]13 }
|
|
29
|
-
't' { [char]9 }
|
|
30
|
-
'v' { [char]11 }
|
|
31
|
-
'u' {
|
|
32
|
-
$match = [regex]::Match($TokenText.Substring($i + 1), '^\{([0-9a-fA-F]{1,6})\}')
|
|
33
|
-
if ($match.Success) {
|
|
34
|
-
$codepoint = [Convert]::ToInt32($match.Groups[1].Value, 16)
|
|
35
|
-
if ($codepoint -le 0x10ffff -and ($codepoint -lt 0xd800 -or $codepoint -gt 0xdfff)) {
|
|
36
|
-
$i += $match.Length
|
|
37
|
-
[char]::ConvertFromUtf32($codepoint)
|
|
38
|
-
} else { $escaped }
|
|
39
|
-
} else { $escaped }
|
|
40
|
-
}
|
|
41
|
-
default { $escaped }
|
|
42
|
-
}
|
|
43
|
-
[void]$result.Append($decoded)
|
|
44
|
-
} else { [void]$result.Append($char) }
|
|
45
|
-
} elseif ($quote -eq '"') {
|
|
46
|
-
if ($char -eq '"') {
|
|
47
|
-
if ($i + 1 -lt $TokenText.Length -and $TokenText[$i + 1] -eq '"') {
|
|
48
|
-
[void]$result.Append('"')
|
|
49
|
-
$i++
|
|
50
|
-
} else { $quote = [char]0 }
|
|
51
|
-
} else { [void]$result.Append($char) }
|
|
52
|
-
} elseif ($char -eq "'" -or $char -eq '"') {
|
|
53
|
-
$quote = $char
|
|
54
|
-
} else { [void]$result.Append($char) }
|
|
55
|
-
}
|
|
56
|
-
return $result.ToString()
|
|
57
|
-
`.trimEnd().split(`
|
|
58
|
-
`).slice(1)),e.push(`}`),e.push(``),e.push(`function ${t}_FindCommand {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if ($name -eq $Token) {`),e.push(` return $command`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveFlagToken {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.ParseForms) {`),e.push(` if ($Token -eq $form) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $null }`),e.push(` }`),e.push(``),e.push(` if (-not $flag.RequiresValue) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('--') -and $Token.StartsWith("$form=")) {`),e.push(` return @{ Flag = $flag; InlinePrefix = "$form=" }`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('-') -and -not $form.StartsWith('--') -and $Token.StartsWith($form) -and $Token.Length -gt $form.Length) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $form }`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_GetState {`),e.push(` param([CommandAst]$CommandAst, [int]$CursorPosition)`),e.push(`\t$pathData = $script:${n}[${quotePowerShellString(``)}]`),e.push(` $path = ""`),e.push(` $afterSeparator = $false`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` $tokens = [System.Collections.Generic.List[string]]::new()`),e.push(``),e.push(` foreach ($element in $CommandAst.CommandElements | Select-Object -Skip 1) {`),e.push(` if ($element.Extent.EndOffset -ge $CursorPosition) {`),e.push(` break`),e.push(` }`),e.push(`\t\t$tokenText = ${t}_UnquoteToken $element.Extent.Text`),e.push(` [void]$tokens.Add($tokenText)`),e.push(` }`),e.push(``),e.push(` foreach ($token in $tokens) {`),e.push(` if ($expectingValue) {`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token -eq '--') {`),e.push(` $afterSeparator = $true`),e.push(` break`),e.push(` }`),e.push(``),e.push(`\t\t$flagMatch = ${t}_ResolveFlagToken -PathData $pathData -Token $token`),e.push(` if ($null -ne $flagMatch) {`),e.push(` if ($flagMatch.InlinePrefix -eq $null -and $flagMatch.Flag.RequiresValue) {`),e.push(` $expectingValue = $true`),e.push(` $valueFlag = $flagMatch.Flag`),e.push(` }`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token.StartsWith('-')) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(`\t\t$command = ${t}_FindCommand -PathData $pathData -Token $token`),e.push(` if ($null -eq $command) {`),e.push(` break`),e.push(` }`),e.push(``),e.push(` $path = if ([string]::IsNullOrEmpty($path)) {`),e.push(` $command.CanonicalName`),e.push(` } else {`),e.push(` "$path $($command.CanonicalName)"`),e.push(` }`),e.push(`\t\t$nextPathData = $script:${n}[$path]`),e.push(` if ($null -eq $nextPathData) {`),e.push(` break`),e.push(` }`),e.push(` $pathData = $nextPathData`),e.push(` }`),e.push(``),e.push(` return @{`),e.push(` Path = $path`),e.push(` PathData = $pathData`),e.push(` AfterSeparator = $afterSeparator`),e.push(` ExpectingValue = $expectingValue`),e.push(` ValueFlag = $valueFlag`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveInlineValueCompletion {`),e.push(` param($PathData, [string]$WordToComplete)`),e.push(`\t$flagMatch = ${t}_ResolveFlagToken -PathData $PathData -Token $WordToComplete`),e.push(` if ($null -eq $flagMatch -or $flagMatch.InlinePrefix -eq $null) {`),e.push(` return $null`),e.push(` }`),e.push(` return $flagMatch`),e.push(`}`),e.push(``),e.push(`function ${t}_FormatCompletionValue {`),e.push(` param([string]$Value)`),e.push(` if ($Value.Length -eq 0) {`),e.push(` return "''"`),e.push(` }`),e.push(``),e.push(` if ($Value -match '^[a-zA-Z0-9_./:\\\\-]+$') {`),e.push(` return $Value`),e.push(` }`),e.push(``),e.push(` return "'$([CodeGeneration]::EscapeSingleQuotedStringContent($Value))'"`),e.push(`}`),e.push(``),e.push(`function ${t}_MatchesCompletionPrefix {`),e.push(` param([string]$WordToComplete, [string]$RawText, [string]$CompletionText)`),e.push(` if ([string]::IsNullOrEmpty($WordToComplete)) {`),e.push(` return $true`),e.push(` }`),e.push(``),e.push(` return $RawText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase) -or $CompletionText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)`),e.push(`}`),e.push(``),e.push(`function ${t}_AddCommandResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $name.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $name,`),e.push(` $name,`),e.push(` [CompletionResultType]::Command,`),e.push(` $command.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddFlagResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.Forms) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $form.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $form,`),e.push(` $form,`),e.push(` [CompletionResultType]::ParameterName,`),e.push(` $flag.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddEnumResults {`),e.push(` param($Results, $Flag, [string]$WordToComplete)`),e.push(` foreach ($value in $Flag.EnumValues) {`),e.push(`\t\t$completionText = ${t}_FormatCompletionValue -Value $value`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $value -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddInlineEnumResults {`),e.push(` param($Results, $InlineValue, [string]$WordToComplete)`),e.push(` foreach ($value in $InlineValue.Flag.EnumValues) {`),e.push(` $rawCompletion = "$($InlineValue.InlinePrefix)$value"`),e.push(`\t\t$formattedValue = ${t}_FormatCompletionValue -Value $value`),e.push(` $completionText = "$($InlineValue.InlinePrefix)$formattedValue"`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $rawCompletion -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $InlineValue.Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`)}function quotePowerShellString(e){return`'${e.replace(/'/g,`''`)}'`}function formatPowerShellArray(e){return e.length===0?`@()`:`@(${e.map(quotePowerShellString).join(`, `)})`}function dedupeValues(e){return[...new Set(e)]}function generateZshCompletion(e,t){let n=`_${sanitizeShellIdentifier(t?.functionPrefix??e.name)}`,r=resolveRootCompletionSurface(e,t?.rootMode),i=r.visibleCommands,a=walkCommandTree(i),o=[];o.push(`#compdef ${quoteShellArg(e.name)}`),o.push(`# Zsh completion for ${programTag(e)}`),o.push(`# Generated by ${versionTag()}`),o.push(`#`),o.push(`# Usage: source <(${e.name} completions zsh)`),o.push(`#`),o.push(`# Install permanently:`),o.push(`# ${e.name} completions zsh > "\${fpath[1]}/_${e.name}"`),o.push(`# # Then restart your shell`),o.push(``);let s=a.filter(e=>e.children.length>0),c=a.filter(e=>e.children.length===0);for(let e of c)e.path.length<2||emitZshLeafFunction(o,`${n}_${e.path.map(sanitizeShellIdentifier).join(`_`)}`,e);let l=[...s].sort((e,t)=>t.path.length-e.path.length);for(let e of l)emitZshGroupFunction(o,`${n}_${e.path.map(sanitizeShellIdentifier).join(`_`)}`,n,e);if(o.push(`${n}() {`),hasDynamicCompletion(e)&&(o.push(` local dynamic word current_prefix=$PREFIX`),o.push(` local -a dynamic_words=()`),o.push(' for word in "${words[@]:1:$((CURRENT-2))}"; do'),o.push(' dynamic_words+=("${(Q)word}")'),o.push(` done`),o.push(` if [[ $compstate[quoting] = (single|double) ]]; then`),o.push(` current_prefix="$compstate[quote]$PREFIX$compstate[quote]"`),o.push(` fi`),o.push(' dynamic_words+=("${(Q)current_prefix}")'),o.push(`\tif dynamic=$(command ${quoteShellArg(e.name)} __complete -- "\${dynamic_words[@]}" 2>/dev/null); then`),o.push(` local -a candidates`),o.push(` if [[ -n "$dynamic" ]]; then`),o.push(' candidates=("${(@f)dynamic}")'),o.push(` compadd -a candidates`),o.push(` fi`),o.push(` return`),o.push(` fi`)),i.length>0){o.push(` local -a subcmds`),o.push(` local line state`),o.push(``);let e=buildZshFlagSpecsFromFlags({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});o.push(` _arguments -C \\`);for(let t of e)o.push(`\t\t${t} \\`);o.push(` '1: :->subcmd' \\`),o.push(` '*::arg:->args'`),o.push(``),o.push(` case "$state" in`),o.push(` subcmd)`),o.push(` subcmds=(`),appendZshCommandCandidates(o,i,` `),o.push(` )`),o.push(` _describe 'command' subcmds`),o.push(` ;;`),o.push(` args)`),o.push(` case "$line[1]" in`);for(let e of i){let t=[e.name,...e.aliases].map(escapeZshCasePatternValue),r=e.commands.filter(e=>!e.hidden);if(o.push(`\t\t\t\t${t.join(`|`)})`),r.length>0){let t=`${n}_${sanitizeShellIdentifier(e.name)}`;o.push(`\t\t\t\t\t${t}`)}else{let t=a.find(t=>t.path.length===1&&t.schema.name===e.name);if(t===void 0)throw new CLIError(`Missing completion node for command '${e.name}'`,{code:`UNEXPECTED_ERROR`});let n=buildZshFlagSpecsFromFlags(t.mergedFlags);if(n.length>0){o.push(` _arguments \\`);for(let e=0;e<n.length;e++){let t=e<n.length-1?` \\`:``;o.push(`\t\t\t\t\t\t${n[e]}${t}`)}}}o.push(` ;;`)}o.push(` esac`),o.push(` ;;`),o.push(` esac`)}else{let e=buildZshFlagSpecsFromFlags({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});o.push(` _arguments \\`);for(let t=0;t<e.length;t++){let n=t<e.length-1?` \\`:``;o.push(`\t\t${e[t]}${n}`)}}return o.push(`}`),o.push(``),o.push(`compdef ${n} ${quoteShellArg(e.name)}`),o.push(``),o.join(`
|
|
59
|
-
`)}function emitZshGroupFunction(e,t,n,r){e.push(`${t}() {`),e.push(` local -a subcmds`),e.push(` local line state`),e.push(``);let i=buildZshFlagSpecsFromFlags(r.mergedFlags);e.push(` _arguments -C \\`);for(let t of i)e.push(`\t\t${t} \\`);e.push(` '1: :->subcmd' \\`),e.push(` '*::arg:->args'`),e.push(``),e.push(` case "$state" in`),e.push(` subcmd)`),e.push(` subcmds=(`),appendZshCommandCandidates(e,r.children,` `),e.push(` )`),e.push(` _describe 'command' subcmds`),e.push(` ;;`),e.push(` args)`),e.push(` case "$line[1]" in`);for(let t of r.children){let i=[t.name,...t.aliases].map(escapeZshCasePatternValue),a=`${n}_${[...r.path,t.name].map(sanitizeShellIdentifier).join(`_`)}`;e.push(`\t\t\t\t${i.join(`|`)})`),e.push(`\t\t\t\t\t${a}`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`),e.push(` esac`),e.push(`}`),e.push(``)}function emitZshLeafFunction(e,t,n){let r=buildZshFlagSpecsFromFlags(n.mergedFlags);if(e.push(`${t}() {`),r.length>0){e.push(` _arguments \\`);for(let t=0;t<r.length;t++){let n=t<r.length-1?` \\`:``;e.push(`\t\t${r[t]}${n}`)}}e.push(`}`),e.push(``)}function appendZshCommandCandidates(e,t,n){for(let r of t){let t=r.description??r.name;for(let i of[r.name,...r.aliases])e.push(`${n}${quoteShellArg(`${i}:${t}`)}`)}}function escapeZshCasePatternValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/"/g,`\\"`).replace(/`/g,"\\`").replace(/\|/g,`\\|`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`).replace(/\{/g,`\\{`).replace(/\}/g,`\\}`).replace(/\+/g,`\\+`).replace(/!/g,`\\!`).replace(/@/g,`\\@`).replace(/#/g,`\\#`).replace(/~/g,`\\~`).replace(/\s/g,e=>e===` `?`\\ `:`\\${e}`)}function escapeZshDescription(e){return e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`)}function buildZshFlagSpecsFromFlags(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;let e=escapeZshDescription(r.description===void 0?n:resolvePlainHelpDescription(r.description)),i=`--${n}`,a=getFlagAliasNames(r,{kind:`short`}).map(e=>`-${e}`),o=getFlagAliasNames(r,{kind:`long`}).map(e=>`--${e}`),s=getVisibleNegatedName(n,r),c=s===void 0?[]:[`--${s}`],l=[...a,i,...o,...c],u=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r)),d=``;if(flagExpectsValue(r)&&(d=u===void 0?`:value:`:`:value:(${u.map(escapeZshEnumValue).join(` `)})`),l.length>1){let n=l.map(escapeZshCasePatternValue).join(`,`);t.push(`${quoteShellArg(`(${l.join(` `)})`)}{${n}}${quoteShellArg(`[${e}]${d}`)}`)}else t.push(quoteShellArg(`${i}[${e}]${d}`))}return t}function escapeZshEnumValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/ /g,`\\ `).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`)}var completion_exports=/* @__PURE__ */ __exportAll({generateCompletion:()=>generateCompletion});function generateCompletion(e,t,n){switch(t){case`bash`:return generateBashCompletion(e,n);case`zsh`:return generateZshCompletion(e,n);case`fish`:return generateFishCompletion(e,n);case`powershell`:return generatePowerShellCompletion(e,n)}}export{generateFishCompletion as a,generatePowerShellCompletion as i,generateCompletion as n,generateBashCompletion as o,generateZshCompletion as r,completion_exports as t};
|