@kjanat/dreamcli 2.0.1 → 2.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/CHANGELOG.md +41 -1
- package/README.md +1 -1
- package/dist/core/completion/shells/powershell.mjs +2 -2
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +90 -90
- package/dist/core/resolve/flags.d.mts +5 -2
- package/dist/core/resolve/flags.mjs +1 -1
- package/dist/core/schema/flag.d.mts +32 -2
- package/dist/runtime/support.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/examples/gh/package.json +3 -3
- package/examples/pwsh-demo/README.md +40 -0
- package/examples/pwsh-demo/package.json +47 -0
- package/examples/pwsh-demo/pwsh-demo.cmd +3 -0
- package/examples/pwsh-demo/smoke-powershell.ps1 +218 -0
- package/examples/pwsh-demo/src/main.test.ts +48 -0
- package/examples/pwsh-demo/src/main.ts +130 -0
- package/package.json +10 -9
- package/src/core/completion/shells/powershell.ts +41 -7
- package/src/core/json-schema/meta-descriptions.generated.ts +98 -115
- package/src/core/resolve/flags.ts +53 -3
- package/src/core/schema/flag.ts +47 -2
- package/src/runtime/support.ts +2 -2
|
@@ -6,193 +6,176 @@
|
|
|
6
6
|
|
|
7
7
|
const definitionMetaSchemaDescriptions = {
|
|
8
8
|
root: {
|
|
9
|
-
description:
|
|
10
|
-
'Runtime descriptor for the CLI program.\n\nStores the program name, version, description, and registered commands.\\\nBuilt incrementally by CLIBuilder.',
|
|
9
|
+
description: "Runtime descriptor for the CLI program.\n\nStores the program name, version, description, and registered commands.\\\nBuilt incrementally by CLIBuilder.",
|
|
11
10
|
properties: {
|
|
12
|
-
name: {
|
|
13
|
-
description:
|
|
11
|
+
"name": {
|
|
12
|
+
description: "Program name (used in help text, usage lines, and completion scripts).",
|
|
14
13
|
},
|
|
15
|
-
version: {
|
|
16
|
-
description:
|
|
14
|
+
"version": {
|
|
15
|
+
description: "Program version (shown by `--version`).",
|
|
17
16
|
},
|
|
18
|
-
description: {
|
|
19
|
-
description:
|
|
17
|
+
"description": {
|
|
18
|
+
description: "Program description (shown in root help).",
|
|
20
19
|
},
|
|
21
|
-
defaultCommand: {
|
|
22
|
-
description:
|
|
23
|
-
'Default command dispatched when no subcommand matches.\n\nWhen set, the CLI root behaves like a hybrid command group: subcommands\ndispatch by name as usual, but empty argv or flags-only argv falls\nthrough to this command instead of showing root help.\n\nSet via the .default() builder method.',
|
|
20
|
+
"defaultCommand": {
|
|
21
|
+
description: "Default command dispatched when no subcommand matches.\n\nWhen set, the CLI root behaves like a hybrid command group: subcommands\ndispatch by name as usual, but empty argv or flags-only argv falls\nthrough to this command instead of showing root help.\n\nSet via the .default() builder method.",
|
|
24
22
|
},
|
|
25
|
-
commands: {
|
|
26
|
-
description:
|
|
23
|
+
"commands": {
|
|
24
|
+
description: "Registered commands (type-erased for heterogeneous storage).",
|
|
27
25
|
},
|
|
28
26
|
},
|
|
29
27
|
},
|
|
30
28
|
defs: {
|
|
31
|
-
command: {
|
|
32
|
-
description:
|
|
33
|
-
"Runtime descriptor produced by CommandBuilder.\n\nConsumers (parser, help generator, CLI dispatcher) read this to\nunderstand the command's shape — flags, args, aliases, subcommands,\nmiddleware, and interactive resolver.",
|
|
29
|
+
"command": {
|
|
30
|
+
description: "Runtime descriptor produced by CommandBuilder.\n\nConsumers (parser, help generator, CLI dispatcher) read this to\nunderstand the command's shape — flags, args, aliases, subcommands,\nmiddleware, and interactive resolver.",
|
|
34
31
|
properties: {
|
|
35
|
-
name: {
|
|
32
|
+
"name": {
|
|
36
33
|
description: "The command name (used for dispatch, e.g. `'deploy'`).",
|
|
37
34
|
},
|
|
38
|
-
description: {
|
|
39
|
-
description:
|
|
35
|
+
"description": {
|
|
36
|
+
description: "Human-readable description for help text.",
|
|
40
37
|
},
|
|
41
|
-
aliases: {
|
|
42
|
-
description:
|
|
38
|
+
"aliases": {
|
|
39
|
+
description: "Alternative names for this command.",
|
|
43
40
|
},
|
|
44
|
-
hidden: {
|
|
45
|
-
description:
|
|
41
|
+
"hidden": {
|
|
42
|
+
description: "Whether this command is hidden from help listings.",
|
|
46
43
|
},
|
|
47
|
-
examples: {
|
|
48
|
-
description:
|
|
44
|
+
"examples": {
|
|
45
|
+
description: "Usage examples for help text.",
|
|
49
46
|
},
|
|
50
|
-
flags: {
|
|
51
|
-
description:
|
|
47
|
+
"flags": {
|
|
48
|
+
description: "Named flag schemas, keyed by flag name.",
|
|
52
49
|
},
|
|
53
|
-
args: {
|
|
54
|
-
description:
|
|
50
|
+
"args": {
|
|
51
|
+
description: "Ordered positional arg entries (name + schema).",
|
|
55
52
|
},
|
|
56
|
-
commands: {
|
|
57
|
-
description:
|
|
58
|
-
'Nested subcommand schemas (for help rendering and completion).\n\nPure data — no execution closures. Populated by `.command()` on\n`CommandBuilder`. Empty for leaf commands.',
|
|
53
|
+
"commands": {
|
|
54
|
+
description: "Nested subcommand schemas (for help rendering and completion).\n\nPure data — no execution closures. Populated by `.command()` on\n`CommandBuilder`. Empty for leaf commands.",
|
|
59
55
|
},
|
|
60
56
|
},
|
|
61
57
|
},
|
|
62
|
-
flag: {
|
|
63
|
-
description:
|
|
64
|
-
"The runtime descriptor stored inside every FlagBuilder. Consumers (parser,\nhelp generator, resolution chain) read this to understand the flag's shape\nwithout touching generics.",
|
|
58
|
+
"flag": {
|
|
59
|
+
description: "The runtime descriptor stored inside every FlagBuilder. Consumers (parser,\nhelp generator, resolution chain) read this to understand the flag's shape\nwithout touching generics.",
|
|
65
60
|
properties: {
|
|
66
|
-
kind: {
|
|
67
|
-
description:
|
|
61
|
+
"kind": {
|
|
62
|
+
description: "What kind of value this flag accepts.",
|
|
68
63
|
},
|
|
69
|
-
presence: {
|
|
70
|
-
description:
|
|
71
|
-
"Presence describes whether a flag value is guaranteed to exist when the\naction handler runs:\n\n- `'optional'` — not required; unresolved value follows the kind-specific\n optional fallback (`undefined` for most flags, `[]` for arrays)\n- `'required'` — must be supplied; error if missing\n- `'defaulted'` — always present (falls back to default value)",
|
|
64
|
+
"presence": {
|
|
65
|
+
description: "Presence describes whether a flag value is guaranteed to exist when the\naction handler runs:\n\n- `'optional'` — not required; unresolved value follows the kind-specific\n optional fallback (`undefined` for most flags, `[]` for arrays)\n- `'required'` — must be supplied; error if missing\n- `'defaulted'` — always present (falls back to default value)",
|
|
72
66
|
},
|
|
73
|
-
defaultValue: {
|
|
74
|
-
description:
|
|
67
|
+
"defaultValue": {
|
|
68
|
+
description: "Runtime default value (if any).",
|
|
75
69
|
},
|
|
76
|
-
aliases: {
|
|
70
|
+
"aliases": {
|
|
77
71
|
description: "Short/long aliases (e.g. `[{ name: 'f', hidden: false }]` for `--force`).",
|
|
78
72
|
},
|
|
79
|
-
envVar: {
|
|
80
|
-
description:
|
|
73
|
+
"envVar": {
|
|
74
|
+
description: "Environment variable name for v0.2+ resolution.",
|
|
81
75
|
},
|
|
82
|
-
configPath: {
|
|
76
|
+
"configPath": {
|
|
83
77
|
description: "Dotted config path for v0.2+ resolution (e.g. `'deploy.region'`).",
|
|
84
78
|
},
|
|
85
|
-
description: {
|
|
86
|
-
description:
|
|
79
|
+
"description": {
|
|
80
|
+
description: "Human-readable description for help text.",
|
|
87
81
|
},
|
|
88
|
-
enumValues: {
|
|
82
|
+
"enumValues": {
|
|
89
83
|
description: "Allowed literal values when `kind === 'enum'`.",
|
|
90
84
|
},
|
|
91
|
-
elementSchema: {
|
|
85
|
+
"elementSchema": {
|
|
92
86
|
description: "Element schema when `kind === 'array'`.",
|
|
93
87
|
},
|
|
94
|
-
prompt: {
|
|
95
|
-
description:
|
|
88
|
+
"prompt": {
|
|
89
|
+
description: "Interactive prompt configuration for v0.3+ resolution.",
|
|
96
90
|
},
|
|
97
|
-
deprecated: {
|
|
98
|
-
description:
|
|
99
|
-
'Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated flag is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`.',
|
|
91
|
+
"deprecated": {
|
|
92
|
+
description: "Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated flag is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`.",
|
|
100
93
|
},
|
|
101
|
-
propagate: {
|
|
102
|
-
description:
|
|
103
|
-
'Whether this flag propagates to subcommands in nested command trees.\n\nWhen `true`, the flag is automatically available to all descendant\ncommands. A child command that defines a flag with the same name\nshadows the propagated parent flag.',
|
|
94
|
+
"propagate": {
|
|
95
|
+
description: "Whether this flag propagates to subcommands in nested command trees.\n\nWhen `true`, the flag is automatically available to all descendant\ncommands. A child command that defines a flag with the same name\nshadows the propagated parent flag.",
|
|
104
96
|
},
|
|
105
97
|
},
|
|
106
98
|
},
|
|
107
|
-
arg: {
|
|
108
|
-
description:
|
|
109
|
-
"The runtime descriptor stored inside every ArgBuilder. Consumers (parser,\nhelp generator) read this to understand the arg's shape without touching\ngenerics.",
|
|
99
|
+
"arg": {
|
|
100
|
+
description: "The runtime descriptor stored inside every ArgBuilder. Consumers (parser,\nhelp generator) read this to understand the arg's shape without touching\ngenerics.",
|
|
110
101
|
properties: {
|
|
111
|
-
name: {
|
|
112
|
-
description:
|
|
113
|
-
'A named positional argument entry in the command schema.\n\nPairs a user-facing arg name with its ArgSchema descriptor.\nThe array ordering in CommandSchema.args determines CLI position.',
|
|
102
|
+
"name": {
|
|
103
|
+
description: "A named positional argument entry in the command schema.\n\nPairs a user-facing arg name with its ArgSchema descriptor.\nThe array ordering in CommandSchema.args determines CLI position.",
|
|
114
104
|
},
|
|
115
|
-
kind: {
|
|
116
|
-
description:
|
|
105
|
+
"kind": {
|
|
106
|
+
description: "What kind of value this arg accepts.",
|
|
117
107
|
},
|
|
118
|
-
presence: {
|
|
119
|
-
description:
|
|
120
|
-
"Presence describes whether a positional arg is guaranteed to exist when the\naction handler runs:\n\n- `'required'` — must be supplied; error if missing (default)\n- `'optional'` — may be `undefined` if not supplied\n- `'defaulted'` — always present (falls back to default value)",
|
|
108
|
+
"presence": {
|
|
109
|
+
description: "Presence describes whether a positional arg is guaranteed to exist when the\naction handler runs:\n\n- `'required'` — must be supplied; error if missing (default)\n- `'optional'` — may be `undefined` if not supplied\n- `'defaulted'` — always present (falls back to default value)",
|
|
121
110
|
},
|
|
122
|
-
variadic: {
|
|
123
|
-
description:
|
|
111
|
+
"variadic": {
|
|
112
|
+
description: "Whether this arg consumes all remaining positionals.",
|
|
124
113
|
},
|
|
125
|
-
stdinMode: {
|
|
126
|
-
description:
|
|
114
|
+
"stdinMode": {
|
|
115
|
+
description: "Whether this arg may read from stdin during resolution.",
|
|
127
116
|
},
|
|
128
|
-
defaultValue: {
|
|
129
|
-
description:
|
|
117
|
+
"defaultValue": {
|
|
118
|
+
description: "Runtime default value (if any).",
|
|
130
119
|
},
|
|
131
|
-
description: {
|
|
132
|
-
description:
|
|
120
|
+
"description": {
|
|
121
|
+
description: "Human-readable description for help text.",
|
|
133
122
|
},
|
|
134
|
-
envVar: {
|
|
135
|
-
description:
|
|
136
|
-
"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.",
|
|
123
|
+
"envVar": {
|
|
124
|
+
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.",
|
|
137
125
|
},
|
|
138
|
-
enumValues: {
|
|
126
|
+
"enumValues": {
|
|
139
127
|
description: "Allowed literal values when `kind === 'enum'`.",
|
|
140
128
|
},
|
|
141
|
-
deprecated: {
|
|
142
|
-
description:
|
|
143
|
-
'Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated arg is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`.',
|
|
129
|
+
"deprecated": {
|
|
130
|
+
description: "Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated arg is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`.",
|
|
144
131
|
},
|
|
145
132
|
},
|
|
146
133
|
},
|
|
147
|
-
prompt: {
|
|
148
|
-
description:
|
|
149
|
-
"Discriminated union of all prompt configurations.\n\nUse the `kind` field to narrow:\n```ts\nif (config.kind === 'select') {\n config.choices // readonly SelectChoice[] | undefined\n}\n```",
|
|
134
|
+
"prompt": {
|
|
135
|
+
description: "Discriminated union of all prompt configurations.\n\nUse the `kind` field to narrow:\n```ts\nif (config.kind === 'select') {\n config.choices // readonly SelectChoice[] | undefined\n}\n```",
|
|
150
136
|
properties: {
|
|
151
|
-
kind: {
|
|
152
|
-
description:
|
|
153
|
-
"The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list",
|
|
137
|
+
"kind": {
|
|
138
|
+
description: "The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list",
|
|
154
139
|
},
|
|
155
|
-
message: {
|
|
156
|
-
description:
|
|
140
|
+
"message": {
|
|
141
|
+
description: "The question displayed to the user.",
|
|
157
142
|
},
|
|
158
|
-
placeholder: {
|
|
159
|
-
description:
|
|
143
|
+
"placeholder": {
|
|
144
|
+
description: "Placeholder text shown before user types (informational only).",
|
|
160
145
|
},
|
|
161
|
-
choices: {
|
|
162
|
-
description:
|
|
163
|
-
'Available choices. When omitted for `enum` flags, the enum values\nfrom the flag schema are used automatically.',
|
|
146
|
+
"choices": {
|
|
147
|
+
description: "Available choices. When omitted for `enum` flags, the enum values\nfrom the flag schema are used automatically.",
|
|
164
148
|
},
|
|
165
|
-
min: {
|
|
166
|
-
description:
|
|
149
|
+
"min": {
|
|
150
|
+
description: "Minimum number of selections required.",
|
|
167
151
|
},
|
|
168
|
-
max: {
|
|
169
|
-
description:
|
|
152
|
+
"max": {
|
|
153
|
+
description: "Maximum number of selections allowed.",
|
|
170
154
|
},
|
|
171
155
|
},
|
|
172
156
|
},
|
|
173
|
-
choice: {
|
|
174
|
-
description:
|
|
175
|
-
'A selectable option for SelectPromptConfig and MultiselectPromptConfig prompts.',
|
|
157
|
+
"choice": {
|
|
158
|
+
description: "A selectable option for SelectPromptConfig and MultiselectPromptConfig prompts.",
|
|
176
159
|
properties: {
|
|
177
|
-
value: {
|
|
178
|
-
description:
|
|
160
|
+
"value": {
|
|
161
|
+
description: "The value returned when this choice is selected.",
|
|
179
162
|
},
|
|
180
|
-
label: {
|
|
181
|
-
description:
|
|
163
|
+
"label": {
|
|
164
|
+
description: "Display label shown to the user.",
|
|
182
165
|
},
|
|
183
|
-
description: {
|
|
184
|
-
description:
|
|
166
|
+
"description": {
|
|
167
|
+
description: "Optional description shown alongside the choice.",
|
|
185
168
|
},
|
|
186
169
|
},
|
|
187
170
|
},
|
|
188
|
-
example: {
|
|
189
|
-
description:
|
|
171
|
+
"example": {
|
|
172
|
+
description: "A single usage example shown in help text.",
|
|
190
173
|
properties: {
|
|
191
|
-
command: {
|
|
174
|
+
"command": {
|
|
192
175
|
description: "The command invocation (e.g. `'deploy production --force'`).",
|
|
193
176
|
},
|
|
194
|
-
description: {
|
|
195
|
-
description:
|
|
177
|
+
"description": {
|
|
178
|
+
description: "Optional description of what this example does.",
|
|
196
179
|
},
|
|
197
180
|
},
|
|
198
181
|
},
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
import { ValidationError } from '#internals/core/errors/index.ts';
|
|
9
9
|
import type { PromptEngine } from '#internals/core/prompt/index.ts';
|
|
10
10
|
import { resolvePromptConfig } from '#internals/core/prompt/index.ts';
|
|
11
|
-
import type { ErasedInteractiveResolver
|
|
12
|
-
import type {
|
|
11
|
+
import type { ErasedInteractiveResolver } from '#internals/core/schema/command.ts';
|
|
12
|
+
import type { FlagKind, FlagSchema } from '#internals/core/schema/flag.ts';
|
|
13
|
+
import type { PromptConfig, PromptKind } from '#internals/core/schema/prompt.ts';
|
|
13
14
|
import { coerceValue } from './coerce.ts';
|
|
14
15
|
import { resolveConfigPath } from './config.ts';
|
|
15
16
|
import type { DeprecationWarning } from './contracts.ts';
|
|
@@ -165,12 +166,60 @@ async function resolveFlags(
|
|
|
165
166
|
return resolved;
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
/** Maps each flag kind to the prompt kinds that produce compatible values. */
|
|
170
|
+
const COMPATIBLE_PROMPT_KINDS: Record<FlagKind, readonly PromptKind[]> = {
|
|
171
|
+
boolean: ['confirm'],
|
|
172
|
+
string: ['input', 'select'],
|
|
173
|
+
number: ['input'],
|
|
174
|
+
enum: ['select', 'input'],
|
|
175
|
+
array: ['multiselect'],
|
|
176
|
+
custom: ['input', 'select', 'confirm', 'multiselect'],
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Check whether a prompt kind is compatible with the flag's declared kind.
|
|
181
|
+
*
|
|
182
|
+
* @returns `undefined` when compatible, or a {@link ValidationError} with
|
|
183
|
+
* code `'CONSTRAINT_VIOLATED'` and an actionable `suggest` message when not.
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
function validatePromptFlagCompatibility(
|
|
187
|
+
flagName: string,
|
|
188
|
+
flagKind: FlagKind,
|
|
189
|
+
promptKind: PromptKind,
|
|
190
|
+
): ValidationError | undefined {
|
|
191
|
+
const allowed = COMPATIBLE_PROMPT_KINDS[flagKind];
|
|
192
|
+
if (allowed.includes(promptKind)) return undefined;
|
|
193
|
+
|
|
194
|
+
return new ValidationError(
|
|
195
|
+
`Prompt kind '${promptKind}' is not compatible with ${flagKind} flag --${flagName}. Use '${allowed[0]}' instead`,
|
|
196
|
+
{
|
|
197
|
+
code: 'CONSTRAINT_VIOLATED',
|
|
198
|
+
details: { flag: flagName, flagKind, promptKind, allowed },
|
|
199
|
+
suggest: `Change the prompt to { kind: '${allowed[0]}' } for --${flagName}`,
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Validate prompt/flag compatibility, run the prompt engine, and coerce the result.
|
|
206
|
+
*
|
|
207
|
+
* Returns early with a {@link ValidationError} if the prompt kind is
|
|
208
|
+
* incompatible with the flag kind (checked via {@link COMPATIBLE_PROMPT_KINDS}
|
|
209
|
+
* before the prompter is invoked).
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
168
212
|
async function resolvePromptValueWithConfig(
|
|
169
213
|
flagName: string,
|
|
170
214
|
schema: FlagSchema,
|
|
171
215
|
promptConfig: PromptConfig,
|
|
172
216
|
prompter: PromptEngine,
|
|
173
217
|
): Promise<PromptResolveResult> {
|
|
218
|
+
const mismatch = validatePromptFlagCompatibility(flagName, schema.kind, promptConfig.kind);
|
|
219
|
+
if (mismatch !== undefined) {
|
|
220
|
+
return { ok: false, error: mismatch };
|
|
221
|
+
}
|
|
222
|
+
|
|
174
223
|
const resolvedConfig = resolvePromptConfig(promptConfig, schema.enumValues);
|
|
175
224
|
const result = await prompter.promptOne(resolvedConfig);
|
|
176
225
|
|
|
@@ -181,6 +230,7 @@ async function resolvePromptValueWithConfig(
|
|
|
181
230
|
return coerceValue(flagName, { kind: 'prompt' }, result.value, schema);
|
|
182
231
|
}
|
|
183
232
|
|
|
233
|
+
/** Build a human-readable suggestion listing all available sources for a required flag. @internal */
|
|
184
234
|
function buildRequiredFlagSuggest(name: string, schema: FlagSchema): string {
|
|
185
235
|
const sources: string[] = [];
|
|
186
236
|
sources.push(`Provide --${name}${schema.kind !== 'boolean' ? ' <value>' : ''}`);
|
|
@@ -202,4 +252,4 @@ function buildRequiredFlagSuggest(name: string, schema: FlagSchema): string {
|
|
|
202
252
|
return sources.length === 2 ? `${rest.join('')} or ${last}` : `${rest.join(', ')}, or ${last}`;
|
|
203
253
|
}
|
|
204
254
|
|
|
205
|
-
export { resolveFlags };
|
|
255
|
+
export { COMPATIBLE_PROMPT_KINDS, resolveFlags };
|
package/src/core/schema/flag.ts
CHANGED
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
* @module dreamcli/core/schema/flag
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
ConfirmPromptConfig,
|
|
14
|
+
InputPromptConfig,
|
|
15
|
+
MultiselectPromptConfig,
|
|
16
|
+
PromptConfig,
|
|
17
|
+
SelectPromptConfig,
|
|
18
|
+
} from './prompt.ts';
|
|
13
19
|
|
|
14
20
|
// --- Type-level configuration (phantom state tracked through the chain)
|
|
15
21
|
|
|
@@ -48,6 +54,8 @@ interface FlagConfig {
|
|
|
48
54
|
readonly presence: FlagPresence;
|
|
49
55
|
/** What an unresolved optional flag becomes at the action boundary. */
|
|
50
56
|
readonly optionalFallback: OptionalFallback;
|
|
57
|
+
/** The runtime kind discriminator, mirroring {@link FlagKind}. */
|
|
58
|
+
readonly flagKind: FlagKind;
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
// --- Type-level helpers
|
|
@@ -60,6 +68,7 @@ type WithPresence<C extends FlagConfig, P extends FlagPresence> = {
|
|
|
60
68
|
readonly valueType: C['valueType'];
|
|
61
69
|
readonly presence: P;
|
|
62
70
|
readonly optionalFallback: C['optionalFallback'];
|
|
71
|
+
readonly flagKind: C['flagKind'];
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
/**
|
|
@@ -87,6 +96,29 @@ type InferFlags<T extends Record<string, FlagBuilder<FlagConfig>>> = {
|
|
|
87
96
|
[K in keyof T]: InferFlag<T[K]>;
|
|
88
97
|
};
|
|
89
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Maps a {@linkcode FlagConfig} to the prompt config types that are compatible
|
|
101
|
+
* with the flag's kind. Prevents compile-time mismatches such as
|
|
102
|
+
* `flag.enum([…]).prompt({ kind: 'multiselect' })`.
|
|
103
|
+
*
|
|
104
|
+
* - `'boolean'` → {@link ConfirmPromptConfig}
|
|
105
|
+
* - `'string'` → {@link InputPromptConfig} | {@link SelectPromptConfig}
|
|
106
|
+
* - `'number'` → {@link InputPromptConfig}
|
|
107
|
+
* - `'enum'` → {@link SelectPromptConfig} | {@link InputPromptConfig}
|
|
108
|
+
* - `'array'` → {@link MultiselectPromptConfig}
|
|
109
|
+
* - `'custom'` → all prompt kinds ({@link PromptConfig})
|
|
110
|
+
*/
|
|
111
|
+
type PromptConfigByFlagKind = {
|
|
112
|
+
readonly string: InputPromptConfig | SelectPromptConfig;
|
|
113
|
+
readonly number: InputPromptConfig;
|
|
114
|
+
readonly boolean: ConfirmPromptConfig;
|
|
115
|
+
readonly enum: SelectPromptConfig | InputPromptConfig;
|
|
116
|
+
readonly array: MultiselectPromptConfig;
|
|
117
|
+
readonly custom: PromptConfig;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
type AllowedPromptConfig<C extends FlagConfig> = PromptConfigByFlagKind[C['flagKind']];
|
|
121
|
+
|
|
90
122
|
// --- Runtime schema data
|
|
91
123
|
|
|
92
124
|
/** All flag kind discriminators as a runtime array. */
|
|
@@ -469,7 +501,7 @@ class FlagBuilder<C extends FlagConfig> {
|
|
|
469
501
|
* // $ mycli init --name foo → skips prompt, uses CLI value
|
|
470
502
|
* ```
|
|
471
503
|
*/
|
|
472
|
-
prompt(config:
|
|
504
|
+
prompt(config: AllowedPromptConfig<C>): FlagBuilder<C> {
|
|
473
505
|
return new FlagBuilder({
|
|
474
506
|
...this.schema,
|
|
475
507
|
prompt: config,
|
|
@@ -547,6 +579,7 @@ interface FlagFactory {
|
|
|
547
579
|
readonly valueType: string;
|
|
548
580
|
readonly presence: 'optional';
|
|
549
581
|
readonly optionalFallback: 'undefined';
|
|
582
|
+
readonly flagKind: 'string';
|
|
550
583
|
}>;
|
|
551
584
|
|
|
552
585
|
/**
|
|
@@ -558,6 +591,7 @@ interface FlagFactory {
|
|
|
558
591
|
readonly valueType: number;
|
|
559
592
|
readonly presence: 'optional';
|
|
560
593
|
readonly optionalFallback: 'undefined';
|
|
594
|
+
readonly flagKind: 'number';
|
|
561
595
|
}>;
|
|
562
596
|
|
|
563
597
|
/**
|
|
@@ -570,6 +604,7 @@ interface FlagFactory {
|
|
|
570
604
|
readonly valueType: boolean;
|
|
571
605
|
readonly presence: 'defaulted';
|
|
572
606
|
readonly optionalFallback: 'undefined';
|
|
607
|
+
readonly flagKind: 'boolean';
|
|
573
608
|
}>;
|
|
574
609
|
|
|
575
610
|
/**
|
|
@@ -593,6 +628,7 @@ interface FlagFactory {
|
|
|
593
628
|
readonly valueType: T[number];
|
|
594
629
|
readonly presence: 'optional';
|
|
595
630
|
readonly optionalFallback: 'undefined';
|
|
631
|
+
readonly flagKind: 'enum';
|
|
596
632
|
}>;
|
|
597
633
|
|
|
598
634
|
/**
|
|
@@ -613,6 +649,7 @@ interface FlagFactory {
|
|
|
613
649
|
readonly valueType: E['valueType'][];
|
|
614
650
|
readonly presence: 'optional';
|
|
615
651
|
readonly optionalFallback: 'empty-array';
|
|
652
|
+
readonly flagKind: 'array';
|
|
616
653
|
}>;
|
|
617
654
|
|
|
618
655
|
/**
|
|
@@ -648,6 +685,7 @@ interface FlagFactory {
|
|
|
648
685
|
readonly valueType: T;
|
|
649
686
|
readonly presence: 'optional';
|
|
650
687
|
readonly optionalFallback: 'undefined';
|
|
688
|
+
readonly flagKind: 'custom';
|
|
651
689
|
}>;
|
|
652
690
|
}
|
|
653
691
|
|
|
@@ -660,6 +698,7 @@ const flag: FlagFactory = {
|
|
|
660
698
|
readonly valueType: string;
|
|
661
699
|
readonly presence: 'optional';
|
|
662
700
|
readonly optionalFallback: 'undefined';
|
|
701
|
+
readonly flagKind: 'string';
|
|
663
702
|
}> {
|
|
664
703
|
return new FlagBuilder(createSchema('string'));
|
|
665
704
|
},
|
|
@@ -668,6 +707,7 @@ const flag: FlagFactory = {
|
|
|
668
707
|
readonly valueType: number;
|
|
669
708
|
readonly presence: 'optional';
|
|
670
709
|
readonly optionalFallback: 'undefined';
|
|
710
|
+
readonly flagKind: 'number';
|
|
671
711
|
}> {
|
|
672
712
|
return new FlagBuilder(createSchema('number'));
|
|
673
713
|
},
|
|
@@ -676,6 +716,7 @@ const flag: FlagFactory = {
|
|
|
676
716
|
readonly valueType: boolean;
|
|
677
717
|
readonly presence: 'defaulted';
|
|
678
718
|
readonly optionalFallback: 'undefined';
|
|
719
|
+
readonly flagKind: 'boolean';
|
|
679
720
|
}> {
|
|
680
721
|
return new FlagBuilder(
|
|
681
722
|
createSchema('boolean', {
|
|
@@ -691,6 +732,7 @@ const flag: FlagFactory = {
|
|
|
691
732
|
readonly valueType: T[number];
|
|
692
733
|
readonly presence: 'optional';
|
|
693
734
|
readonly optionalFallback: 'undefined';
|
|
735
|
+
readonly flagKind: 'enum';
|
|
694
736
|
}> {
|
|
695
737
|
return new FlagBuilder(createSchema('enum', { enumValues: values }));
|
|
696
738
|
},
|
|
@@ -701,6 +743,7 @@ const flag: FlagFactory = {
|
|
|
701
743
|
readonly valueType: E['valueType'][];
|
|
702
744
|
readonly presence: 'optional';
|
|
703
745
|
readonly optionalFallback: 'empty-array';
|
|
746
|
+
readonly flagKind: 'array';
|
|
704
747
|
}> {
|
|
705
748
|
return new FlagBuilder(createSchema('array', { elementSchema: element.schema }));
|
|
706
749
|
},
|
|
@@ -709,6 +752,7 @@ const flag: FlagFactory = {
|
|
|
709
752
|
readonly valueType: T;
|
|
710
753
|
readonly presence: 'optional';
|
|
711
754
|
readonly optionalFallback: 'undefined';
|
|
755
|
+
readonly flagKind: 'custom';
|
|
712
756
|
}> {
|
|
713
757
|
return new FlagBuilder(createSchema('custom', { parseFn: parseFn as FlagParseFn<unknown> }));
|
|
714
758
|
},
|
|
@@ -730,6 +774,7 @@ export type {
|
|
|
730
774
|
} from './prompt.ts';
|
|
731
775
|
export { PROMPT_KINDS } from './prompt.ts';
|
|
732
776
|
export type {
|
|
777
|
+
AllowedPromptConfig,
|
|
733
778
|
FlagAlias,
|
|
734
779
|
FlagConfig,
|
|
735
780
|
FlagFactory,
|
package/src/runtime/support.ts
CHANGED
|
@@ -43,8 +43,8 @@ const SUPPORTED_RUNTIMES: readonly RuntimeSupportEntry[] = [
|
|
|
43
43
|
{
|
|
44
44
|
runtime: 'bun',
|
|
45
45
|
displayName: 'Bun',
|
|
46
|
-
minimum: '1.3
|
|
47
|
-
engineRange: '>=1.3
|
|
46
|
+
minimum: '1.3',
|
|
47
|
+
engineRange: '>=1.3',
|
|
48
48
|
packageName: '@kjanat/dreamcli',
|
|
49
49
|
adapterName: 'BunAdapter',
|
|
50
50
|
},
|