@kjanat/dreamcli 4.2.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/completion-B4oRc2Ae.mjs +59 -0
- package/dist/completion.d.mts +11 -11
- package/dist/completion.mjs +1 -1
- package/dist/config-DSh3QJpX.mjs +1 -0
- package/dist/config.d.mts +11 -1
- package/dist/config.mjs +1 -1
- package/dist/core-BZx351-p.mjs +21 -0
- package/dist/dynamic-BK2lQF2M.mjs +1 -0
- package/dist/{index-C5CYWtxn.d.mts → index-CLtWJqwn.d.mts} +50 -10
- package/dist/{index-B6oD4_8b.d.mts → index-CuhI1Ynv.d.mts} +638 -47
- package/dist/{index-B3_9MlHz.d.mts → index-D683D09G.d.mts} +0 -2
- package/dist/{index-B_1Dmsdq.d.mts → index-DDhRLoTu.d.mts} +157 -21
- package/dist/{index-Cj7kXwQH.d.mts → index-DIWRV_wp.d.mts} +1 -7
- package/dist/{index-eF7SkQzQ.d.mts → index-Vjl2_m23.d.mts} +66 -15
- package/dist/{index-CaRNJH2R.d.mts → index-aTmg9yfl.d.mts} +14 -12
- package/dist/index.d.mts +41 -12
- package/dist/index.mjs +1 -1
- package/dist/json-schema-CYgq_hFu.mjs +59 -0
- package/dist/json-schema.d.mts +10 -2
- package/dist/json-schema.mjs +1 -1
- package/dist/{package-json-fYhxDdWD.mjs → package-json-hqUWeazy.mjs} +1 -1
- package/dist/prompt.d.mts +13 -8
- package/dist/prompt.mjs +1 -1
- package/dist/rolldown-runtime-DOYBPklu.mjs +1 -0
- package/dist/runtime.d.mts +20 -2
- package/dist/runtime.mjs +1 -1
- package/dist/session-BEKj0yLA.mjs +1 -0
- package/dist/{terminal-cbye9mKF.mjs → terminal-Dws_b5UK.mjs} +1 -1
- package/dist/test-prompter-euLYzWWO.mjs +1 -0
- package/dist/testkit.d.mts +18 -7
- package/dist/testkit.mjs +1 -1
- package/dist/version.d.mts +1 -3
- package/dist/version.mjs +1 -1
- package/dreamcli.schema.json +151 -2
- package/package.json +11 -11
- package/skills/cli-creation/SKILL.md +1 -1
- package/dist/adapter-DsmEc0WO.d.mts +0 -285
- package/dist/completion-BYhuYn2Q.mjs +0 -6
- package/dist/config-BgJZ-X4r.mjs +0 -1
- package/dist/core-B4Twhd48.mjs +0 -18
- package/dist/json-schema-DVyfq4bA.mjs +0 -52
- package/dist/rolldown-runtime-G4Kt5YOX.mjs +0 -1
- package/dist/session-CQsnVijE.mjs +0 -1
- package/dist/test-prompter-Ddkt9n5A.mjs +0 -1
package/dreamcli.schema.json
CHANGED
|
@@ -62,6 +62,14 @@
|
|
|
62
62
|
"type": "string"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
+
"envAbsolute": {
|
|
66
|
+
"description": "Whether the env source is read exactly as written, outside the CLI-wide\nnamespace set by `CLIBuilder.envPrefix()` (set by `.env(…, { absolute:\ntrue })`). Applies to ArgSchema.envVar and\nArgSchema.envIndexed alike.\n\nDefault: `false`",
|
|
67
|
+
"const": true
|
|
68
|
+
},
|
|
69
|
+
"envIndexed": {
|
|
70
|
+
"$ref": "#/$defs/envIndexed",
|
|
71
|
+
"description": "Indexed environment family read as the env source, set by `.env()` with an\nIndexedEnvBinding (`undefined` otherwise). An arg declares at most\none env source, so this and ArgSchema.envVar are never both set."
|
|
72
|
+
},
|
|
65
73
|
"envVar": {
|
|
66
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.",
|
|
67
75
|
"type": "string"
|
|
@@ -129,6 +137,11 @@
|
|
|
129
137
|
}
|
|
130
138
|
},
|
|
131
139
|
"additionalProperties": false,
|
|
140
|
+
"dependentSchemas": {
|
|
141
|
+
"envAbsolute": {
|
|
142
|
+
"$ref": "#/$defs/envBound"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
132
145
|
"anyOf": [
|
|
133
146
|
{
|
|
134
147
|
"not": {
|
|
@@ -147,7 +160,13 @@
|
|
|
147
160
|
}
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
|
-
]
|
|
163
|
+
],
|
|
164
|
+
"not": {
|
|
165
|
+
"required": [
|
|
166
|
+
"envIndexed",
|
|
167
|
+
"envVar"
|
|
168
|
+
]
|
|
169
|
+
}
|
|
151
170
|
},
|
|
152
171
|
"argElement": {
|
|
153
172
|
"description": "Element schema when `kind === 'keyValue'`.\n\nDescribes the value of each entry, so `arg.keyValue(arg.number())` decodes\n`A=1` to the number `1`. `undefined` leaves entry values as strings.",
|
|
@@ -250,6 +269,10 @@
|
|
|
250
269
|
"description": "Human-readable description for help text.",
|
|
251
270
|
"type": "string"
|
|
252
271
|
},
|
|
272
|
+
"details": {
|
|
273
|
+
"description": "Longer explanation shown only in this command's help, with paragraphs wrapped to its width.",
|
|
274
|
+
"type": "string"
|
|
275
|
+
},
|
|
253
276
|
"examples": {
|
|
254
277
|
"description": "Usage examples for help text.",
|
|
255
278
|
"type": "array",
|
|
@@ -311,6 +334,18 @@
|
|
|
311
334
|
"description": "Human-readable description for help text.",
|
|
312
335
|
"type": "string"
|
|
313
336
|
},
|
|
337
|
+
"details": {
|
|
338
|
+
"description": "Longer explanation shown only in this command's help.",
|
|
339
|
+
"type": "string"
|
|
340
|
+
},
|
|
341
|
+
"envPrefix": {
|
|
342
|
+
"description": "CLI-wide environment namespace prepended to every relative env binding\n(`undefined` when none is set). `.env('TOKEN')` reads `<envPrefix>TOKEN`;\na binding declared with `{ absolute: true }` is read as written.\n\nSet via the .envPrefix() builder method\nor the `envPrefix` field of CLIDefinition. Fixed when declared, so\nneither manifest name inference nor an inherited invocation name changes it.",
|
|
343
|
+
"type": "string",
|
|
344
|
+
"minLength": 1,
|
|
345
|
+
"not": {
|
|
346
|
+
"pattern": "[={}]"
|
|
347
|
+
}
|
|
348
|
+
},
|
|
314
349
|
"examples": {
|
|
315
350
|
"description": "Usage examples attached to the command.",
|
|
316
351
|
"type": "array",
|
|
@@ -340,6 +375,82 @@
|
|
|
340
375
|
},
|
|
341
376
|
"additionalProperties": false
|
|
342
377
|
},
|
|
378
|
+
"envBound": {
|
|
379
|
+
"anyOf": [
|
|
380
|
+
{
|
|
381
|
+
"required": [
|
|
382
|
+
"envVar"
|
|
383
|
+
]
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
"required": [
|
|
387
|
+
"envIndexed"
|
|
388
|
+
]
|
|
389
|
+
}
|
|
390
|
+
]
|
|
391
|
+
},
|
|
392
|
+
"envIndexed": {
|
|
393
|
+
"description": "A numbered family of environment variables read as one input's env source.\n\nPass it to `.env()` in place of a variable name. The count variable decides\nwhether the env stage supplied a value at all, and how many entries it owns;\na declared entry with a missing member is an error, never a fallback to a\nlater source.",
|
|
394
|
+
"type": "object",
|
|
395
|
+
"required": [
|
|
396
|
+
"count"
|
|
397
|
+
],
|
|
398
|
+
"properties": {
|
|
399
|
+
"count": {
|
|
400
|
+
"description": "Variable holding how many entries the family declares, as a canonical\nnon-negative integer. When it is unset the env source supplies nothing;\n`0` supplies an explicit empty list.",
|
|
401
|
+
"type": "string",
|
|
402
|
+
"minLength": 1,
|
|
403
|
+
"not": {
|
|
404
|
+
"pattern": "[{}=]"
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
"fields": {
|
|
408
|
+
"description": "One variable template per record field, each with `{index}` standing for\nthe zero-based index. Every field is required for every declared entry.",
|
|
409
|
+
"type": "object",
|
|
410
|
+
"minProperties": 1,
|
|
411
|
+
"additionalProperties": {
|
|
412
|
+
"$ref": "#/$defs/envIndexedTemplate"
|
|
413
|
+
},
|
|
414
|
+
"propertyNames": {
|
|
415
|
+
"minLength": 1
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
"value": {
|
|
419
|
+
"$ref": "#/$defs/envIndexedTemplate",
|
|
420
|
+
"description": "Variable template for one entry, with `{index}` standing for the zero-based index."
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
"additionalProperties": false,
|
|
424
|
+
"oneOf": [
|
|
425
|
+
{
|
|
426
|
+
"required": [
|
|
427
|
+
"value"
|
|
428
|
+
],
|
|
429
|
+
"not": {
|
|
430
|
+
"required": [
|
|
431
|
+
"fields"
|
|
432
|
+
]
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
"required": [
|
|
437
|
+
"fields"
|
|
438
|
+
],
|
|
439
|
+
"not": {
|
|
440
|
+
"required": [
|
|
441
|
+
"value"
|
|
442
|
+
]
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
]
|
|
446
|
+
},
|
|
447
|
+
"envIndexedTemplate": {
|
|
448
|
+
"type": "string",
|
|
449
|
+
"pattern": "\\{index\\}",
|
|
450
|
+
"not": {
|
|
451
|
+
"pattern": "="
|
|
452
|
+
}
|
|
453
|
+
},
|
|
343
454
|
"example": {
|
|
344
455
|
"description": "A single usage example shown in help text.",
|
|
345
456
|
"type": "object",
|
|
@@ -432,6 +543,14 @@
|
|
|
432
543
|
"type": "string"
|
|
433
544
|
}
|
|
434
545
|
},
|
|
546
|
+
"envAbsolute": {
|
|
547
|
+
"description": "Whether the env source is read exactly as written, outside the CLI-wide\nnamespace set by `CLIBuilder.envPrefix()` (set by `.env(…, { absolute:\ntrue })`). Applies to FlagSchema.envVar and\nFlagSchema.envIndexed alike.\n\nDefault: `false`",
|
|
548
|
+
"const": true
|
|
549
|
+
},
|
|
550
|
+
"envIndexed": {
|
|
551
|
+
"$ref": "#/$defs/envIndexed",
|
|
552
|
+
"description": "Indexed environment family read as the env source, set by `.env()` with an\nIndexedEnvBinding (`undefined` otherwise). A flag declares at most\none env source, so this and FlagSchema.envVar are never both set."
|
|
553
|
+
},
|
|
435
554
|
"envVar": {
|
|
436
555
|
"description": "Environment variable name for v0.2+ resolution.",
|
|
437
556
|
"type": "string"
|
|
@@ -500,7 +619,18 @@
|
|
|
500
619
|
"type": "string"
|
|
501
620
|
}
|
|
502
621
|
},
|
|
503
|
-
"additionalProperties": false
|
|
622
|
+
"additionalProperties": false,
|
|
623
|
+
"dependentSchemas": {
|
|
624
|
+
"envAbsolute": {
|
|
625
|
+
"$ref": "#/$defs/envBound"
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
"not": {
|
|
629
|
+
"required": [
|
|
630
|
+
"envIndexed",
|
|
631
|
+
"envVar"
|
|
632
|
+
]
|
|
633
|
+
}
|
|
504
634
|
},
|
|
505
635
|
"flagElement": {
|
|
506
636
|
"description": "Element schema when `kind === 'array'` or `kind === 'keyValue'`.",
|
|
@@ -565,6 +695,14 @@
|
|
|
565
695
|
"type": "string"
|
|
566
696
|
}
|
|
567
697
|
},
|
|
698
|
+
"envAbsolute": {
|
|
699
|
+
"description": "Whether the env source is read exactly as written, outside the CLI-wide\nnamespace set by `CLIBuilder.envPrefix()` (set by `.env(…, { absolute:\ntrue })`). Applies to FlagSchema.envVar and\nFlagSchema.envIndexed alike.\n\nDefault: `false`",
|
|
700
|
+
"const": true
|
|
701
|
+
},
|
|
702
|
+
"envIndexed": {
|
|
703
|
+
"$ref": "#/$defs/envIndexed",
|
|
704
|
+
"description": "Indexed environment family read as the env source, set by `.env()` with an\nIndexedEnvBinding (`undefined` otherwise). A flag declares at most\none env source, so this and FlagSchema.envVar are never both set."
|
|
705
|
+
},
|
|
568
706
|
"envVar": {
|
|
569
707
|
"description": "Environment variable name for v0.2+ resolution.",
|
|
570
708
|
"type": "string"
|
|
@@ -812,6 +950,9 @@
|
|
|
812
950
|
"when"
|
|
813
951
|
],
|
|
814
952
|
"properties": {
|
|
953
|
+
"argv": {
|
|
954
|
+
"const": false
|
|
955
|
+
},
|
|
815
956
|
"consume": {
|
|
816
957
|
"description": "Whether this input consumes the stream alone.",
|
|
817
958
|
"enum": [
|
|
@@ -896,6 +1037,14 @@
|
|
|
896
1037
|
"description": "Program description (shown in root help).",
|
|
897
1038
|
"type": "string"
|
|
898
1039
|
},
|
|
1040
|
+
"envPrefix": {
|
|
1041
|
+
"description": "CLI-wide environment namespace prepended to every relative env binding\n(`undefined` when none is set). `.env('TOKEN')` reads `<envPrefix>TOKEN`;\na binding declared with `{ absolute: true }` is read as written.\n\nSet via the .envPrefix() builder method\nor the `envPrefix` field of CLIDefinition. Fixed when declared, so\nneither manifest name inference nor an inherited invocation name changes it.",
|
|
1042
|
+
"type": "string",
|
|
1043
|
+
"minLength": 1,
|
|
1044
|
+
"not": {
|
|
1045
|
+
"pattern": "[={}]"
|
|
1046
|
+
}
|
|
1047
|
+
},
|
|
899
1048
|
"name": {
|
|
900
1049
|
"description": "Program name (used in help text, usage lines, and completion scripts).",
|
|
901
1050
|
"type": "string"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kjanat/dreamcli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Schema-first, fully typed TypeScript CLI framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dreamcli",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"!**/*.pyc",
|
|
87
87
|
"!**/AGENTS.md"
|
|
88
88
|
],
|
|
89
|
-
"workspaces": ["
|
|
89
|
+
"workspaces": ["examples/*", "docs"],
|
|
90
90
|
"scripts": {
|
|
91
91
|
"bd": "run -s build typecheck:dist package:check lazy:check",
|
|
92
92
|
"build": "bun --bun tsdown",
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
"version:check": "bun scripts/check-version-sync.ts"
|
|
136
136
|
},
|
|
137
137
|
"dependencies": {
|
|
138
|
-
"ansispeck": "^0.4.
|
|
138
|
+
"ansispeck": "^0.4.3"
|
|
139
139
|
},
|
|
140
140
|
"devDependencies": {
|
|
141
141
|
"@arethetypeswrong/core": "^0.18.5",
|
|
@@ -144,19 +144,19 @@
|
|
|
144
144
|
"@types/deno": "^2.7.0",
|
|
145
145
|
"@types/node": ">=26.6.5",
|
|
146
146
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
147
|
-
"@vitest/coverage-v8": "5.0
|
|
148
|
-
"biome": "npm:@biomejs/biome@^2.
|
|
149
|
-
"dprint": "0.64.
|
|
147
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
148
|
+
"biome": "npm:@biomejs/biome@^2.6.7",
|
|
149
|
+
"dprint": "0.64.3",
|
|
150
150
|
"importmapify": "1.7.0",
|
|
151
|
-
"knip": "^6.
|
|
151
|
+
"knip": "^6.45.1",
|
|
152
152
|
"publint": "^0.3.25",
|
|
153
153
|
"runner-run": "0.28.0",
|
|
154
|
-
"tsdown": "0.23.
|
|
154
|
+
"tsdown": "0.23.7",
|
|
155
155
|
"typescript": ">=6.0.3,<7",
|
|
156
156
|
"vitest": "^5.0.5",
|
|
157
157
|
"yaml": "^2.9.1"
|
|
158
158
|
},
|
|
159
|
-
"packageManager": "bun@1.4.
|
|
159
|
+
"packageManager": "bun@1.4.4",
|
|
160
160
|
"engines": {
|
|
161
161
|
"bun": ">=1.3",
|
|
162
162
|
"deno": ">=2.6.0",
|
|
@@ -173,8 +173,8 @@
|
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
"volta": {
|
|
176
|
-
"node": "26.
|
|
177
|
-
"npm": "
|
|
176
|
+
"node": "26.13.1",
|
|
177
|
+
"npm": "12.2.2"
|
|
178
178
|
},
|
|
179
179
|
"publishConfig": {
|
|
180
180
|
"access": "public"
|
|
@@ -52,7 +52,7 @@ deno doc --filter=CLIBuilder jsr:@kjanat/dreamcli 2>/dev/null # one symbol
|
|
|
52
52
|
`2>/dev/null` matters: deno writes download and type-check progress to stderr,
|
|
53
53
|
which otherwise swamps the documentation output.
|
|
54
54
|
|
|
55
|
-
Pin a version with `jsr:@kjanat/dreamcli@
|
|
55
|
+
Pin a version with `jsr:@kjanat/dreamcli@5.1.0` when the project is not on
|
|
56
56
|
latest. `--filter` takes a declaration name; it prints nothing for a name that
|
|
57
57
|
does not exist, which is itself a useful signal.
|
|
58
58
|
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { a as WriteFn, s as ReadFn } from "./index-B6oD4_8b.mjs";
|
|
2
|
-
//#region src/runtime/adapter.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Runtime adapter interface.
|
|
5
|
-
*
|
|
6
|
-
* Defines the minimal contract between the platform-agnostic core and
|
|
7
|
-
* the host runtime (Node.js, Bun, Deno). Every platform-dependent
|
|
8
|
-
* operation flows through this interface — the core never calls
|
|
9
|
-
* `process.*`, `Deno.*`, or `Bun.*` directly.
|
|
10
|
-
*
|
|
11
|
-
* Adapters are designed to be:
|
|
12
|
-
* - **Immutable in shape:** all properties are readonly
|
|
13
|
-
* - **Minimal:** only the operations the framework actually needs
|
|
14
|
-
* - **Testable:** easily stubbed in tests via {@linkcode createTestAdapter | createTestAdapter()}
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* // Production: auto-detected
|
|
19
|
-
* cli('mycli').run(); // uses Node/Bun/Deno adapter
|
|
20
|
-
*
|
|
21
|
-
* // Test: explicit adapter
|
|
22
|
-
* cli('mycli').run({ adapter: createTestAdapter({ argv: ['deploy'] }) });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
interface RuntimeAdapter {
|
|
26
|
-
/** Raw argv array (including binary + script path, e.g. `['node', 'cli.js', 'deploy']`). */
|
|
27
|
-
readonly argv: readonly string[];
|
|
28
|
-
/**
|
|
29
|
-
* Environment variables.
|
|
30
|
-
* Values are `string | undefined` — mirrors Node's `process.env` semantics.
|
|
31
|
-
*/
|
|
32
|
-
readonly env: Readonly<Record<string, string | undefined>>;
|
|
33
|
-
/** Current working directory (absolute path). */
|
|
34
|
-
readonly cwd: string;
|
|
35
|
-
/** Writer for stdout. Framework routes `out.log`/`out.info` through this. */
|
|
36
|
-
readonly stdout: WriteFn;
|
|
37
|
-
/** Writer for stderr. Framework routes `out.warn`/`out.error` through this. */
|
|
38
|
-
readonly stderr: WriteFn;
|
|
39
|
-
/** Wait for pending output writes to settle, rejecting with a recorded output failure. */
|
|
40
|
-
readonly flush?: () => Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Line reader for stdin. Used by the prompt engine for interactive input.
|
|
43
|
-
*
|
|
44
|
-
* Returns `null` on EOF (Ctrl+D on Unix, Ctrl+Z on Windows),
|
|
45
|
-
* indicating the user closed the input stream (treated as cancel).
|
|
46
|
-
*/
|
|
47
|
-
readonly stdin: ReadFn;
|
|
48
|
-
/** Hidden terminal input. Absent when echo suppression is unsupported. */
|
|
49
|
-
readonly readSecret?: ReadFn;
|
|
50
|
-
/**
|
|
51
|
-
* Read all of stdin as a single string (for piped data).
|
|
52
|
-
*
|
|
53
|
-
* Returns the full stdin contents when data is piped (`stdinIsTTY` is
|
|
54
|
-
* false), or `null` when stdin is a TTY (no piped data available).
|
|
55
|
-
*
|
|
56
|
-
* Used by the resolve chain for args with `.stdin()` configured.
|
|
57
|
-
* Unlike {@link stdin} (which reads one line for prompts), this
|
|
58
|
-
* consumes the entire stream to EOF.
|
|
59
|
-
*
|
|
60
|
-
* @returns Full stdin contents as a string, or `null` if stdin is a TTY.
|
|
61
|
-
*/
|
|
62
|
-
readonly readStdin: () => Promise<string | null>;
|
|
63
|
-
/** Whether stdout is connected to a TTY. */
|
|
64
|
-
readonly isTTY: boolean;
|
|
65
|
-
/** Whether stdin is connected to a TTY (used for prompt gating). */
|
|
66
|
-
readonly stdinIsTTY: boolean;
|
|
67
|
-
/** Read current terminal dimensions for stdout, if available. */
|
|
68
|
-
readonly getTerminalSize: () => TerminalSize | undefined;
|
|
69
|
-
/** Subscribe to terminal resize events when the runtime supports them. */
|
|
70
|
-
readonly onTerminalResize: (listener: () => void) => (() => void) | undefined;
|
|
71
|
-
/**
|
|
72
|
-
* Exit the process with the given code.
|
|
73
|
-
* Must not return (divergent function).
|
|
74
|
-
*/
|
|
75
|
-
readonly exit: (code: number) => never;
|
|
76
|
-
/**
|
|
77
|
-
* Read a file as UTF-8 text.
|
|
78
|
-
*
|
|
79
|
-
* Returns file contents on success, `null` if the file does not exist
|
|
80
|
-
* (ENOENT/NotFound). Throws on other I/O errors (permission denied,
|
|
81
|
-
* is-directory, etc.) — those indicate unexpected failures, not
|
|
82
|
-
* "try the next path".
|
|
83
|
-
*
|
|
84
|
-
* Used by config file discovery to probe multiple candidate paths.
|
|
85
|
-
*/
|
|
86
|
-
readonly readFile: (path: string) => Promise<string | null>;
|
|
87
|
-
/**
|
|
88
|
-
* Probe what exists at a filesystem path.
|
|
89
|
-
*
|
|
90
|
-
* Returns `'file'` or `'directory'` for existing paths (other kinds such
|
|
91
|
-
* as sockets report `'file'`), or `null` when nothing exists there.
|
|
92
|
-
*
|
|
93
|
-
* Used by `flag.path()` existence/type checks after resolution.
|
|
94
|
-
*/
|
|
95
|
-
readonly stat: (path: string) => Promise<'file' | 'directory' | null>;
|
|
96
|
-
/**
|
|
97
|
-
* Create a directory, including missing parents.
|
|
98
|
-
*
|
|
99
|
-
* Succeeds when the directory already exists. Throws on other I/O errors
|
|
100
|
-
* (permission denied, existing file at the path, etc.).
|
|
101
|
-
*
|
|
102
|
-
* Used by `flag.path()` `create` checks after resolution.
|
|
103
|
-
*/
|
|
104
|
-
readonly mkdir: (path: string) => Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* User home directory (absolute path).
|
|
107
|
-
*
|
|
108
|
-
* - Node/Bun: derived from `HOME` / `USERPROFILE` env
|
|
109
|
-
* - Deno: `Deno.env.get('HOME')` / `Deno.env.get('USERPROFILE')`
|
|
110
|
-
*/
|
|
111
|
-
readonly homedir: string;
|
|
112
|
-
/**
|
|
113
|
-
* Platform-specific user configuration directory (absolute path).
|
|
114
|
-
*
|
|
115
|
-
* - Unix: `$XDG_CONFIG_HOME` or `~/.config`
|
|
116
|
-
* - Windows: `%APPDATA%` or `~\AppData\Roaming`
|
|
117
|
-
*
|
|
118
|
-
* Config discovery appends the app-specific subdirectory.
|
|
119
|
-
*/
|
|
120
|
-
readonly configDir: string;
|
|
121
|
-
/**
|
|
122
|
-
* User-scope config roots for discovery, highest priority first.
|
|
123
|
-
*
|
|
124
|
-
* - Unix: `[configDir]`
|
|
125
|
-
* - macOS: `[configDir, ~/Library/Application Support]`
|
|
126
|
-
* - Windows: `[configDir]`
|
|
127
|
-
*
|
|
128
|
-
* When absent, discovery falls back to `[configDir]`.
|
|
129
|
-
*/
|
|
130
|
-
readonly userConfigDirs?: readonly string[];
|
|
131
|
-
/**
|
|
132
|
-
* System-scope config roots for discovery (`['/etc']` on Linux and
|
|
133
|
-
* macOS, `[]` on Windows). When absent, discovery probes none.
|
|
134
|
-
*/
|
|
135
|
-
readonly systemConfigDirs?: readonly string[];
|
|
136
|
-
}
|
|
137
|
-
/** Current terminal dimensions in columns and rows. */
|
|
138
|
-
interface TerminalSize {
|
|
139
|
-
/** Terminal width in columns. */
|
|
140
|
-
readonly columns: number;
|
|
141
|
-
/** Terminal height in rows. */
|
|
142
|
-
readonly rows: number;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Options for creating a test adapter.
|
|
146
|
-
*
|
|
147
|
-
* All fields are optional — sensible defaults are applied for testing
|
|
148
|
-
* scenarios (empty argv, empty env, noop stdout/stderr, non-TTY, exit
|
|
149
|
-
* throws instead of killing the process).
|
|
150
|
-
*/
|
|
151
|
-
interface TestAdapterOptions {
|
|
152
|
-
/** Raw argv (defaults to `['node', 'test']`). */
|
|
153
|
-
readonly argv?: readonly string[];
|
|
154
|
-
/** Environment variables (defaults to `{}`). */
|
|
155
|
-
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
156
|
-
/** Working directory (defaults to `'/test'`). */
|
|
157
|
-
readonly cwd?: string;
|
|
158
|
-
/** Stdout writer (defaults to noop). */
|
|
159
|
-
readonly stdout?: WriteFn;
|
|
160
|
-
/** Stderr writer (defaults to noop). */
|
|
161
|
-
readonly stderr?: WriteFn;
|
|
162
|
-
/**
|
|
163
|
-
* Stdin line reader (defaults to returning `null` — immediate EOF).
|
|
164
|
-
*
|
|
165
|
-
* Use a custom {@linkcode ReadFn} to simulate user input in tests.
|
|
166
|
-
*/
|
|
167
|
-
readonly stdin?: ReadFn;
|
|
168
|
-
/** Hidden reader stub; omitted adapters report unsupported hidden input. */
|
|
169
|
-
readonly readSecret?: ReadFn;
|
|
170
|
-
/**
|
|
171
|
-
* Piped stdin data for testing args with `.stdin()` configured.
|
|
172
|
-
*
|
|
173
|
-
* When provided and `stdinIsTTY` is `false`, `readStdin()` returns this
|
|
174
|
-
* string once, then `null` on subsequent reads. When absent, or when
|
|
175
|
-
* `stdinIsTTY` is `true`, `readStdin()` returns `null`.
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```ts
|
|
179
|
-
* createTestAdapter({
|
|
180
|
-
* stdinData: '{"key": "value"}',
|
|
181
|
-
* })
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
readonly stdinData?: string;
|
|
185
|
-
/** TTY flag for stdout (defaults to `false`). */
|
|
186
|
-
readonly isTTY?: boolean;
|
|
187
|
-
/** TTY flag for stdin (defaults to `false`). */
|
|
188
|
-
readonly stdinIsTTY?: boolean;
|
|
189
|
-
/** Terminal dimensions returned by `getTerminalSize()`. */
|
|
190
|
-
readonly terminalSize?: TerminalSize;
|
|
191
|
-
/** Resize subscription hook returned by `onTerminalResize()`. */
|
|
192
|
-
readonly onTerminalResize?: (listener: () => void) => (() => void) | undefined;
|
|
193
|
-
/**
|
|
194
|
-
* Exit function (defaults to throwing {@linkcode ExitError}).
|
|
195
|
-
* The default throw-based exit allows tests to catch the exit code.
|
|
196
|
-
*/
|
|
197
|
-
readonly exit?: (code: number) => never;
|
|
198
|
-
/**
|
|
199
|
-
* File reader stub (defaults to returning `null` — all files not found).
|
|
200
|
-
*
|
|
201
|
-
* Supply a custom function to simulate a virtual filesystem in tests:
|
|
202
|
-
* ```ts
|
|
203
|
-
* createTestAdapter({
|
|
204
|
-
* readFile: (path) => Promise.resolve(
|
|
205
|
-
* path === '/home/test/.config/myapp/config.json'
|
|
206
|
-
* ? '{"region":"eu"}'
|
|
207
|
-
* : null
|
|
208
|
-
* ),
|
|
209
|
-
* })
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
readonly readFile?: (path: string) => Promise<string | null>;
|
|
213
|
-
/**
|
|
214
|
-
* Filesystem probe stub for `flag.path()` checks (defaults to returning
|
|
215
|
-
* `null` — nothing exists).
|
|
216
|
-
*
|
|
217
|
-
* Supply a custom function to simulate a virtual filesystem in tests:
|
|
218
|
-
* ```ts
|
|
219
|
-
* createTestAdapter({
|
|
220
|
-
* stat: (path) => Promise.resolve(path === '/data' ? 'directory' : null),
|
|
221
|
-
* })
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
readonly stat?: (path: string) => Promise<'file' | 'directory' | null>;
|
|
225
|
-
/**
|
|
226
|
-
* Directory creation stub for `flag.path()` `create` checks (defaults to
|
|
227
|
-
* a noop that resolves without creating anything).
|
|
228
|
-
*/
|
|
229
|
-
readonly mkdir?: (path: string) => Promise<void>;
|
|
230
|
-
/** Home directory (defaults to `'/home/test'`). */
|
|
231
|
-
readonly homedir?: string;
|
|
232
|
-
/** Config directory (defaults to `'/home/test/.config'`). */
|
|
233
|
-
readonly configDir?: string;
|
|
234
|
-
/** User-scope config roots for discovery (defaults to `[configDir]`). */
|
|
235
|
-
readonly userConfigDirs?: readonly string[];
|
|
236
|
-
/** System-scope config roots for discovery (defaults to `[]`). */
|
|
237
|
-
readonly systemConfigDirs?: readonly string[];
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Error thrown by adapter implementations that model process exit as an
|
|
241
|
-
* exception instead of terminating immediately.
|
|
242
|
-
*
|
|
243
|
-
* Runtime and CLI dispatch layers can catch this to perform real process
|
|
244
|
-
* termination, while tests can assert on exit codes without killing the
|
|
245
|
-
* runner:
|
|
246
|
-
*
|
|
247
|
-
* ```ts
|
|
248
|
-
* try {
|
|
249
|
-
* await cli.run({ adapter: createTestAdapter() });
|
|
250
|
-
* } catch (e) {
|
|
251
|
-
* if (e instanceof ExitError) expect(e.code).toBe(0);
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
declare class ExitError extends Error {
|
|
256
|
-
/** Error name — always `'ExitError'` for `instanceof` checks. */
|
|
257
|
-
readonly name = "ExitError";
|
|
258
|
-
/** The exit code passed to `exit()`. */
|
|
259
|
-
readonly code: number;
|
|
260
|
-
/** Create an ExitError for the given process exit code. */
|
|
261
|
-
constructor(code: number);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Create a test runtime adapter with injectable process state.
|
|
265
|
-
*
|
|
266
|
-
* Use this in `@kjanat/dreamcli/testkit` tests when you need to simulate argv,
|
|
267
|
-
* environment variables, TTY state, stdin, or config-file reads without
|
|
268
|
-
* touching the host process.
|
|
269
|
-
*
|
|
270
|
-
* @param options - Optional overrides for any adapter field.
|
|
271
|
-
* @returns A {@linkcode RuntimeAdapter} suitable for test scenarios.
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```ts
|
|
275
|
-
* const adapter = createTestAdapter({
|
|
276
|
-
* argv: ['node', 'cli.js', 'deploy', '--force'],
|
|
277
|
-
* env: { DEPLOY_REGION: 'us' },
|
|
278
|
-
* });
|
|
279
|
-
*
|
|
280
|
-
* const result = await cli('mycli').run({ adapter });
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
declare function createTestAdapter(options?: TestAdapterOptions): RuntimeAdapter;
|
|
284
|
-
//#endregion
|
|
285
|
-
export { createTestAdapter as a, TestAdapterOptions as i, RuntimeAdapter as n, TerminalSize as r, ExitError as t };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{E as flagExpectsValue,G as createFlagSchema,I as resolvePlainHelpDescription,J as getFlagNegatedName,et as builtinEnabled,f as resolveRootSurface,m as collectPropagatedFlags,q as getFlagAliasNames,tt as CLIError}from"./core-B4Twhd48.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 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(``),s.push(`${n}() {`),s.push(` local cur prev words cword`),s.push(` _init_completion || return`),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.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)){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(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(r.kind!==`enum`||r.enumValues===void 0)continue;let e=[`--${n}`,...getFlagAliasNames(r,{includeHidden:!0}).map(e=>e.length===1?`-${e}`:`--${e}`)].map(escapeBashCasePatternValue);t.push({flags:e.join(`|`),values:r.enumValues})}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(``),emitFishPathHelpers(l,r,i,o,s,a),appendFishCommandCompletions(l,c,i,``,o),appendFishFlagCompletions(l,c,i,``,a.rootFlags),a.includeDefaultFlags&&appendFishFlagCompletions(l,c,i,``,a.defaultFlags);for(let e of s){let t=e.path.join(` `);appendFishCommandCompletions(l,c,i,t,e.children),appendFishFlagCompletions(l,c,i,t,e.mergedFlags)}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 -opc)`),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){let a=buildFishCondition(n,r);for(let[n,r]of Object.entries(i)){let i=[`complete -c ${t}`,`-n "${a}"`];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 o=getVisibleNegatedName(n,r);if(o!==void 0&&i.push(`-l ${quoteShellArg(o)}`),i.push(`-d ${quoteShellArg(r.description===void 0?n:resolvePlainHelpDescription(r.description))}`),flagExpectsValue(r)&&i.push(`-r`,`-f`),r.kind===`enum`&&r.enumValues!==void 0)for(let t of r.enumValues)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(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)`),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)){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.enumValues??[])}`),e.push(` }`)}e.push(` )`),e.push(` }`)}function emitPowerShellHelpers(e,t,n){e.push(`function ${t}_UnquoteToken {`),e.push(` param([string]$TokenText)`),e.push(` if ($TokenText.Length -lt 2) {`),e.push(` return $TokenText`),e.push(` }`),e.push(``),e.push(` if (($TokenText.StartsWith("'") -and $TokenText.EndsWith("'")) -or`),e.push(` ($TokenText.StartsWith('"') -and $TokenText.EndsWith('"'))) {`),e.push(` return $TokenText.Substring(1, $TokenText.Length - 2)`),e.push(` }`),e.push(``),e.push(` return $TokenText`),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}() {`),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(`
|
|
6
|
-
`)}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)){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=``;if(flagExpectsValue(r)&&(u=r.kind===`enum`&&r.enumValues!==void 0?`:value:(${r.enumValues.map(escapeZshEnumValue).join(` `)})`:`:value:`),l.length>1){let n=l.map(escapeZshCasePatternValue).join(`,`);t.push(`${quoteShellArg(`(${l.join(` `)})`)}{${n}}${quoteShellArg(`[${e}]${u}`)}`)}else t.push(quoteShellArg(`${i}[${e}]${u}`))}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({generateBashCompletion:()=>generateBashCompletion,generateCompletion:()=>generateCompletion,generateFishCompletion:()=>generateFishCompletion,generatePowerShellCompletion:()=>generatePowerShellCompletion,generateZshCompletion:()=>generateZshCompletion});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};
|
package/dist/config-BgJZ-X4r.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{tt as CLIError}from"./core-B4Twhd48.mjs";var config_exports=/* @__PURE__ */ __exportAll({buildConfigSearchPaths:()=>buildConfigSearchPaths,configFormat:()=>configFormat,discoverConfig:()=>discoverConfig});function isPlainObject(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const jsonLoader={extensions:[`json`],parse:e=>{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`Config must be a JSON object`);return t}};function joinPath(e,...t){let n=e.includes(`\\`)?`\\`:`/`;return[e.endsWith(n)?e.slice(0,-1):e,...t].join(n)}function ancestorDirs(e){let t=e.includes(`\\`)?`\\`:`/`,n=e;for(;n.length>1&&n.endsWith(t)&&!n.endsWith(`:${t}`);)n=n.slice(0,-1);let r=[n];for(;;){let e=n.lastIndexOf(t);if(e<0)break;let i=n.slice(0,e);if(i===``?i=t:/^[A-Za-z]:$/.test(i)&&(i=`${i}${t}`),i===n)break;r.push(i),n=i}return r}function getExtension(e){let t=e.lastIndexOf(`.`);return t<=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))?``:e.slice(t+1).toLowerCase()}function buildConfigSearchPaths(e,t){let n=buildExtensionList(t.loaders),r=[];for(let i of ancestorDirs(t.baseDir)){for(let t of n)r.push(joinPath(i,`.${e}.${t}`));for(let t of n)r.push(joinPath(i,`${e}.config.${t}`));for(let t of n)r.push(joinPath(i,`.config`,`${e}.${t}`))}for(let i of t.userConfigDirs)for(let t of n)r.push(joinPath(i,e,`config.${t}`));for(let i of t.systemConfigDirs??[])for(let t of n)r.push(joinPath(i,e,`config.${t}`));return r}function buildExtensionList(e){let t=/* @__PURE__ */ new Set,n=[];for(let e of jsonLoader.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}if(e!==void 0)for(let r of e)for(let e of r.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}return n}function buildLoaderMap(e){let t=/* @__PURE__ */ new Map;for(let e of jsonLoader.extensions)t.set(e.toLowerCase(),jsonLoader);if(e!==void 0)for(let n of e)for(let e of n.extensions)t.set(e.toLowerCase(),n);return t}async function discoverConfig(e,t,n){let r=buildLoaderMap(n?.loaders),i=n?.configPath===void 0?n?.searchPaths??buildConfigSearchPaths(e,{baseDir:n?.baseDir??t.cwd,userConfigDirs:t.userConfigDirs??[t.configDir],systemConfigDirs:t.systemConfigDirs??[],...n?.loaders===void 0?{}:{loaders:n.loaders}}):[n.configPath];for(let e of i){let i=await t.readFile(e);if(i===null){if(n?.configPath!==void 0)throw new CLIError(`Config file not found: ${e}`,{code:`CONFIG_NOT_FOUND`,details:{path:e},suggest:`Create the config file or remove the --config flag`});continue}let a=getExtension(e),o=r.get(a);if(o===void 0)throw new CLIError(`No loader registered for config format: .${a}`,{code:`CONFIG_UNKNOWN_FORMAT`,details:{path:e,extension:a},suggest:`Supported formats: ${[...r.keys()].join(`, `)}`});try{let t=o.parse(i);if(!isPlainObject(t))throw Error(`Config loader must return a plain object`);return{found:!0,path:e,data:t,format:a}}catch(t){throw new CLIError(`Failed to parse config file: ${e}`,{code:`CONFIG_PARSE_ERROR`,cause:t,details:{path:e,format:a,message:t instanceof Error?t.message:String(t)},suggest:`Check the config file for syntax errors`})}}return{found:!1}}function configFormat(e,t){return{extensions:e,parse:t}}export{discoverConfig as i,configFormat as n,config_exports as r,buildConfigSearchPaths as t};
|