@kjanat/dreamcli 3.0.1 → 4.0.0-rc.1
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 +951 -1
- package/README.md +7 -3
- package/dist/core/cli/builtins.d.mts +47 -0
- package/dist/core/cli/builtins.mjs +135 -0
- package/dist/core/cli/compiled.d.mts +29 -0
- package/dist/core/cli/compiled.mjs +76 -0
- package/dist/core/cli/dispatch.d.mts +9 -85
- package/dist/core/cli/help-links.d.mts +2 -14
- package/dist/core/cli/index.d.mts +282 -101
- package/dist/core/cli/index.mjs +497 -264
- package/dist/core/cli/planner.d.mts +13 -86
- package/dist/core/cli/planner.mjs +47 -30
- package/dist/core/cli/plugin.d.mts +1 -1
- package/dist/core/cli/propagate.mjs +1 -1
- package/dist/core/cli/reserved-flags.d.mts +1 -0
- package/dist/core/cli/reserved-flags.mjs +158 -0
- package/dist/core/cli/root-help.d.mts +1 -47
- package/dist/core/cli/root-help.mjs +37 -47
- package/dist/core/cli/root-output-flags.d.mts +1 -0
- package/dist/core/cli/root-output-flags.mjs +169 -0
- package/dist/core/cli/root-surface.d.mts +1 -68
- package/dist/core/cli/root-surface.mjs +2 -2
- package/dist/core/cli/runtime-preflight.d.mts +1 -199
- package/dist/core/cli/runtime-preflight.mjs +67 -17
- package/dist/core/completion/index.d.mts +2 -2
- package/dist/core/completion/shells/bash.d.mts +0 -1
- package/dist/core/completion/shells/bash.mjs +2 -1
- package/dist/core/completion/shells/fish.d.mts +0 -1
- package/dist/core/completion/shells/fish.mjs +2 -1
- package/dist/core/completion/shells/powershell.d.mts +0 -1
- package/dist/core/completion/shells/powershell.mjs +2 -1
- package/dist/core/completion/shells/shared.d.mts +3 -114
- package/dist/core/completion/shells/shared.mjs +9 -39
- package/dist/core/completion/shells/zsh.d.mts +0 -1
- package/dist/core/completion/shells/zsh.mjs +2 -1
- package/dist/core/config/index.d.mts +3 -3
- package/dist/core/config/index.mjs +2 -2
- package/dist/core/config/package-json.d.mts +2 -33
- package/dist/core/config/package-json.mjs +1 -34
- package/dist/core/errors/index.d.mts +7 -7
- package/dist/core/execution/index.d.mts +1 -48
- package/dist/core/execution/index.mjs +42 -27
- package/dist/core/help/ansi.d.mts +0 -11
- package/dist/core/help/index.d.mts +3 -35
- package/dist/core/help/index.mjs +29 -6
- package/dist/core/help/theme.d.mts +1 -21
- package/dist/core/json-schema/index.d.mts +279 -10
- package/dist/core/json-schema/index.mjs +482 -237
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +79 -7
- package/dist/core/json-schema/meta-descriptions.generated.mjs +40 -6
- package/dist/core/output/activity.d.mts +1 -193
- package/dist/core/output/activity.mjs +1 -1
- package/dist/core/output/bind.d.mts +1 -37
- package/dist/core/output/contracts.d.mts +7 -13
- package/dist/core/output/contracts.mjs +1 -1
- package/dist/core/output/display-value.d.mts +1 -19
- package/dist/core/output/index.d.mts +5 -187
- package/dist/core/output/index.mjs +44 -9
- package/dist/core/output/renderers.d.mts +1 -45
- package/dist/core/output/writer.d.mts +0 -1
- package/dist/core/parse/index.d.mts +27 -5
- package/dist/core/parse/index.mjs +350 -227
- package/dist/core/parse/occurrences.d.mts +89 -0
- package/dist/core/parse/occurrences.mjs +114 -0
- package/dist/core/prompt/index.d.mts +3 -3
- package/dist/core/read-flags/index.d.mts +150 -0
- package/dist/core/read-flags/index.mjs +217 -0
- package/dist/core/resolve/args.d.mts +35 -4
- package/dist/core/resolve/args.mjs +132 -55
- package/dist/core/resolve/coerce.d.mts +66 -9
- package/dist/core/resolve/coerce.mjs +834 -270
- package/dist/core/resolve/config.d.mts +1 -10
- package/dist/core/resolve/contracts.d.mts +67 -44
- package/dist/core/resolve/errors.mjs +29 -21
- package/dist/core/resolve/flags.d.mts +36 -9
- package/dist/core/resolve/flags.mjs +129 -151
- package/dist/core/resolve/index.d.mts +8 -6
- package/dist/core/resolve/index.mjs +51 -18
- package/dist/core/resolve/path-checks.d.mts +47 -0
- package/dist/core/resolve/path-checks.mjs +102 -0
- package/dist/core/resolve/redaction.d.mts +12 -0
- package/dist/core/resolve/redaction.mjs +14 -0
- package/dist/core/resolve/stages.d.mts +85 -0
- package/dist/core/resolve/stages.mjs +170 -0
- package/dist/core/resolve/standard.d.mts +1 -24
- package/dist/core/resolve/standard.mjs +141 -43
- package/dist/core/schema/activity.d.mts +16 -16
- package/dist/core/schema/arg.d.mts +849 -71
- package/dist/core/schema/arg.mjs +727 -54
- package/dist/core/schema/brand.d.mts +17 -0
- package/dist/core/schema/cardinality.d.mts +301 -0
- package/dist/core/schema/cardinality.mjs +514 -0
- package/dist/core/schema/command.d.mts +181 -112
- package/dist/core/schema/command.mjs +305 -42
- package/dist/core/schema/flag.d.mts +515 -173
- package/dist/core/schema/flag.mjs +576 -78
- package/dist/core/schema/index.d.mts +11 -8
- package/dist/core/schema/index.mjs +10 -0
- package/dist/core/schema/middleware.d.mts +15 -12
- package/dist/core/schema/number-constraints.d.mts +5 -5
- package/dist/core/schema/prompt.d.mts +4 -4
- package/dist/core/schema/provenance.d.mts +99 -0
- package/dist/core/schema/provenance.mjs +28 -0
- package/dist/core/schema/run.d.mts +21 -60
- package/dist/core/schema/source.d.mts +179 -0
- package/dist/core/schema/source.mjs +206 -0
- package/dist/core/schema/standard.d.mts +12 -19
- package/dist/core/schema/stdin.d.mts +87 -0
- package/dist/core/schema/stdin.mjs +91 -0
- package/dist/core/schema/string-constraints.d.mts +16 -5
- package/dist/core/schema/string-constraints.mjs +18 -1
- package/dist/core/schema/value-parsers.d.mts +81 -9
- package/dist/core/schema/value-parsers.mjs +19 -1
- package/dist/core/schema/value.d.mts +242 -0
- package/dist/core/schema/value.mjs +573 -0
- package/dist/core/testkit/index.d.mts +28 -3
- package/dist/core/testkit/index.mjs +40 -26
- package/dist/index.d.mts +21 -16
- package/dist/index.mjs +10 -6
- package/dist/runtime/adapter.d.mts +3 -3
- package/dist/runtime/deno.d.mts +3 -3
- package/dist/runtime/detect.d.mts +2 -2
- package/dist/runtime/node.d.mts +3 -3
- package/dist/runtime/paths.d.mts +1 -31
- package/dist/runtime.d.mts +4 -4
- package/dist/strings.d.mts +1 -16
- package/dist/testkit.d.mts +2 -2
- package/dist/testkit.mjs +1 -1
- package/dist/version.d.mts +0 -13
- package/dist/version.mjs +2 -2
- package/dreamcli.schema.json +368 -78
- package/examples/interactive.ts +6 -5
- package/package.json +9 -9
- package/skills/cli-creation/SKILL.md +72 -16
- package/skills/cli-creation/references/pattern-cookbook.md +169 -11
- package/dist/core/resolve/property.d.mts +0 -51
- package/dist/core/resolve/property.mjs +0 -53
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DUPLICATE_KEYS } from "../schema/cardinality.mjs";
|
|
1
2
|
import { getFlagAliasNames } from "../schema/flag.mjs";
|
|
2
3
|
import { resolveExampleCommand } from "../schema/command.mjs";
|
|
3
4
|
import { definitionMetaSchemaDescriptions } from "./meta-descriptions.generated.mjs";
|
|
@@ -17,23 +18,29 @@ function resolveOptions(options) {
|
|
|
17
18
|
/**
|
|
18
19
|
* `$schema` URL for definition documents.
|
|
19
20
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* Self-hosted. The `v1` segment is the definition format version, the value
|
|
22
|
+
* every document reports as `schemaVersion`, so it resolves for every package
|
|
23
|
+
* release that emits `schemaVersion: 1`. Two mirrors carry identical bytes:
|
|
24
|
+
* `./node_modules/@kjanat/dreamcli/dreamcli.schema.json` for offline or
|
|
25
|
+
* local-first workflows, and
|
|
26
|
+
* `https://cdn.jsdelivr.net/npm/@kjanat/dreamcli/dreamcli.schema.json` on the
|
|
27
|
+
* npm CDN.
|
|
23
28
|
*/
|
|
24
|
-
const DEFINITION_SCHEMA_URL = "https://
|
|
29
|
+
const DEFINITION_SCHEMA_URL = "https://dreamcli.kjanat.dev/schemas/definition/v1.schema.json";
|
|
25
30
|
/** Meta-schema URL for JSON Schema draft 2020-12 (input validation). */
|
|
26
31
|
const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
32
|
+
/**
|
|
33
|
+
* Version of the definition document format emitted by {@link generateSchema}
|
|
34
|
+
* and {@link generateCommandSchema}.
|
|
35
|
+
*/
|
|
36
|
+
const DEFINITION_SCHEMA_VERSION = 1;
|
|
30
37
|
/**
|
|
31
38
|
* Generate a definition metadata document describing the CLI's structure.
|
|
32
39
|
*
|
|
33
40
|
* Walks the full command tree and produces a plain JSON-serializable object
|
|
34
41
|
* representing all commands, subcommands, flags, args, and metadata.
|
|
35
|
-
* Non-serializable runtime values (parse functions,
|
|
36
|
-
*
|
|
42
|
+
* Non-serializable runtime values (parse functions, interactive resolvers)
|
|
43
|
+
* are omitted.
|
|
37
44
|
*
|
|
38
45
|
* @param schema - The CLI schema from `CLIBuilder.schema`.
|
|
39
46
|
* @param options - Generation options.
|
|
@@ -54,36 +61,43 @@ function generateSchema(schema, options, meta) {
|
|
|
54
61
|
name: schema.name,
|
|
55
62
|
version: schema.version
|
|
56
63
|
};
|
|
57
|
-
const
|
|
64
|
+
const defaultCommand = schema.defaultCommand !== void 0 && (opts.includeHidden || !schema.defaultCommand.hidden) ? serializeCommand(schema.defaultCommand, opts, resolvedMeta) : void 0;
|
|
65
|
+
return {
|
|
58
66
|
$schema: DEFINITION_SCHEMA_URL,
|
|
59
|
-
|
|
67
|
+
schemaVersion: 1,
|
|
68
|
+
name: schema.name,
|
|
69
|
+
...schema.version !== void 0 ? { version: schema.version } : {},
|
|
70
|
+
...schema.description !== void 0 ? { description: schema.description } : {},
|
|
71
|
+
...defaultCommand !== void 0 ? { defaultCommand } : {},
|
|
72
|
+
commands: schema.commands.filter((cmd) => opts.includeHidden || !cmd.hidden).map((cmd) => serializeCommand(cmd, opts, resolvedMeta))
|
|
60
73
|
};
|
|
61
|
-
if (schema.version !== void 0) result.version = schema.version;
|
|
62
|
-
if (schema.description !== void 0) result.description = schema.description;
|
|
63
|
-
if (schema.defaultCommand !== void 0 && (opts.includeHidden || !schema.defaultCommand.schema.hidden)) result.defaultCommand = serializeCommand(schema.defaultCommand.schema, opts, resolvedMeta);
|
|
64
|
-
result.commands = schema.commands.filter((cmd) => opts.includeHidden || !cmd.schema.hidden).map((cmd) => serializeCommand(cmd.schema, opts, resolvedMeta));
|
|
65
|
-
return result;
|
|
66
74
|
}
|
|
67
75
|
/**
|
|
68
76
|
* Generate the definition metadata document for a single command.
|
|
69
77
|
*
|
|
70
|
-
* The per-command counterpart of {@link generateSchema}:
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* embedding one command's definition into
|
|
78
|
+
* The per-command counterpart of {@link generateSchema}: one entry of its
|
|
79
|
+
* `commands` array (flags, args, subcommands, examples), plus the
|
|
80
|
+
* `schemaVersion` every standalone document carries. Powers `--help` in
|
|
81
|
+
* `--json` mode and is useful for embedding one command's definition into
|
|
82
|
+
* custom tooling.
|
|
74
83
|
*
|
|
75
84
|
* @param schema - The command schema to serialize.
|
|
76
85
|
* @param options - Generation options.
|
|
77
86
|
* @param meta - Program name/version for function-form examples; defaults to
|
|
78
87
|
* the command's own name with no version.
|
|
79
88
|
* @returns A plain object suitable for `JSON.stringify()`.
|
|
89
|
+
* @remarks Validate standalone output against
|
|
90
|
+
* `https://dreamcli.kjanat.dev/schemas/definition/v1.schema.json#/$defs/commandDocument`.
|
|
80
91
|
*/
|
|
81
92
|
function generateCommandSchema(schema, options, meta) {
|
|
82
93
|
const resolvedMeta = meta ?? {
|
|
83
94
|
name: schema.name,
|
|
84
95
|
version: void 0
|
|
85
96
|
};
|
|
86
|
-
return
|
|
97
|
+
return {
|
|
98
|
+
schemaVersion: 1,
|
|
99
|
+
...serializeCommand(schema, resolveOptions(options), resolvedMeta)
|
|
100
|
+
};
|
|
87
101
|
}
|
|
88
102
|
/**
|
|
89
103
|
* Serialize a single {@link CommandSchema} into a plain object.
|
|
@@ -93,17 +107,18 @@ function generateCommandSchema(schema, options, meta) {
|
|
|
93
107
|
* @returns JSON-serializable object representing the command.
|
|
94
108
|
*/
|
|
95
109
|
function serializeCommand(schema, opts, meta) {
|
|
96
|
-
const result = { name: schema.name };
|
|
97
|
-
if (schema.description !== void 0) result.description = schema.description;
|
|
98
|
-
if (schema.aliases.length > 0) result.aliases = [...schema.aliases];
|
|
99
|
-
if (schema.hidden) result.hidden = true;
|
|
100
|
-
if (schema.examples.length > 0) result.examples = schema.examples.map((example) => serializeExample(example, meta));
|
|
101
110
|
const flags = {};
|
|
102
111
|
for (const [name, flagDef] of Object.entries(schema.flags)) flags[name] = serializeFlag(flagDef, opts);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
return {
|
|
113
|
+
name: schema.name,
|
|
114
|
+
...schema.description !== void 0 ? { description: schema.description } : {},
|
|
115
|
+
...schema.aliases.length > 0 ? { aliases: [...schema.aliases] } : {},
|
|
116
|
+
...schema.hidden ? { hidden: true } : {},
|
|
117
|
+
...schema.examples.length > 0 ? { examples: schema.examples.map((example) => serializeExample(example, meta)) } : {},
|
|
118
|
+
flags,
|
|
119
|
+
args: schema.args.map((entry) => serializeArgEntry(entry, opts)),
|
|
120
|
+
commands: schema.commands.filter((cmd) => opts.includeHidden || !cmd.hidden).map((cmd) => serializeCommand(cmd, opts, meta))
|
|
121
|
+
};
|
|
107
122
|
}
|
|
108
123
|
/**
|
|
109
124
|
* Serialize a {@link FlagSchema} into a plain object.
|
|
@@ -113,67 +128,155 @@ function serializeCommand(schema, opts, meta) {
|
|
|
113
128
|
* @returns JSON-serializable object representing the flag.
|
|
114
129
|
*/
|
|
115
130
|
function serializeFlag(schema, opts) {
|
|
116
|
-
const
|
|
131
|
+
const visibleAliases = getFlagAliasNames(schema);
|
|
132
|
+
const stringConstraints = schema.stringConstraints;
|
|
133
|
+
const pathChecks = schema.pathChecks;
|
|
134
|
+
const negation = schema.negation;
|
|
135
|
+
return {
|
|
117
136
|
kind: schema.kind,
|
|
118
|
-
presence: schema.presence
|
|
137
|
+
presence: schema.presence,
|
|
138
|
+
...isJsonSerializable(schema.defaultValue) ? { defaultValue: schema.defaultValue } : {},
|
|
139
|
+
...visibleAliases.length > 0 ? { aliases: [...visibleAliases] } : {},
|
|
140
|
+
...schema.stdin !== void 0 ? { stdin: serializeStdin(schema.stdin) } : {},
|
|
141
|
+
...schema.envVar !== void 0 ? { envVar: schema.envVar } : {},
|
|
142
|
+
...schema.configPath !== void 0 ? { configPath: schema.configPath } : {},
|
|
143
|
+
...schema.description !== void 0 ? { description: schema.description } : {},
|
|
144
|
+
...schema.enumValues !== void 0 ? { enumValues: [...schema.enumValues] } : {},
|
|
145
|
+
...schema.numberConstraints !== void 0 ? { numberConstraints: { ...schema.numberConstraints } } : {},
|
|
146
|
+
...stringConstraints !== void 0 ? { stringConstraints: serializeStringConstraints(stringConstraints) } : {},
|
|
147
|
+
...schema.elementSchema !== void 0 ? { elementSchema: serializeFlag(schema.elementSchema, opts) } : {},
|
|
148
|
+
...schema.separator !== void 0 ? { separator: schema.separator } : {},
|
|
149
|
+
...schema.split !== void 0 ? { split: serializeSplit(schema.split) } : {},
|
|
150
|
+
...schema.duplicateKeys !== "last" ? { duplicateKeys: schema.duplicateKeys } : {},
|
|
151
|
+
...schema.unique ? { unique: true } : {},
|
|
152
|
+
...pathChecks !== void 0 ? { pathChecks: serializePathChecks(pathChecks) } : {},
|
|
153
|
+
...schema.valueHint !== void 0 ? { valueHint: schema.valueHint } : {},
|
|
154
|
+
...opts.includePrompts && schema.prompt !== void 0 ? { prompt: serializePrompt(schema.prompt) } : {},
|
|
155
|
+
...schema.deprecated !== void 0 ? { deprecated: schema.deprecated } : {},
|
|
156
|
+
...schema.propagate ? { propagate: true } : {},
|
|
157
|
+
...negation !== void 0 ? { negation: {
|
|
158
|
+
...negation.alias !== void 0 ? { alias: negation.alias } : {},
|
|
159
|
+
...negation.hidden ? { hidden: true } : {}
|
|
160
|
+
} } : {},
|
|
161
|
+
...schema.duplicates !== "last" ? { duplicates: schema.duplicates } : {}
|
|
119
162
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
...
|
|
131
|
-
|
|
132
|
-
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Serialize {@link StringConstraints} into a plain object.
|
|
166
|
+
*
|
|
167
|
+
* @param constraints - The string constraints to serialize.
|
|
168
|
+
* @returns JSON-serializable object with the pattern split into source and flags.
|
|
169
|
+
*/
|
|
170
|
+
function serializeStringConstraints(constraints) {
|
|
171
|
+
const pattern = constraints.pattern;
|
|
172
|
+
return {
|
|
173
|
+
...constraints.nonEmpty !== void 0 ? { nonEmpty: constraints.nonEmpty } : {},
|
|
174
|
+
...constraints.minLength !== void 0 ? { minLength: constraints.minLength } : {},
|
|
175
|
+
...constraints.maxLength !== void 0 ? { maxLength: constraints.maxLength } : {},
|
|
176
|
+
...pattern !== void 0 ? { pattern: {
|
|
177
|
+
source: pattern.source,
|
|
178
|
+
flags: pattern.flags
|
|
133
179
|
} } : {}
|
|
134
180
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Serialize {@link PathChecks} into a plain object.
|
|
184
|
+
*
|
|
185
|
+
* @param checks - The filesystem expectations to serialize.
|
|
186
|
+
* @returns JSON-serializable object omitting the defaults.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
function serializePathChecks(checks) {
|
|
190
|
+
return {
|
|
191
|
+
mustExist: checks.mustExist,
|
|
192
|
+
...checks.type !== void 0 ? { type: checks.type } : {},
|
|
193
|
+
...checks.create ? { create: true } : {}
|
|
142
194
|
};
|
|
143
|
-
if (schema.valueHint !== void 0) result.valueHint = schema.valueHint;
|
|
144
|
-
if (opts.includePrompts && schema.prompt !== void 0) result.prompt = serializePrompt(schema.prompt);
|
|
145
|
-
if (schema.deprecated !== void 0) result.deprecated = schema.deprecated;
|
|
146
|
-
if (schema.propagate) result.propagate = true;
|
|
147
|
-
if (schema.negation !== void 0) {
|
|
148
|
-
const negation = {};
|
|
149
|
-
if (schema.negation.alias !== void 0) negation.alias = schema.negation.alias;
|
|
150
|
-
if (schema.negation.hidden) negation.hidden = true;
|
|
151
|
-
result.negation = negation;
|
|
152
|
-
}
|
|
153
|
-
if (schema.duplicates !== "last") result.duplicates = schema.duplicates;
|
|
154
|
-
return result;
|
|
155
195
|
}
|
|
156
196
|
/**
|
|
157
197
|
* Serialize a {@link CommandArgEntry} into a plain object.
|
|
158
198
|
*
|
|
159
199
|
* @param entry - The positional arg entry (name + {@link ArgSchema}).
|
|
200
|
+
* @param opts - Resolved generation options (prompt inclusion).
|
|
160
201
|
* @returns JSON-serializable object representing the arg.
|
|
161
202
|
*/
|
|
162
|
-
function serializeArgEntry(entry) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
203
|
+
function serializeArgEntry(entry, opts) {
|
|
204
|
+
return {
|
|
205
|
+
name: entry.name,
|
|
206
|
+
...serializeArgValue(entry.schema, opts)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Serialize the value half of an {@link ArgSchema} into a plain object.
|
|
211
|
+
*
|
|
212
|
+
* @param schema - The arg schema to serialize.
|
|
213
|
+
* @param opts - Resolved generation options (prompt inclusion).
|
|
214
|
+
* @returns JSON-serializable object representing everything but the name.
|
|
215
|
+
*/
|
|
216
|
+
function serializeArgValue(schema, opts) {
|
|
217
|
+
const stringConstraints = schema.stringConstraints;
|
|
218
|
+
const pathChecks = schema.pathChecks;
|
|
219
|
+
return {
|
|
166
220
|
kind: schema.kind,
|
|
167
|
-
presence: schema.presence
|
|
221
|
+
presence: schema.presence,
|
|
222
|
+
...schema.variadic ? { variadic: true } : {},
|
|
223
|
+
...schema.stdin !== void 0 ? { stdin: serializeStdin(schema.stdin) } : {},
|
|
224
|
+
...isJsonSerializable(schema.defaultValue) ? { defaultValue: schema.defaultValue } : {},
|
|
225
|
+
...schema.description !== void 0 ? { description: schema.description } : {},
|
|
226
|
+
...schema.envVar !== void 0 ? { envVar: schema.envVar } : {},
|
|
227
|
+
...schema.configPath !== void 0 ? { configPath: schema.configPath } : {},
|
|
228
|
+
...schema.enumValues !== void 0 ? { enumValues: [...schema.enumValues] } : {},
|
|
229
|
+
...schema.elementSchema !== void 0 ? { elementSchema: serializeArgElementValue(schema.elementSchema) } : {},
|
|
230
|
+
...schema.numberConstraints !== void 0 ? { numberConstraints: { ...schema.numberConstraints } } : {},
|
|
231
|
+
...stringConstraints !== void 0 ? { stringConstraints: serializeStringConstraints(stringConstraints) } : {},
|
|
232
|
+
...pathChecks !== void 0 ? { pathChecks: serializePathChecks(pathChecks) } : {},
|
|
233
|
+
...schema.valueHint !== void 0 ? { valueHint: schema.valueHint } : {},
|
|
234
|
+
...schema.separator !== void 0 ? { separator: schema.separator } : {},
|
|
235
|
+
...schema.split !== void 0 ? { split: serializeSplit(schema.split) } : {},
|
|
236
|
+
...schema.duplicateKeys !== "last" ? { duplicateKeys: schema.duplicateKeys } : {},
|
|
237
|
+
...schema.unique ? { unique: true } : {},
|
|
238
|
+
...opts.includePrompts && schema.prompt !== void 0 ? { prompt: serializePrompt(schema.prompt) } : {},
|
|
239
|
+
...schema.deprecated !== void 0 ? { deprecated: schema.deprecated } : {}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** Serialize only the value-axis fields an entry element supports. */
|
|
243
|
+
function serializeArgElementValue(schema) {
|
|
244
|
+
if (schema.kind === "keyValue") throw new TypeError("Arg element schema kind 'keyValue' is not supported");
|
|
245
|
+
return {
|
|
246
|
+
kind: schema.kind,
|
|
247
|
+
presence: "required",
|
|
248
|
+
...schema.enumValues !== void 0 ? { enumValues: [...schema.enumValues] } : {},
|
|
249
|
+
...schema.numberConstraints !== void 0 ? { numberConstraints: { ...schema.numberConstraints } } : {},
|
|
250
|
+
...schema.stringConstraints !== void 0 ? { stringConstraints: serializeStringConstraints(schema.stringConstraints) } : {},
|
|
251
|
+
...schema.pathChecks !== void 0 ? { pathChecks: serializePathChecks(schema.pathChecks) } : {},
|
|
252
|
+
...schema.valueHint !== void 0 ? { valueHint: schema.valueHint } : {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Serialize the non-CLI split policies of a collection.
|
|
257
|
+
*
|
|
258
|
+
* @param split - The stored split binding.
|
|
259
|
+
* @returns JSON-serializable object naming only the sources it sets.
|
|
260
|
+
*/
|
|
261
|
+
function serializeSplit(split) {
|
|
262
|
+
return {
|
|
263
|
+
...split.env !== void 0 ? { env: { ...split.env } } : {},
|
|
264
|
+
...split.stdin !== void 0 ? { stdin: { ...split.stdin } } : {}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Serialize a {@link StdinBinding} into a plain object.
|
|
269
|
+
*
|
|
270
|
+
* @param stdin - The stdin axis to serialize.
|
|
271
|
+
* @returns JSON-serializable object naming the trigger, the sharing mode, and
|
|
272
|
+
* the trimming.
|
|
273
|
+
*/
|
|
274
|
+
function serializeStdin(stdin) {
|
|
275
|
+
return {
|
|
276
|
+
when: stdin.when,
|
|
277
|
+
consume: stdin.consume,
|
|
278
|
+
trim: stdin.trim
|
|
168
279
|
};
|
|
169
|
-
if (schema.variadic) result.variadic = true;
|
|
170
|
-
if (schema.stdinMode) result.stdinMode = true;
|
|
171
|
-
if (schema.presence === "defaulted" && isJsonSerializable(schema.defaultValue)) result.defaultValue = schema.defaultValue;
|
|
172
|
-
if (schema.description !== void 0) result.description = schema.description;
|
|
173
|
-
if (schema.envVar !== void 0) result.envVar = schema.envVar;
|
|
174
|
-
if (schema.enumValues !== void 0) result.enumValues = [...schema.enumValues];
|
|
175
|
-
if (schema.deprecated !== void 0) result.deprecated = schema.deprecated;
|
|
176
|
-
return result;
|
|
177
280
|
}
|
|
178
281
|
/**
|
|
179
282
|
* Serialize a {@link PromptConfig} into a plain object.
|
|
@@ -182,25 +285,29 @@ function serializeArgEntry(entry) {
|
|
|
182
285
|
* @returns JSON-serializable object representing the prompt.
|
|
183
286
|
*/
|
|
184
287
|
function serializePrompt(prompt) {
|
|
185
|
-
const result = {
|
|
186
|
-
kind: prompt.kind,
|
|
187
|
-
message: prompt.message
|
|
188
|
-
};
|
|
189
288
|
switch (prompt.kind) {
|
|
190
|
-
case "input":
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
289
|
+
case "input": return {
|
|
290
|
+
kind: prompt.kind,
|
|
291
|
+
message: prompt.message,
|
|
292
|
+
...prompt.placeholder !== void 0 ? { placeholder: prompt.placeholder } : {}
|
|
293
|
+
};
|
|
294
|
+
case "select": return {
|
|
295
|
+
kind: prompt.kind,
|
|
296
|
+
message: prompt.message,
|
|
297
|
+
...prompt.choices !== void 0 ? { choices: prompt.choices.map(serializeChoice) } : {}
|
|
298
|
+
};
|
|
299
|
+
case "multiselect": return {
|
|
300
|
+
kind: prompt.kind,
|
|
301
|
+
message: prompt.message,
|
|
302
|
+
...prompt.choices !== void 0 ? { choices: prompt.choices.map(serializeChoice) } : {},
|
|
303
|
+
...prompt.min !== void 0 ? { min: prompt.min } : {},
|
|
304
|
+
...prompt.max !== void 0 ? { max: prompt.max } : {}
|
|
305
|
+
};
|
|
306
|
+
case "confirm": return {
|
|
307
|
+
kind: prompt.kind,
|
|
308
|
+
message: prompt.message
|
|
309
|
+
};
|
|
202
310
|
}
|
|
203
|
-
return result;
|
|
204
311
|
}
|
|
205
312
|
/**
|
|
206
313
|
* Serialize a {@link SelectChoice} into a plain object.
|
|
@@ -209,10 +316,11 @@ function serializePrompt(prompt) {
|
|
|
209
316
|
* @returns JSON-serializable object with value, optional label and description.
|
|
210
317
|
*/
|
|
211
318
|
function serializeChoice(choice) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
319
|
+
return {
|
|
320
|
+
value: choice.value,
|
|
321
|
+
...choice.label !== void 0 ? { label: choice.label } : {},
|
|
322
|
+
...choice.description !== void 0 ? { description: choice.description } : {}
|
|
323
|
+
};
|
|
216
324
|
}
|
|
217
325
|
/**
|
|
218
326
|
* Serialize a {@link CommandExample} into a plain object.
|
|
@@ -225,9 +333,10 @@ function serializeChoice(choice) {
|
|
|
225
333
|
* @returns JSON-serializable object with command and optional description.
|
|
226
334
|
*/
|
|
227
335
|
function serializeExample(example, meta) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
336
|
+
return {
|
|
337
|
+
command: resolveExampleCommand(example.command, meta),
|
|
338
|
+
...example.description !== void 0 ? { description: example.description } : {}
|
|
339
|
+
};
|
|
231
340
|
}
|
|
232
341
|
/**
|
|
233
342
|
* Generate a JSON Schema (draft 2020-12) for validating CLI input as JSON.
|
|
@@ -264,19 +373,19 @@ function generateInputSchema(schema, options) {
|
|
|
264
373
|
...commandToInputSchema(schema)
|
|
265
374
|
};
|
|
266
375
|
const branches = [];
|
|
376
|
+
if (schema.defaultCommand !== void 0 && (opts.includeHidden || !schema.defaultCommand.hidden)) collectInputBranches(schema.defaultCommand, "", branches, opts);
|
|
267
377
|
for (const cmd of schema.commands) {
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (branches.length === 1) {
|
|
272
|
-
const branch = stripCommandDiscriminator(branches[0] ?? {});
|
|
273
|
-
return {
|
|
274
|
-
$schema: JSON_SCHEMA_DRAFT,
|
|
275
|
-
...branch
|
|
276
|
-
};
|
|
378
|
+
if (cmd === schema.defaultCommand || cmd.name === schema.defaultCommand?.name) continue;
|
|
379
|
+
if (!opts.includeHidden && cmd.hidden) continue;
|
|
380
|
+
collectInputBranches(cmd, "", branches, opts);
|
|
277
381
|
}
|
|
382
|
+
const [onlyBranch] = branches;
|
|
383
|
+
if (branches.length === 1 && onlyBranch !== void 0) return {
|
|
384
|
+
$schema: JSON_SCHEMA_DRAFT,
|
|
385
|
+
...stripCommandDiscriminator(onlyBranch)
|
|
386
|
+
};
|
|
278
387
|
if (branches.length > 0) {
|
|
279
|
-
const defaultBranchName = schema.defaultCommand !== void 0 && (opts.includeHidden || !schema.defaultCommand.
|
|
388
|
+
const defaultBranchName = schema.defaultCommand !== void 0 && (opts.includeHidden || !schema.defaultCommand.hidden) ? schema.defaultCommand.name : void 0;
|
|
280
389
|
const normalizedBranches = defaultBranchName !== void 0 ? branches.map((branch) => getBranchCommandDiscriminator(branch) === defaultBranchName ? stripCommandDiscriminator(branch) : branch) : branches;
|
|
281
390
|
return {
|
|
282
391
|
$schema: JSON_SCHEMA_DRAFT,
|
|
@@ -292,11 +401,11 @@ function generateInputSchema(schema, options) {
|
|
|
292
401
|
* Discriminate between CLISchema and CommandSchema at runtime.
|
|
293
402
|
*
|
|
294
403
|
* Use a command-only field combination rather than a single shape check:
|
|
295
|
-
* command schemas always carry flags, args,
|
|
296
|
-
*
|
|
404
|
+
* command schemas always carry flags, args, and hasAction, while the CLI root
|
|
405
|
+
* schema does not expose that execution surface.
|
|
297
406
|
*/
|
|
298
407
|
function isCommandSchema(schema) {
|
|
299
|
-
return "flags" in schema && "args" in schema && "
|
|
408
|
+
return "flags" in schema && "args" in schema && "hasAction" in schema;
|
|
300
409
|
}
|
|
301
410
|
/** Recursively collect input schema branches for all invocable commands. */
|
|
302
411
|
function collectInputBranches(schema, prefix, branches, opts) {
|
|
@@ -328,46 +437,46 @@ function commandToInputSchema(schema, commandPath) {
|
|
|
328
437
|
properties[entry.name] = argToJsonSchemaType(entry.schema);
|
|
329
438
|
if (entry.schema.presence === "required") required.push(entry.name);
|
|
330
439
|
}
|
|
331
|
-
|
|
440
|
+
return {
|
|
332
441
|
type: "object",
|
|
333
442
|
properties,
|
|
334
|
-
additionalProperties: false
|
|
443
|
+
additionalProperties: false,
|
|
444
|
+
...required.length > 0 ? { required } : {}
|
|
335
445
|
};
|
|
336
|
-
if (required.length > 0) result.required = required;
|
|
337
|
-
return result;
|
|
338
446
|
}
|
|
339
447
|
/** @internal */
|
|
340
448
|
function stripCommandDiscriminator(branch) {
|
|
341
|
-
const
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (cleanedRequired !== void 0 && cleanedRequired.length > 0) result.required = cleanedRequired;
|
|
350
|
-
else delete result.required;
|
|
351
|
-
return result;
|
|
449
|
+
const { command: _discriminator, ...properties } = branch.properties;
|
|
450
|
+
const required = branch.required?.filter((value) => value !== "command");
|
|
451
|
+
return {
|
|
452
|
+
type: branch.type,
|
|
453
|
+
properties,
|
|
454
|
+
additionalProperties: branch.additionalProperties,
|
|
455
|
+
...required !== void 0 && required.length > 0 ? { required } : {}
|
|
456
|
+
};
|
|
352
457
|
}
|
|
353
458
|
function getBranchCommandDiscriminator(branch) {
|
|
354
|
-
const
|
|
355
|
-
if (
|
|
356
|
-
const
|
|
357
|
-
return
|
|
459
|
+
const commandValue = branch.properties.command;
|
|
460
|
+
if (commandValue === void 0) return;
|
|
461
|
+
const constValue = commandValue.const;
|
|
462
|
+
return typeof constValue === "string" ? constValue : void 0;
|
|
463
|
+
}
|
|
464
|
+
/** Map shared string constraints to JSON Schema properties. @internal */
|
|
465
|
+
function stringConstraintsToJsonSchemaProperties(constraints) {
|
|
466
|
+
const result = {};
|
|
467
|
+
const minLength = constraints?.nonEmpty === true ? Math.max(constraints.minLength ?? 1, 1) : constraints?.minLength;
|
|
468
|
+
if (minLength !== void 0) result.minLength = minLength;
|
|
469
|
+
if (constraints?.maxLength !== void 0) result.maxLength = constraints.maxLength;
|
|
470
|
+
if (constraints?.pattern !== void 0) result.pattern = constraints.pattern.source;
|
|
471
|
+
return result;
|
|
358
472
|
}
|
|
359
473
|
function flagToJsonSchemaType(schema) {
|
|
360
474
|
const result = {};
|
|
361
475
|
switch (schema.kind) {
|
|
362
|
-
case "string":
|
|
476
|
+
case "string":
|
|
363
477
|
result.type = "string";
|
|
364
|
-
|
|
365
|
-
const minLength = constraints?.nonEmpty === true ? Math.max(constraints.minLength ?? 1, 1) : constraints?.minLength;
|
|
366
|
-
if (minLength !== void 0) result.minLength = minLength;
|
|
367
|
-
if (constraints?.maxLength !== void 0) result.maxLength = constraints.maxLength;
|
|
368
|
-
if (constraints?.pattern !== void 0) result.pattern = constraints.pattern.source;
|
|
478
|
+
Object.assign(result, stringConstraintsToJsonSchemaProperties(schema.stringConstraints));
|
|
369
479
|
break;
|
|
370
|
-
}
|
|
371
480
|
case "number": {
|
|
372
481
|
const constraints = schema.numberConstraints;
|
|
373
482
|
result.type = constraints?.int === true ? "integer" : "number";
|
|
@@ -393,29 +502,31 @@ function flagToJsonSchemaType(schema) {
|
|
|
393
502
|
break;
|
|
394
503
|
case "keyValue":
|
|
395
504
|
result.type = "object";
|
|
396
|
-
result.additionalProperties = { type: "string" };
|
|
397
|
-
break;
|
|
505
|
+
result.additionalProperties = schema.elementSchema === void 0 ? { type: "string" } : flagToJsonSchemaType(schema.elementSchema);
|
|
398
506
|
}
|
|
399
507
|
if (schema.description !== void 0) result.description = schema.description;
|
|
400
|
-
if (
|
|
508
|
+
if (isJsonSerializable(schema.defaultValue)) result.default = schema.defaultValue;
|
|
401
509
|
if (schema.deprecated !== void 0) result.deprecated = schema.deprecated;
|
|
402
510
|
return result;
|
|
403
511
|
}
|
|
404
512
|
function argToJsonSchemaType(schema) {
|
|
405
513
|
const kind = argKindToType(schema);
|
|
406
|
-
const result = schema.variadic ? {
|
|
514
|
+
const result = schema.variadic && schema.kind !== "keyValue" ? {
|
|
407
515
|
type: "array",
|
|
408
516
|
items: kind
|
|
409
517
|
} : { ...kind };
|
|
410
518
|
if (schema.description !== void 0) result.description = schema.description;
|
|
411
|
-
if (
|
|
519
|
+
if (isJsonSerializable(schema.defaultValue)) result.default = schema.defaultValue;
|
|
412
520
|
if (schema.deprecated !== void 0) result.deprecated = schema.deprecated;
|
|
413
521
|
return result;
|
|
414
522
|
}
|
|
415
523
|
/** Map an arg's kind to a JSON Schema type fragment. */
|
|
416
524
|
function argKindToType(schema) {
|
|
417
525
|
switch (schema.kind) {
|
|
418
|
-
case "string": return {
|
|
526
|
+
case "string": return {
|
|
527
|
+
type: "string",
|
|
528
|
+
...stringConstraintsToJsonSchemaProperties(schema.stringConstraints)
|
|
529
|
+
};
|
|
419
530
|
case "number": {
|
|
420
531
|
const constraints = schema.numberConstraints;
|
|
421
532
|
const result = { type: constraints?.int === true ? "integer" : "number" };
|
|
@@ -428,6 +539,11 @@ function argKindToType(schema) {
|
|
|
428
539
|
if (schema.enumValues !== void 0) result.enum = [...schema.enumValues];
|
|
429
540
|
return result;
|
|
430
541
|
}
|
|
542
|
+
case "boolean": return { type: "boolean" };
|
|
543
|
+
case "keyValue": return {
|
|
544
|
+
type: "object",
|
|
545
|
+
additionalProperties: schema.elementSchema === void 0 ? { type: "string" } : argKindToType(schema.elementSchema)
|
|
546
|
+
};
|
|
431
547
|
case "custom": return {};
|
|
432
548
|
}
|
|
433
549
|
}
|
|
@@ -506,6 +622,96 @@ function withDefinitionMetaSchemaDescriptions(schema, descriptions) {
|
|
|
506
622
|
};
|
|
507
623
|
}
|
|
508
624
|
/**
|
|
625
|
+
* Command-fragment property schemas shared by the nested `command` def and
|
|
626
|
+
* the standalone `commandDocument` def, so the two cannot drift.
|
|
627
|
+
*/
|
|
628
|
+
const commandFragmentProperties = {
|
|
629
|
+
name: { type: "string" },
|
|
630
|
+
description: { type: "string" },
|
|
631
|
+
aliases: {
|
|
632
|
+
type: "array",
|
|
633
|
+
items: { type: "string" }
|
|
634
|
+
},
|
|
635
|
+
hidden: { const: true },
|
|
636
|
+
examples: {
|
|
637
|
+
type: "array",
|
|
638
|
+
items: { $ref: "#/$defs/example" }
|
|
639
|
+
},
|
|
640
|
+
flags: {
|
|
641
|
+
type: "object",
|
|
642
|
+
additionalProperties: { $ref: "#/$defs/flag" }
|
|
643
|
+
},
|
|
644
|
+
args: {
|
|
645
|
+
type: "array",
|
|
646
|
+
items: { $ref: "#/$defs/arg" }
|
|
647
|
+
},
|
|
648
|
+
commands: {
|
|
649
|
+
type: "array",
|
|
650
|
+
items: { $ref: "#/$defs/command" }
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
/**
|
|
654
|
+
* Property schemas carried by a named positional definition.
|
|
655
|
+
*/
|
|
656
|
+
const argValueFragmentProperties = {
|
|
657
|
+
kind: { enum: [
|
|
658
|
+
"string",
|
|
659
|
+
"number",
|
|
660
|
+
"boolean",
|
|
661
|
+
"enum",
|
|
662
|
+
"custom",
|
|
663
|
+
"keyValue"
|
|
664
|
+
] },
|
|
665
|
+
presence: { enum: [
|
|
666
|
+
"required",
|
|
667
|
+
"optional",
|
|
668
|
+
"defaulted"
|
|
669
|
+
] },
|
|
670
|
+
variadic: { const: true },
|
|
671
|
+
stdin: { $ref: "#/$defs/stdin" },
|
|
672
|
+
defaultValue: {},
|
|
673
|
+
description: { type: "string" },
|
|
674
|
+
envVar: { type: "string" },
|
|
675
|
+
configPath: { type: "string" },
|
|
676
|
+
enumValues: {
|
|
677
|
+
type: "array",
|
|
678
|
+
items: { type: "string" }
|
|
679
|
+
},
|
|
680
|
+
elementSchema: { $ref: "#/$defs/argElement" },
|
|
681
|
+
numberConstraints: { $ref: "#/$defs/numberConstraints" },
|
|
682
|
+
stringConstraints: { $ref: "#/$defs/stringConstraints" },
|
|
683
|
+
pathChecks: { $ref: "#/$defs/pathChecks" },
|
|
684
|
+
valueHint: { type: "string" },
|
|
685
|
+
separator: {
|
|
686
|
+
type: "string",
|
|
687
|
+
minLength: 1
|
|
688
|
+
},
|
|
689
|
+
split: { $ref: "#/$defs/split" },
|
|
690
|
+
duplicateKeys: { enum: [...DUPLICATE_KEYS] },
|
|
691
|
+
unique: { const: true },
|
|
692
|
+
prompt: { $ref: "#/$defs/prompt" },
|
|
693
|
+
deprecated: { oneOf: [{ type: "string" }, { const: true }] }
|
|
694
|
+
};
|
|
695
|
+
/** Property schemas supported by a key-value entry element. */
|
|
696
|
+
const argElementFragmentProperties = {
|
|
697
|
+
kind: { enum: [
|
|
698
|
+
"string",
|
|
699
|
+
"number",
|
|
700
|
+
"boolean",
|
|
701
|
+
"enum",
|
|
702
|
+
"custom"
|
|
703
|
+
] },
|
|
704
|
+
presence: { const: "required" },
|
|
705
|
+
enumValues: {
|
|
706
|
+
type: "array",
|
|
707
|
+
items: { type: "string" }
|
|
708
|
+
},
|
|
709
|
+
numberConstraints: { $ref: "#/$defs/numberConstraints" },
|
|
710
|
+
stringConstraints: { $ref: "#/$defs/stringConstraints" },
|
|
711
|
+
pathChecks: { $ref: "#/$defs/pathChecks" },
|
|
712
|
+
valueHint: { type: "string" }
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
509
715
|
* JSON Schema (draft 2020-12) that validates the output of {@link generateSchema}.
|
|
510
716
|
*
|
|
511
717
|
* Hosted at {@link DEFINITION_SCHEMA_URL} for `$schema` resolution. Also
|
|
@@ -531,6 +737,7 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
531
737
|
additionalProperties: false,
|
|
532
738
|
properties: {
|
|
533
739
|
$schema: { const: DEFINITION_SCHEMA_URL },
|
|
740
|
+
schemaVersion: { const: 1 },
|
|
534
741
|
name: { type: "string" },
|
|
535
742
|
version: { type: "string" },
|
|
536
743
|
description: { type: "string" },
|
|
@@ -542,39 +749,31 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
542
749
|
},
|
|
543
750
|
required: [
|
|
544
751
|
"$schema",
|
|
752
|
+
"schemaVersion",
|
|
545
753
|
"name",
|
|
546
754
|
"commands"
|
|
547
755
|
],
|
|
548
756
|
$defs: {
|
|
549
757
|
command: {
|
|
758
|
+
type: "object",
|
|
759
|
+
additionalProperties: false,
|
|
760
|
+
properties: commandFragmentProperties,
|
|
761
|
+
required: [
|
|
762
|
+
"name",
|
|
763
|
+
"flags",
|
|
764
|
+
"args",
|
|
765
|
+
"commands"
|
|
766
|
+
]
|
|
767
|
+
},
|
|
768
|
+
commandDocument: {
|
|
550
769
|
type: "object",
|
|
551
770
|
additionalProperties: false,
|
|
552
771
|
properties: {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
aliases: {
|
|
556
|
-
type: "array",
|
|
557
|
-
items: { type: "string" }
|
|
558
|
-
},
|
|
559
|
-
hidden: { const: true },
|
|
560
|
-
examples: {
|
|
561
|
-
type: "array",
|
|
562
|
-
items: { $ref: "#/$defs/example" }
|
|
563
|
-
},
|
|
564
|
-
flags: {
|
|
565
|
-
type: "object",
|
|
566
|
-
additionalProperties: { $ref: "#/$defs/flag" }
|
|
567
|
-
},
|
|
568
|
-
args: {
|
|
569
|
-
type: "array",
|
|
570
|
-
items: { $ref: "#/$defs/arg" }
|
|
571
|
-
},
|
|
572
|
-
commands: {
|
|
573
|
-
type: "array",
|
|
574
|
-
items: { $ref: "#/$defs/command" }
|
|
575
|
-
}
|
|
772
|
+
schemaVersion: { const: 1 },
|
|
773
|
+
...commandFragmentProperties
|
|
576
774
|
},
|
|
577
775
|
required: [
|
|
776
|
+
"schemaVersion",
|
|
578
777
|
"name",
|
|
579
778
|
"flags",
|
|
580
779
|
"args",
|
|
@@ -605,6 +804,7 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
605
804
|
type: "array",
|
|
606
805
|
items: { type: "string" }
|
|
607
806
|
},
|
|
807
|
+
stdin: { $ref: "#/$defs/stdin" },
|
|
608
808
|
envVar: { type: "string" },
|
|
609
809
|
configPath: { type: "string" },
|
|
610
810
|
description: { type: "string" },
|
|
@@ -612,56 +812,17 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
612
812
|
type: "array",
|
|
613
813
|
items: { type: "string" }
|
|
614
814
|
},
|
|
615
|
-
numberConstraints: {
|
|
616
|
-
|
|
617
|
-
additionalProperties: false,
|
|
618
|
-
properties: {
|
|
619
|
-
min: { type: "number" },
|
|
620
|
-
max: { type: "number" },
|
|
621
|
-
int: { type: "boolean" },
|
|
622
|
-
finite: { type: "boolean" }
|
|
623
|
-
}
|
|
624
|
-
},
|
|
625
|
-
stringConstraints: {
|
|
626
|
-
type: "object",
|
|
627
|
-
additionalProperties: false,
|
|
628
|
-
properties: {
|
|
629
|
-
nonEmpty: { type: "boolean" },
|
|
630
|
-
minLength: {
|
|
631
|
-
type: "integer",
|
|
632
|
-
minimum: 0
|
|
633
|
-
},
|
|
634
|
-
maxLength: {
|
|
635
|
-
type: "integer",
|
|
636
|
-
minimum: 0
|
|
637
|
-
},
|
|
638
|
-
pattern: {
|
|
639
|
-
type: "object",
|
|
640
|
-
additionalProperties: false,
|
|
641
|
-
properties: {
|
|
642
|
-
source: { type: "string" },
|
|
643
|
-
flags: { type: "string" }
|
|
644
|
-
},
|
|
645
|
-
required: ["source", "flags"]
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
},
|
|
815
|
+
numberConstraints: { $ref: "#/$defs/numberConstraints" },
|
|
816
|
+
stringConstraints: { $ref: "#/$defs/stringConstraints" },
|
|
649
817
|
elementSchema: { $ref: "#/$defs/flag" },
|
|
650
818
|
separator: {
|
|
651
819
|
type: "string",
|
|
652
820
|
minLength: 1
|
|
653
821
|
},
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
properties: {
|
|
659
|
-
mustExist: { type: "boolean" },
|
|
660
|
-
type: { enum: ["file", "directory"] },
|
|
661
|
-
create: { type: "boolean" }
|
|
662
|
-
},
|
|
663
|
-
required: ["mustExist"]
|
|
664
|
-
},
|
|
822
|
+
split: { $ref: "#/$defs/split" },
|
|
823
|
+
duplicateKeys: { enum: [...DUPLICATE_KEYS] },
|
|
824
|
+
unique: { const: true },
|
|
825
|
+
pathChecks: { $ref: "#/$defs/pathChecks" },
|
|
665
826
|
valueHint: { type: "string" },
|
|
666
827
|
prompt: { $ref: "#/$defs/prompt" },
|
|
667
828
|
deprecated: { oneOf: [{ type: "string" }, { const: true }] },
|
|
@@ -675,6 +836,56 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
675
836
|
},
|
|
676
837
|
required: ["kind", "presence"]
|
|
677
838
|
},
|
|
839
|
+
stdin: {
|
|
840
|
+
type: "object",
|
|
841
|
+
additionalProperties: false,
|
|
842
|
+
properties: {
|
|
843
|
+
when: { enum: [
|
|
844
|
+
"dash",
|
|
845
|
+
"missing",
|
|
846
|
+
"dash-or-missing"
|
|
847
|
+
] },
|
|
848
|
+
consume: { enum: ["exclusive", "broadcast"] },
|
|
849
|
+
trim: { type: "boolean" }
|
|
850
|
+
},
|
|
851
|
+
required: ["when", "consume"]
|
|
852
|
+
},
|
|
853
|
+
split: {
|
|
854
|
+
type: "object",
|
|
855
|
+
additionalProperties: false,
|
|
856
|
+
properties: {
|
|
857
|
+
env: { $ref: "#/$defs/splitPolicy" },
|
|
858
|
+
stdin: { $ref: "#/$defs/splitPolicy" }
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
splitPolicy: {
|
|
862
|
+
type: "object",
|
|
863
|
+
additionalProperties: false,
|
|
864
|
+
properties: {
|
|
865
|
+
format: { enum: [
|
|
866
|
+
"whole",
|
|
867
|
+
"delimiter",
|
|
868
|
+
"lines",
|
|
869
|
+
"json"
|
|
870
|
+
] },
|
|
871
|
+
delimiter: {
|
|
872
|
+
type: "string",
|
|
873
|
+
minLength: 1
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
required: ["format"],
|
|
877
|
+
oneOf: [{
|
|
878
|
+
properties: { format: { const: "delimiter" } },
|
|
879
|
+
required: ["format", "delimiter"]
|
|
880
|
+
}, {
|
|
881
|
+
properties: { format: { enum: [
|
|
882
|
+
"whole",
|
|
883
|
+
"lines",
|
|
884
|
+
"json"
|
|
885
|
+
] } },
|
|
886
|
+
not: { required: ["delimiter"] }
|
|
887
|
+
}]
|
|
888
|
+
},
|
|
678
889
|
negation: {
|
|
679
890
|
type: "object",
|
|
680
891
|
additionalProperties: false,
|
|
@@ -683,38 +894,72 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
683
894
|
hidden: { const: true }
|
|
684
895
|
}
|
|
685
896
|
},
|
|
897
|
+
numberConstraints: {
|
|
898
|
+
type: "object",
|
|
899
|
+
additionalProperties: false,
|
|
900
|
+
properties: {
|
|
901
|
+
min: { type: "number" },
|
|
902
|
+
max: { type: "number" },
|
|
903
|
+
int: { type: "boolean" },
|
|
904
|
+
finite: { type: "boolean" }
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
stringConstraints: {
|
|
908
|
+
type: "object",
|
|
909
|
+
additionalProperties: false,
|
|
910
|
+
properties: {
|
|
911
|
+
nonEmpty: { type: "boolean" },
|
|
912
|
+
minLength: {
|
|
913
|
+
type: "integer",
|
|
914
|
+
minimum: 0
|
|
915
|
+
},
|
|
916
|
+
maxLength: {
|
|
917
|
+
type: "integer",
|
|
918
|
+
minimum: 0
|
|
919
|
+
},
|
|
920
|
+
pattern: {
|
|
921
|
+
type: "object",
|
|
922
|
+
additionalProperties: false,
|
|
923
|
+
properties: {
|
|
924
|
+
source: { type: "string" },
|
|
925
|
+
flags: { type: "string" }
|
|
926
|
+
},
|
|
927
|
+
required: ["source", "flags"]
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
pathChecks: {
|
|
932
|
+
type: "object",
|
|
933
|
+
additionalProperties: false,
|
|
934
|
+
properties: {
|
|
935
|
+
mustExist: { type: "boolean" },
|
|
936
|
+
type: { enum: ["file", "directory"] },
|
|
937
|
+
create: { const: true }
|
|
938
|
+
},
|
|
939
|
+
required: ["mustExist"]
|
|
940
|
+
},
|
|
941
|
+
argElement: {
|
|
942
|
+
type: "object",
|
|
943
|
+
additionalProperties: false,
|
|
944
|
+
properties: argElementFragmentProperties,
|
|
945
|
+
required: ["kind", "presence"]
|
|
946
|
+
},
|
|
686
947
|
arg: {
|
|
687
948
|
type: "object",
|
|
688
949
|
additionalProperties: false,
|
|
689
950
|
properties: {
|
|
690
951
|
name: { type: "string" },
|
|
691
|
-
|
|
692
|
-
"string",
|
|
693
|
-
"number",
|
|
694
|
-
"enum",
|
|
695
|
-
"custom"
|
|
696
|
-
] },
|
|
697
|
-
presence: { enum: [
|
|
698
|
-
"required",
|
|
699
|
-
"optional",
|
|
700
|
-
"defaulted"
|
|
701
|
-
] },
|
|
702
|
-
variadic: { const: true },
|
|
703
|
-
stdinMode: { const: true },
|
|
704
|
-
defaultValue: {},
|
|
705
|
-
description: { type: "string" },
|
|
706
|
-
envVar: { type: "string" },
|
|
707
|
-
enumValues: {
|
|
708
|
-
type: "array",
|
|
709
|
-
items: { type: "string" }
|
|
710
|
-
},
|
|
711
|
-
deprecated: { oneOf: [{ type: "string" }, { const: true }] }
|
|
952
|
+
...argValueFragmentProperties
|
|
712
953
|
},
|
|
713
954
|
required: [
|
|
714
955
|
"name",
|
|
715
956
|
"kind",
|
|
716
957
|
"presence"
|
|
717
|
-
]
|
|
958
|
+
],
|
|
959
|
+
anyOf: [{ not: { required: ["elementSchema"] } }, {
|
|
960
|
+
properties: { kind: { const: "keyValue" } },
|
|
961
|
+
required: ["kind"]
|
|
962
|
+
}]
|
|
718
963
|
},
|
|
719
964
|
prompt: {
|
|
720
965
|
type: "object",
|
|
@@ -759,4 +1004,4 @@ const definitionMetaSchema = withDefinitionMetaSchemaDescriptions({
|
|
|
759
1004
|
}
|
|
760
1005
|
}, definitionMetaSchemaDescriptions);
|
|
761
1006
|
//#endregion
|
|
762
|
-
export { definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema };
|
|
1007
|
+
export { DEFINITION_SCHEMA_URL, DEFINITION_SCHEMA_VERSION, definitionMetaSchema, generateCommandSchema, generateInputSchema, generateSchema };
|