@ykdz/template 0.0.38 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.d.ts +1 -52
- package/dist/application.js +0 -81
- package/dist/cli.js +14 -28
- package/dist/input-schemas.d.ts +30 -0
- package/dist/input-schemas.js +75 -0
- package/dist/main.d.ts +3 -14
- package/dist/main.js +496 -378
- package/dist/result-schemas.d.ts +222 -0
- package/dist/result-schemas.js +74 -0
- package/dist/standard-schema.d.ts +3 -0
- package/dist/standard-schema.js +29 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/assert/strict.d.ts +111 -0
- package/node_modules/@types/node/assert.d.ts +1115 -0
- package/node_modules/@types/node/async_hooks.d.ts +619 -0
- package/node_modules/@types/node/buffer.buffer.d.ts +477 -0
- package/node_modules/@types/node/buffer.d.ts +1941 -0
- package/node_modules/@types/node/child_process.d.ts +1480 -0
- package/node_modules/@types/node/cluster.d.ts +578 -0
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/console.d.ts +453 -0
- package/node_modules/@types/node/constants.d.ts +21 -0
- package/node_modules/@types/node/crypto.d.ts +5484 -0
- package/node_modules/@types/node/dgram.d.ts +715 -0
- package/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
- package/node_modules/@types/node/dns/promises.d.ts +503 -0
- package/node_modules/@types/node/dns.d.ts +923 -0
- package/node_modules/@types/node/domain.d.ts +166 -0
- package/node_modules/@types/node/events.d.ts +967 -0
- package/node_modules/@types/node/fs/promises.d.ts +1354 -0
- package/node_modules/@types/node/fs.d.ts +4777 -0
- package/node_modules/@types/node/globals.d.ts +170 -0
- package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
- package/node_modules/@types/node/http.d.ts +2246 -0
- package/node_modules/@types/node/http2.d.ts +2882 -0
- package/node_modules/@types/node/https.d.ts +585 -0
- package/node_modules/@types/node/index.d.ts +101 -0
- package/node_modules/@types/node/inspector.d.ts +323 -0
- package/node_modules/@types/node/inspector.generated.d.ts +4406 -0
- package/node_modules/@types/node/module.d.ts +844 -0
- package/node_modules/@types/node/net.d.ts +1197 -0
- package/node_modules/@types/node/os.d.ts +507 -0
- package/node_modules/@types/node/package.json +140 -0
- package/node_modules/@types/node/path.d.ts +200 -0
- package/node_modules/@types/node/perf_hooks.d.ts +1054 -0
- package/node_modules/@types/node/process.d.ts +2101 -0
- package/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/node/querystring.d.ts +152 -0
- package/node_modules/@types/node/readline/promises.d.ts +161 -0
- package/node_modules/@types/node/readline.d.ts +600 -0
- package/node_modules/@types/node/repl.d.ts +438 -0
- package/node_modules/@types/node/sea.d.ts +162 -0
- package/node_modules/@types/node/sqlite.d.ts +1182 -0
- package/node_modules/@types/node/stream/consumers.d.ts +45 -0
- package/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/node_modules/@types/node/stream/web.d.ts +596 -0
- package/node_modules/@types/node/stream.d.ts +1707 -0
- package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/node/test.d.ts +2656 -0
- package/node_modules/@types/node/timers/promises.d.ts +108 -0
- package/node_modules/@types/node/timers.d.ts +285 -0
- package/node_modules/@types/node/tls.d.ts +1314 -0
- package/node_modules/@types/node/trace_events.d.ts +197 -0
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +473 -0
- package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
- package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
- package/node_modules/@types/node/tty.d.ts +209 -0
- package/node_modules/@types/node/url.d.ts +1103 -0
- package/node_modules/@types/node/util.d.ts +2376 -0
- package/node_modules/@types/node/v8.d.ts +1010 -0
- package/node_modules/@types/node/vm.d.ts +1160 -0
- package/node_modules/@types/node/wasi.d.ts +202 -0
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
- package/node_modules/@types/node/worker_threads.d.ts +894 -0
- package/node_modules/@types/node/zlib.d.ts +768 -0
- package/node_modules/@valibot/to-json-schema/LICENSE.md +9 -0
- package/node_modules/@valibot/to-json-schema/README.md +475 -0
- package/node_modules/@valibot/to-json-schema/dist/index.cjs +800 -0
- package/node_modules/@valibot/to-json-schema/dist/index.d.cts +991 -0
- package/node_modules/@valibot/to-json-schema/dist/index.d.mts +991 -0
- package/node_modules/@valibot/to-json-schema/dist/index.min.cjs +1 -0
- package/node_modules/@valibot/to-json-schema/dist/index.min.mjs +1 -0
- package/node_modules/@valibot/to-json-schema/dist/index.mjs +795 -0
- package/node_modules/@valibot/to-json-schema/package.json +75 -0
- package/node_modules/@ykdz/cli-contract/LICENSE +21 -0
- package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.d.ts +17 -0
- package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.js +55 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-contract.d.ts +1164 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-contract.js +1408 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-execution.d.ts +54 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-execution.js +708 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-invocation.d.ts +174 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-invocation.js +524 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-write-error.d.ts +10 -0
- package/node_modules/@ykdz/cli-contract/dist/cli-write-error.js +14 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.d.ts +260 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.js +130 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.d.ts +63 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.js +17 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.d.ts +6 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.js +532 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema.d.ts +14 -0
- package/node_modules/@ykdz/cli-contract/dist/contract-schema.js +1 -0
- package/node_modules/@ykdz/cli-contract/dist/description.d.ts +2 -0
- package/node_modules/@ykdz/cli-contract/dist/description.js +13 -0
- package/node_modules/@ykdz/cli-contract/dist/index.d.ts +8 -0
- package/node_modules/@ykdz/cli-contract/dist/index.js +7 -0
- package/node_modules/@ykdz/cli-contract/dist/json-value.d.ts +4 -0
- package/node_modules/@ykdz/cli-contract/dist/json-value.js +64 -0
- package/node_modules/@ykdz/cli-contract/dist/node.d.ts +21 -0
- package/node_modules/@ykdz/cli-contract/dist/node.js +109 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-fact.d.ts +162 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-fact.js +113 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-wire.d.ts +53 -0
- package/node_modules/@ykdz/cli-contract/dist/outcome-wire.js +189 -0
- package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.d.ts +16 -0
- package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.js +45 -0
- package/node_modules/@ykdz/cli-contract/package.json +69 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.d.ts +20 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.js +5 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.d.ts +19 -0
- package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.js +1 -1
- package/node_modules/@ykdz/template-builtin-presets/dist/src/index.d.ts +2 -1
- package/node_modules/@ykdz/template-builtin-presets/dist/src/index.js +2 -1
- package/node_modules/@ykdz/template-builtin-presets/dist/src/ts-cli/definition.js +9 -5
- package/node_modules/@ykdz/template-builtin-presets/package.json +2 -1
- package/node_modules/@ykdz/template-builtin-presets/templates/foundation/AGENTS.md.template +3 -3
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/artifact.ts +128 -59
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/handoff.ts +80 -8
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/readiness.ts +7 -3
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/cli.ts +9 -19
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/main.ts +144 -60
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/standard-schema.ts +37 -0
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/lookup.journey.ts +71 -0
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/integration/command.test.ts +118 -59
- package/node_modules/@ykdz/template-core/dist/pnpm-workspace.yaml +2 -1
- package/node_modules/@ykdz/template-core/dist/project-blueprint.d.ts +15 -0
- package/node_modules/@ykdz/template-core/dist/project-blueprint.js +1 -1
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/README.md +6 -0
- package/node_modules/undici-types/agent.d.ts +32 -0
- package/node_modules/undici-types/api.d.ts +43 -0
- package/node_modules/undici-types/balanced-pool.d.ts +30 -0
- package/node_modules/undici-types/cache-interceptor.d.ts +179 -0
- package/node_modules/undici-types/cache.d.ts +36 -0
- package/node_modules/undici-types/client-stats.d.ts +15 -0
- package/node_modules/undici-types/client.d.ts +123 -0
- package/node_modules/undici-types/connector.d.ts +36 -0
- package/node_modules/undici-types/content-type.d.ts +21 -0
- package/node_modules/undici-types/cookies.d.ts +30 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
- package/node_modules/undici-types/dispatcher.d.ts +279 -0
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici-types/errors.d.ts +177 -0
- package/node_modules/undici-types/eventsource.d.ts +66 -0
- package/node_modules/undici-types/fetch.d.ts +211 -0
- package/node_modules/undici-types/formdata.d.ts +108 -0
- package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/node_modules/undici-types/global-origin.d.ts +7 -0
- package/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/node_modules/undici-types/handlers.d.ts +15 -0
- package/node_modules/undici-types/header.d.ts +160 -0
- package/node_modules/undici-types/index.d.ts +91 -0
- package/node_modules/undici-types/interceptors.d.ts +80 -0
- package/node_modules/undici-types/mock-agent.d.ts +68 -0
- package/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/node_modules/undici-types/mock-client.d.ts +27 -0
- package/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/node_modules/undici-types/mock-interceptor.d.ts +94 -0
- package/node_modules/undici-types/mock-pool.d.ts +27 -0
- package/node_modules/undici-types/package.json +55 -0
- package/node_modules/undici-types/patch.d.ts +29 -0
- package/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/node_modules/undici-types/pool.d.ts +41 -0
- package/node_modules/undici-types/proxy-agent.d.ts +29 -0
- package/node_modules/undici-types/readable.d.ts +68 -0
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/utility.d.ts +7 -0
- package/node_modules/undici-types/webidl.d.ts +347 -0
- package/node_modules/undici-types/websocket.d.ts +188 -0
- package/package.json +5 -3
- package/dist/command-result.d.ts +0 -9
- package/dist/command-result.js +0 -231
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/greet.journey.ts +0 -46
- package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/unit/greet.test.ts +0 -15
- package/node_modules/commander/LICENSE +0 -22
- package/node_modules/commander/Readme.md +0 -1172
- package/node_modules/commander/index.js +0 -21
- package/node_modules/commander/lib/argument.js +0 -147
- package/node_modules/commander/lib/command.js +0 -2790
- package/node_modules/commander/lib/error.js +0 -36
- package/node_modules/commander/lib/help.js +0 -731
- package/node_modules/commander/lib/option.js +0 -377
- package/node_modules/commander/lib/suggestSimilar.js +0 -99
- package/node_modules/commander/package-support.json +0 -19
- package/node_modules/commander/package.json +0 -64
- package/node_modules/commander/typings/index.d.ts +0 -1113
|
@@ -0,0 +1,1164 @@
|
|
|
1
|
+
import { type RuntimeAtomicVariant } from "#/atomic-variant-compiler";
|
|
2
|
+
import type { CommandUsage } from "#/cli-invocation";
|
|
3
|
+
import type { ContractSchema, ContractSchemaInput, ContractSchemaOutput, EmptyCliInput, JsonObject, JsonValue } from "#/contract-schema";
|
|
4
|
+
import type { AtomicTextPresenter, CompletionFact, CompletionTextPresenter, CompletionOutcome, DataFactUnion, DataOutcome, DataVariantDefinitions, FailureFactUnion, FailureOutcome, FailureVariantDefinitions, OutcomeFact, TextLine, TextLines, StreamOutcome, StreamTextPresenter, StreamRecordDefinitions, StreamRecordFactUnion, StreamSuccessFact } from "#/outcome-fact";
|
|
5
|
+
import { type RuntimeStreamRecord, type StreamRecordManifest } from "#/stream-variant-compiler";
|
|
6
|
+
export { createCompletionFact, createDataFact, createFailureFact, createStreamRecordFact, createStreamSuccessFact, isIssuedOutcomeFact, text, } from "#/outcome-fact";
|
|
7
|
+
export type { CompletionFact, CompletionTextPresenter, CompletionOutcome, DataFact, DataFactUnion, DataOutcome, DataVariantDefinition, DataVariantDefinitions, FailureFact, FailureFactUnion, FailureOutcome, FailureVariantDefinition, FailureVariantDefinitions, OutcomeFact, StreamOutcome, StreamRecordDefinition, StreamRecordDefinitions, StreamRecordFact, StreamRecordFactUnion, StreamSuccessFact, StreamTextPresenter, SilentText, TextLine, TextLines, TextFragment, } from "#/outcome-fact";
|
|
8
|
+
declare const cliContractType: unique symbol;
|
|
9
|
+
declare const executableCommandType: unique symbol;
|
|
10
|
+
declare const definitionPropertyKeys: {
|
|
11
|
+
readonly cli: readonly ["root", "help", "version", "output", "usageFailureExitCode", "commands"];
|
|
12
|
+
readonly group: readonly ["kind", "parent", "name", "aliases", "description", "helpSupplement", "handler"];
|
|
13
|
+
readonly command: readonly ["kind", "parent", "name", "aliases", "description", "helpSupplement", "fields", "input", "success", "failures", "handler", "usageConstraints"];
|
|
14
|
+
readonly field: {
|
|
15
|
+
readonly flag: readonly ["kind", "longOption", "shortAlias", "negatedLongOption", "description"];
|
|
16
|
+
readonly option: readonly ["kind", "longOption", "shortAlias", "description"];
|
|
17
|
+
readonly positional: readonly ["kind", "description"];
|
|
18
|
+
};
|
|
19
|
+
readonly usage: {
|
|
20
|
+
readonly requires: readonly ["kind", "field", "requires"];
|
|
21
|
+
readonly exclusive: readonly ["kind", "fields"];
|
|
22
|
+
readonly forbiddenCombination: readonly ["kind", "values"];
|
|
23
|
+
readonly value: readonly ["field", "value"];
|
|
24
|
+
};
|
|
25
|
+
readonly success: {
|
|
26
|
+
readonly completion: readonly ["kind", "text"];
|
|
27
|
+
readonly data: readonly ["kind", "variants"];
|
|
28
|
+
readonly stream: readonly ["kind", "records", "text"];
|
|
29
|
+
};
|
|
30
|
+
readonly atomicVariant: readonly ["description", "schema", "exitCode", "text"];
|
|
31
|
+
readonly streamRecord: readonly ["description", "schema", "text"];
|
|
32
|
+
readonly capability: {
|
|
33
|
+
readonly help: readonly ["shortAlias", "headings", "wording"];
|
|
34
|
+
readonly version: readonly ["value", "description", "shortAlias"];
|
|
35
|
+
readonly output: readonly ["defaultFormat", "text", "compatibilityFlags"];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export interface HelpCapability {
|
|
39
|
+
readonly kind: "helpCapability";
|
|
40
|
+
readonly longOption: "--help";
|
|
41
|
+
readonly shortAlias?: "-h";
|
|
42
|
+
readonly headings?: HelpHeadings;
|
|
43
|
+
readonly wording?: HelpFactWording;
|
|
44
|
+
readonly [cliContractType]: "help";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 根级帮助中既定段落的可选标题。未声明标题时仍保留对应机械内容和缩进,
|
|
48
|
+
* 不会由核心补写默认文案。
|
|
49
|
+
*/
|
|
50
|
+
export interface HelpHeadings {
|
|
51
|
+
readonly usage?: string;
|
|
52
|
+
readonly commands?: string;
|
|
53
|
+
readonly arguments?: string;
|
|
54
|
+
readonly options?: string;
|
|
55
|
+
readonly constraints?: string;
|
|
56
|
+
readonly supplement?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface HelpFactWording {
|
|
59
|
+
/** 命令组占位词本身,核心为它添加尖括号。 */
|
|
60
|
+
readonly commandPlaceholder?: string;
|
|
61
|
+
/** 字段或输出格式的候选集合,必须包含 `{choices}`。 */
|
|
62
|
+
readonly choices?: string;
|
|
63
|
+
/** 字段或输出格式的默认 JSON 值,必须包含 `{value}`。 */
|
|
64
|
+
readonly default?: string;
|
|
65
|
+
/** 字段依赖关系,必须包含 `{field}` 与 `{requires}`。 */
|
|
66
|
+
readonly requires?: string;
|
|
67
|
+
/** 互斥字段集合,必须包含 `{fields}`。 */
|
|
68
|
+
readonly exclusive?: string;
|
|
69
|
+
/** 禁止同时出现的字段和值,必须包含 `{values}`。 */
|
|
70
|
+
readonly forbiddenCombination?: string;
|
|
71
|
+
}
|
|
72
|
+
/** 根契约一次装配的帮助配置;标题可省略,实际出现的事实必须有文案。 */
|
|
73
|
+
export interface HelpCapabilityDefinition {
|
|
74
|
+
readonly shortAlias?: "-h";
|
|
75
|
+
readonly headings?: HelpHeadings;
|
|
76
|
+
readonly wording?: HelpFactWording;
|
|
77
|
+
}
|
|
78
|
+
export interface VersionCapability {
|
|
79
|
+
readonly kind: "versionCapability";
|
|
80
|
+
readonly value: string;
|
|
81
|
+
readonly description?: string;
|
|
82
|
+
readonly shortAlias?: "-V";
|
|
83
|
+
readonly [cliContractType]: "version";
|
|
84
|
+
}
|
|
85
|
+
export interface VersionCapabilityDefinition {
|
|
86
|
+
readonly value: TextLine;
|
|
87
|
+
readonly description?: string;
|
|
88
|
+
readonly shortAlias?: "-V";
|
|
89
|
+
}
|
|
90
|
+
export type OutputFormat = "structured" | "text";
|
|
91
|
+
export interface OutputCapability<Formats extends readonly OutputFormat[] = readonly OutputFormat[]> {
|
|
92
|
+
readonly kind: "outputCapability";
|
|
93
|
+
readonly defaultFormat: Formats[number];
|
|
94
|
+
readonly formats: Formats;
|
|
95
|
+
readonly compatibilityFlags: Readonly<Record<string, OutputFormat>>;
|
|
96
|
+
readonly [cliContractType]: "output";
|
|
97
|
+
}
|
|
98
|
+
type OutputCapabilityDefinition = Readonly<{
|
|
99
|
+
readonly defaultFormat: OutputFormat;
|
|
100
|
+
readonly text?: boolean;
|
|
101
|
+
readonly compatibilityFlags?: Readonly<Record<`--${string}`, OutputFormat>>;
|
|
102
|
+
}>;
|
|
103
|
+
type OutputFormatsFor<Definition extends OutputCapabilityDefinition> = Definition["defaultFormat"] extends "text" ? readonly ["structured", "text"] : Definition["text"] extends true ? readonly ["structured", "text"] : readonly ["structured"];
|
|
104
|
+
type LowercaseLetter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
105
|
+
type DecimalDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
106
|
+
type LowercaseAlphaNumeric = DecimalDigit | LowercaseLetter;
|
|
107
|
+
type AlphaNumeric = LowercaseAlphaNumeric | Uppercase<LowercaseLetter>;
|
|
108
|
+
type IsCanonicalKebabBody<Value extends string, NeedsCharacter extends boolean = true> = Value extends "" ? NeedsCharacter extends true ? false : true : Value extends `${LowercaseAlphaNumeric}${infer Rest}` ? IsCanonicalKebabBody<Rest, false> : Value extends `-${infer Rest}` ? NeedsCharacter extends true ? false : IsCanonicalKebabBody<Rest> : false;
|
|
109
|
+
type IsLowerCamelCase<Value extends string> = Value extends `${LowercaseLetter}${infer Rest}` ? Rest extends "" ? true : Rest extends `${AlphaNumeric}${infer Tail}` ? IsAlphaNumericTail<Tail> : false : false;
|
|
110
|
+
type IsAlphaNumericTail<Value extends string> = Value extends "" ? true : Value extends `${AlphaNumeric}${infer Rest}` ? IsAlphaNumericTail<Rest> : false;
|
|
111
|
+
export type CanonicalLongOption<Value extends string> = string extends Value ? `--${string}` : `--${string}` extends Value ? Value : Value extends `--${infer Body}` ? IsCanonicalKebabBody<Body> extends true ? Value : never : never;
|
|
112
|
+
export type ShortOptionAlias<Value extends string> = string extends Value ? `-${string}` : Value extends `-${infer Body}` ? Body extends AlphaNumeric ? Value : never : never;
|
|
113
|
+
export interface PositionalDefinition {
|
|
114
|
+
readonly kind: "positional";
|
|
115
|
+
readonly description: string;
|
|
116
|
+
}
|
|
117
|
+
export interface VariadicPositionalDefinition {
|
|
118
|
+
readonly kind: "variadicPositional";
|
|
119
|
+
readonly description: string;
|
|
120
|
+
}
|
|
121
|
+
export interface FlagDefinition<LongOption extends `--${string}` = `--${string}`, ShortAlias extends `-${string}` | undefined = `-${string}` | undefined, NegatedLongOption extends `--${string}` | undefined = `--${string}` | undefined> {
|
|
122
|
+
readonly kind: "flag";
|
|
123
|
+
readonly longOption: LongOption;
|
|
124
|
+
readonly shortAlias?: ShortAlias;
|
|
125
|
+
readonly negatedLongOption?: NegatedLongOption;
|
|
126
|
+
readonly description: string;
|
|
127
|
+
}
|
|
128
|
+
export interface RepeatableOptionDefinition<LongOption extends `--${string}` = `--${string}`, ShortAlias extends `-${string}` | undefined = `-${string}` | undefined> {
|
|
129
|
+
readonly kind: "repeatableOption";
|
|
130
|
+
readonly longOption: LongOption;
|
|
131
|
+
readonly shortAlias?: ShortAlias;
|
|
132
|
+
readonly description: string;
|
|
133
|
+
}
|
|
134
|
+
export interface ValueOptionDefinition<LongOption extends `--${string}` = `--${string}`, ShortAlias extends `-${string}` | undefined = `-${string}` | undefined> {
|
|
135
|
+
readonly kind: "valueOption";
|
|
136
|
+
readonly longOption: LongOption;
|
|
137
|
+
readonly shortAlias?: ShortAlias;
|
|
138
|
+
readonly description: string;
|
|
139
|
+
}
|
|
140
|
+
export type FieldDefinition = FlagDefinition | PositionalDefinition | RepeatableOptionDefinition | VariadicPositionalDefinition | ValueOptionDefinition;
|
|
141
|
+
export type FieldDefinitions = Readonly<Record<string, FieldDefinition>>;
|
|
142
|
+
/**
|
|
143
|
+
* 由调用语法拥有、可同时投影到 parser 和 Draft 2020-12 的字段关系。
|
|
144
|
+
* `requires` 与 `exclusive` 作用于可选 option;`forbiddenCombination`
|
|
145
|
+
* 的离散值只作用于 flag 或 value option。动态声明在定义期检查这些前提。
|
|
146
|
+
*/
|
|
147
|
+
export type UsageConstraint<Fields extends FieldDefinitions = FieldDefinitions> = RequiresUsageConstraint<Extract<keyof Fields, string>> | ExclusiveUsageConstraint<Extract<keyof Fields, string>> | ForbiddenCombinationUsageConstraint<Fields>;
|
|
148
|
+
export interface RequiresUsageConstraint<Field extends string = string> {
|
|
149
|
+
readonly kind: "requires";
|
|
150
|
+
readonly field: Field;
|
|
151
|
+
readonly requires: Field;
|
|
152
|
+
}
|
|
153
|
+
export interface ExclusiveUsageConstraint<Field extends string = string> {
|
|
154
|
+
readonly kind: "exclusive";
|
|
155
|
+
readonly fields: readonly [Field, Field, ...Field[]];
|
|
156
|
+
}
|
|
157
|
+
type DiscreteUsageValue<Field extends FieldDefinition> = Field extends FlagDefinition ? boolean : Field extends ValueOptionDefinition ? string : never;
|
|
158
|
+
export type ForbiddenCombinationValue<Fields extends FieldDefinitions = FieldDefinitions> = {
|
|
159
|
+
[Field in keyof Fields & string]: DiscreteUsageValue<Fields[Field]> extends never ? never : Readonly<{
|
|
160
|
+
readonly field: Field;
|
|
161
|
+
readonly value: DiscreteUsageValue<Fields[Field]>;
|
|
162
|
+
}>;
|
|
163
|
+
}[keyof Fields & string];
|
|
164
|
+
export interface ForbiddenCombinationUsageConstraint<Fields extends FieldDefinitions = FieldDefinitions> {
|
|
165
|
+
readonly kind: "forbiddenCombination";
|
|
166
|
+
readonly values: readonly [
|
|
167
|
+
ForbiddenCombinationValue<Fields>,
|
|
168
|
+
ForbiddenCombinationValue<Fields>,
|
|
169
|
+
...ForbiddenCombinationValue<Fields>[]
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
export type ValueOptionDefinitions = Readonly<Record<string, ValueOptionDefinition>>;
|
|
173
|
+
type RawFieldValue<Field extends FieldDefinition> = Field extends {
|
|
174
|
+
readonly kind: "flag";
|
|
175
|
+
} ? Field extends {
|
|
176
|
+
readonly negatedLongOption: unknown;
|
|
177
|
+
} ? boolean : true : Field extends RepeatableOptionDefinition | VariadicPositionalDefinition ? readonly [string, ...string[]] : string;
|
|
178
|
+
type RawSchemaInputValue<Field extends FieldDefinition> = Field extends RepeatableOptionDefinition | VariadicPositionalDefinition ? [string, ...string[]] : RawFieldValue<Field>;
|
|
179
|
+
export type RawFieldInput<Fields extends FieldDefinitions> = Readonly<{
|
|
180
|
+
[Field in keyof Fields]?: RawFieldValue<Fields[Field]>;
|
|
181
|
+
}>;
|
|
182
|
+
export type RawValueOptionInput<Fields extends ValueOptionDefinitions> = RawFieldInput<Fields>;
|
|
183
|
+
export type FieldDefinitionsForInput<Input> = Readonly<{
|
|
184
|
+
[Field in Extract<keyof Input, string>]: FieldDefinition;
|
|
185
|
+
}>;
|
|
186
|
+
export type ValueOptionDefinitionsForInput<Input> = Readonly<{
|
|
187
|
+
[Field in Extract<keyof Input, string>]: ValueOptionDefinition;
|
|
188
|
+
}>;
|
|
189
|
+
type CheckedFieldDefinition<Field extends FieldDefinition, Key> = Field extends PositionalDefinition ? Field : Field extends VariadicPositionalDefinition ? Field : Field extends FlagDefinition<infer LongOption, infer ShortAlias> ? CheckedNegatedFlagDefinition<Field, Key, LongOption, ShortAlias> : Field extends RepeatableOptionDefinition<infer LongOption, infer ShortAlias> ? CheckedOptionDefinition<Field, Key, LongOption, ShortAlias> : Field extends ValueOptionDefinition<infer LongOption, infer ShortAlias> ? CheckedOptionDefinition<Field, Key, LongOption, ShortAlias> : never;
|
|
190
|
+
type CheckedNegatedFlagDefinition<Field, Key, LongOption extends `--${string}`, ShortAlias extends `-${string}` | undefined> = CheckedOptionDefinition<Field, Key, LongOption, ShortAlias> extends Field ? Field extends {
|
|
191
|
+
readonly negatedLongOption: infer NegatedLongOption extends `--${string}`;
|
|
192
|
+
} ? NegatedLongOption extends CanonicalLongOption<NegatedLongOption> ? Field : ContractTypeError<"invalidNegatedLongOption", Readonly<{
|
|
193
|
+
readonly field: Key;
|
|
194
|
+
readonly received: NegatedLongOption;
|
|
195
|
+
}>> : Field : CheckedOptionDefinition<Field, Key, LongOption, ShortAlias>;
|
|
196
|
+
type CheckedOptionDefinition<Field, Key, LongOption extends `--${string}`, ShortAlias extends `-${string}` | undefined> = LongOption extends CanonicalLongOption<LongOption> ? ShortAlias extends undefined ? Field : ShortAlias extends ShortOptionAlias<Extract<ShortAlias, string>> ? Field : ContractTypeError<"invalidShortOptionAlias", Readonly<{
|
|
197
|
+
readonly field: Key;
|
|
198
|
+
readonly received: ShortAlias;
|
|
199
|
+
}>> : ContractTypeError<"invalidCanonicalLongOption", Readonly<{
|
|
200
|
+
readonly field: Key;
|
|
201
|
+
readonly received: LongOption;
|
|
202
|
+
}>>;
|
|
203
|
+
type CheckedFieldDefinitions<Fields extends FieldDefinitions> = {
|
|
204
|
+
readonly [Field in keyof Fields]: CheckedFieldDefinition<Fields[Field], Field> & RejectUnknownProperties<Fields[Field], AllowedFieldProperties<Fields[Field]>>;
|
|
205
|
+
};
|
|
206
|
+
type RejectUnknownProperties<Value, Allowed extends PropertyKey> = Readonly<{
|
|
207
|
+
[Property in Exclude<keyof Value, Allowed>]?: never;
|
|
208
|
+
}>;
|
|
209
|
+
type AllowedFieldProperties<Field> = Field extends Readonly<{
|
|
210
|
+
readonly kind: "flag";
|
|
211
|
+
}> ? (typeof definitionPropertyKeys.field.flag)[number] : Field extends Readonly<{
|
|
212
|
+
readonly kind: "valueOption" | "repeatableOption";
|
|
213
|
+
}> ? (typeof definitionPropertyKeys.field.option)[number] : (typeof definitionPropertyKeys.field.positional)[number];
|
|
214
|
+
type ClosedVariantDefinitions<Definitions, Allowed extends PropertyKey> = Readonly<{
|
|
215
|
+
[Variant in keyof Definitions]: RejectUnknownProperties<Definitions[Variant], Allowed>;
|
|
216
|
+
}>;
|
|
217
|
+
type ClosedAtomicVariants<Variants> = ClosedVariantDefinitions<Variants, (typeof definitionPropertyKeys.atomicVariant)[number]>;
|
|
218
|
+
type ClosedStreamRecords<Records> = ClosedVariantDefinitions<Records, (typeof definitionPropertyKeys.streamRecord)[number]>;
|
|
219
|
+
type ClosedFieldDefinitions<Fields> = Readonly<{
|
|
220
|
+
[Field in keyof Fields]: RejectUnknownProperties<Fields[Field], AllowedFieldProperties<Fields[Field]>>;
|
|
221
|
+
}>;
|
|
222
|
+
type ClosedUsageConstraint<Constraint> = Constraint extends Readonly<{
|
|
223
|
+
readonly kind: "requires";
|
|
224
|
+
}> ? RejectUnknownProperties<Constraint, (typeof definitionPropertyKeys.usage.requires)[number]> : Constraint extends Readonly<{
|
|
225
|
+
readonly kind: "exclusive";
|
|
226
|
+
}> ? RejectUnknownProperties<Constraint, (typeof definitionPropertyKeys.usage.exclusive)[number]> : Constraint extends Readonly<{
|
|
227
|
+
readonly kind: "forbiddenCombination";
|
|
228
|
+
readonly values: infer Values extends readonly unknown[];
|
|
229
|
+
}> ? RejectUnknownProperties<Constraint, (typeof definitionPropertyKeys.usage.forbiddenCombination)[number]> & Readonly<{
|
|
230
|
+
readonly values: {
|
|
231
|
+
[Index in keyof Values]: Values[Index] & RejectUnknownProperties<Values[Index], (typeof definitionPropertyKeys.usage.value)[number]>;
|
|
232
|
+
};
|
|
233
|
+
}> : unknown;
|
|
234
|
+
type ClosedUsageConstraints<Constraints> = Constraints extends readonly (infer Constraint)[] ? readonly (Constraint & ClosedUsageConstraint<Constraint>)[] : unknown;
|
|
235
|
+
type ClosedSuccessDefinition<Success> = Success extends Readonly<{
|
|
236
|
+
readonly kind: "data";
|
|
237
|
+
readonly variants: infer Variants;
|
|
238
|
+
}> ? RejectUnknownProperties<Success, (typeof definitionPropertyKeys.success.data)[number]> & Readonly<{
|
|
239
|
+
readonly variants: ClosedAtomicVariants<Variants>;
|
|
240
|
+
}> : Success extends Readonly<{
|
|
241
|
+
readonly kind: "stream";
|
|
242
|
+
readonly records: infer Records;
|
|
243
|
+
}> ? RejectUnknownProperties<Success, (typeof definitionPropertyKeys.success.stream)[number]> & Readonly<{
|
|
244
|
+
readonly records: ClosedStreamRecords<Records>;
|
|
245
|
+
}> : RejectUnknownProperties<Success, (typeof definitionPropertyKeys.success.completion)[number]>;
|
|
246
|
+
type ClosedCommandDefinition<Definition> = RejectUnknownProperties<Definition, (typeof definitionPropertyKeys.command)[number] | typeof executableCommandType> & (Definition extends Readonly<{
|
|
247
|
+
readonly success: infer Success;
|
|
248
|
+
}> ? Readonly<{
|
|
249
|
+
readonly success: ClosedSuccessDefinition<Success>;
|
|
250
|
+
}> : unknown) & (Definition extends Readonly<{
|
|
251
|
+
readonly failures: infer Failures;
|
|
252
|
+
}> ? Readonly<{
|
|
253
|
+
readonly failures: ClosedAtomicVariants<Failures>;
|
|
254
|
+
}> : unknown) & (Definition extends Readonly<{
|
|
255
|
+
readonly fields: infer Fields;
|
|
256
|
+
}> ? Readonly<{
|
|
257
|
+
readonly fields: ClosedFieldDefinitions<Fields>;
|
|
258
|
+
}> : unknown) & (Definition extends Readonly<{
|
|
259
|
+
readonly usageConstraints: infer Constraints;
|
|
260
|
+
}> ? Readonly<{
|
|
261
|
+
readonly usageConstraints: ClosedUsageConstraints<Constraints>;
|
|
262
|
+
}> : unknown);
|
|
263
|
+
type ClosedRootCommands<Commands> = Readonly<{
|
|
264
|
+
[Command in keyof Commands]: Commands[Command] extends Readonly<{
|
|
265
|
+
readonly kind: "command" | "rootCommand";
|
|
266
|
+
}> ? ClosedCommandDefinition<Commands[Command]> : RejectUnknownProperties<Commands[Command], (typeof definitionPropertyKeys.group)[number]>;
|
|
267
|
+
}>;
|
|
268
|
+
type ClosedRootDefinition<Definition> = RejectUnknownProperties<Definition, (typeof definitionPropertyKeys.cli)[number]> & (Definition extends Readonly<{
|
|
269
|
+
readonly commands: infer Commands;
|
|
270
|
+
}> ? Readonly<{
|
|
271
|
+
readonly commands: ClosedRootCommands<Commands>;
|
|
272
|
+
}> : unknown);
|
|
273
|
+
type InvalidFieldIdentities<Fields extends FieldDefinitions> = {
|
|
274
|
+
[Field in keyof Fields & string]: IsLowerCamelCase<Field> extends true ? never : Field;
|
|
275
|
+
}[keyof Fields & string];
|
|
276
|
+
type FieldIdentityContract<Fields extends FieldDefinitions> = string extends keyof Fields ? unknown : InvalidFieldIdentities<Fields> extends never ? unknown : ContractTypeError<"fieldMustBeLowerCamelCase", Readonly<{
|
|
277
|
+
readonly fields: InvalidFieldIdentities<Fields>;
|
|
278
|
+
}>>;
|
|
279
|
+
export type RawValueOptionInputForSchema<InputSchema extends ContractSchema> = Readonly<{
|
|
280
|
+
[Field in Extract<keyof ContractSchemaInput<InputSchema>, string>]?: string;
|
|
281
|
+
}>;
|
|
282
|
+
export interface ContractTypeError<Code extends string, Evidence> {
|
|
283
|
+
readonly contractTypeError: Readonly<{
|
|
284
|
+
readonly code: Code;
|
|
285
|
+
} & Evidence>;
|
|
286
|
+
}
|
|
287
|
+
type InputStringKeys<Input> = Extract<keyof Input, string>;
|
|
288
|
+
type IsAny<Value> = 0 extends 1 & Value ? true : false;
|
|
289
|
+
type IsUnion<Value, Whole = Value> = IsAny<Value> extends true ? false : Value extends unknown ? [Whole] extends [Value] ? false : true : never;
|
|
290
|
+
type NormalizeNarrowStringLeaf<Value> = IsAny<Value> extends true ? Value : [Value] extends [never] ? Value : [Exclude<Value, undefined>] extends [never] ? Value : [Exclude<Value, undefined>] extends [string] ? string | (undefined extends Value ? undefined : never) : Value;
|
|
291
|
+
type NormalizeNarrowStringArray<Value extends readonly unknown[]> = {
|
|
292
|
+
[Index in keyof Value]: NormalizeNarrowStringLeaf<Value[Index]>;
|
|
293
|
+
};
|
|
294
|
+
type NormalizeNarrowStrings<Value> = IsAny<Value> extends true ? Value : [Value] extends [never] ? Value : [Exclude<Value, undefined>] extends [readonly unknown[]] ? IsUnion<Exclude<Value, undefined>> extends true ? Value : NormalizeNarrowStringArray<Extract<Exclude<Value, undefined>, readonly unknown[]>> | (undefined extends Value ? undefined : never) : NormalizeNarrowStringLeaf<Value>;
|
|
295
|
+
type IncompatibleRawInputKeys<Fields extends FieldDefinitions, Input> = {
|
|
296
|
+
[Field in keyof Fields & InputStringKeys<Input>]: RawSchemaInputValue<Fields[Field]> extends NormalizeNarrowStrings<Input[Field]> ? never : Field;
|
|
297
|
+
}[keyof Fields & InputStringKeys<Input>];
|
|
298
|
+
type RawFieldInputContract<Command extends string, Fields extends FieldDefinitions, InputSchema extends ContractSchema> = IncompatibleRawInputKeys<Fields, ContractSchemaInput<InputSchema>> extends never ? unknown : IncompatibleRawInputIssues<Command, Fields, ContractSchemaInput<InputSchema>>;
|
|
299
|
+
type InvalidVariantNames<Variants> = {
|
|
300
|
+
[Variant in keyof Variants & string]: IsLowerCamelCase<Variant> extends true ? never : Variant;
|
|
301
|
+
}[keyof Variants & string];
|
|
302
|
+
type InvalidDataVariantNames<Variants> = InvalidVariantNames<Variants>;
|
|
303
|
+
type DataVariantNameContract<Variants> = InvalidDataVariantNames<Variants> extends never ? unknown : ContractTypeError<"dataVariantMustBeLowerCamelCase", Readonly<{
|
|
304
|
+
readonly variants: InvalidDataVariantNames<Variants>;
|
|
305
|
+
}>>;
|
|
306
|
+
type InvalidFailureVariantNames<Failures> = InvalidVariantNames<Failures>;
|
|
307
|
+
type FailureVariantNameContract<Failures> = InvalidFailureVariantNames<Failures> extends never ? unknown : ContractTypeError<"failureVariantMustBeLowerCamelCase", Readonly<{
|
|
308
|
+
readonly variants: InvalidFailureVariantNames<Failures>;
|
|
309
|
+
}>>;
|
|
310
|
+
export interface CompletionHandlerContext<Command extends string, Dependencies, Failures extends FailureVariantDefinitions, Input = EmptyCliInput> {
|
|
311
|
+
readonly input: Input;
|
|
312
|
+
readonly dependencies: Dependencies;
|
|
313
|
+
readonly outcome: CompletionOutcome<Command> & FailureOutcome<Command, Failures>;
|
|
314
|
+
}
|
|
315
|
+
export interface DataHandlerContext<Command extends string, Dependencies, Input, Variants extends DataVariantDefinitions, Failures extends FailureVariantDefinitions> {
|
|
316
|
+
readonly input: Input;
|
|
317
|
+
readonly dependencies: Dependencies;
|
|
318
|
+
readonly outcome: DataOutcome<Command, Variants> & FailureOutcome<Command, Failures>;
|
|
319
|
+
}
|
|
320
|
+
export interface StreamHandlerContext<Command extends string, Dependencies, Input, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions> {
|
|
321
|
+
readonly input: Input;
|
|
322
|
+
readonly dependencies: Dependencies;
|
|
323
|
+
readonly outcome: StreamOutcome<Command, Records> & FailureOutcome<Command, Failures>;
|
|
324
|
+
}
|
|
325
|
+
type CompletionSuccessDefinition<Command extends string, TextEnabled extends boolean> = TextEnabled extends true ? Readonly<{
|
|
326
|
+
readonly kind: "completion";
|
|
327
|
+
readonly text: CompletionTextPresenter;
|
|
328
|
+
}> | (Readonly<{
|
|
329
|
+
readonly kind: "completion";
|
|
330
|
+
}> & ContractTypeError<"missingTextPresenter", Readonly<{
|
|
331
|
+
readonly command: Command;
|
|
332
|
+
readonly location: "completion";
|
|
333
|
+
readonly missing: "text";
|
|
334
|
+
}>>) : TextEnabled extends false ? Readonly<{
|
|
335
|
+
readonly kind: "completion";
|
|
336
|
+
readonly text?: never;
|
|
337
|
+
}> : Readonly<{
|
|
338
|
+
readonly kind: "completion";
|
|
339
|
+
readonly text?: CompletionTextPresenter;
|
|
340
|
+
}>;
|
|
341
|
+
type MissingVariantTextPresenters<Variants> = {
|
|
342
|
+
[Variant in keyof Variants & string]: Variants[Variant] extends Readonly<{
|
|
343
|
+
readonly text: unknown;
|
|
344
|
+
}> ? never : Variant;
|
|
345
|
+
}[keyof Variants & string];
|
|
346
|
+
type NamedVariantTextContract<Command extends string, Location extends "data" | "failure" | "record", Variants, TextEnabled extends boolean, TextDisabledDefinition> = [TextEnabled] extends [true] ? MissingVariantTextPresenters<Variants> extends never ? unknown : ContractTypeError<"missingTextPresenter", Readonly<{
|
|
347
|
+
readonly command: Command;
|
|
348
|
+
readonly location: Location;
|
|
349
|
+
readonly variant: MissingVariantTextPresenters<Variants>;
|
|
350
|
+
readonly missing: "text";
|
|
351
|
+
}>> : [TextEnabled] extends [false] ? TextDisabledDefinition : unknown;
|
|
352
|
+
type DataVariantTextContract<Command extends string, Variants, TextEnabled extends boolean> = NamedVariantTextContract<Command, "data", Variants, TextEnabled, DataVariantDefinitions<false>>;
|
|
353
|
+
type AtomicTextPresenterContract<Payload, TextEnabled extends boolean> = [
|
|
354
|
+
TextEnabled
|
|
355
|
+
] extends [true] ? Readonly<{
|
|
356
|
+
readonly text: AtomicTextPresenter<Payload>;
|
|
357
|
+
}> : [TextEnabled] extends [false] ? Readonly<{
|
|
358
|
+
readonly text?: never;
|
|
359
|
+
}> : Readonly<{
|
|
360
|
+
readonly text?: AtomicTextPresenter<Payload>;
|
|
361
|
+
}>;
|
|
362
|
+
type AtomicVariantDefinitionForSchema<Schema extends ContractSchema, TextEnabled extends boolean> = Readonly<{
|
|
363
|
+
readonly description: string;
|
|
364
|
+
readonly schema: Schema;
|
|
365
|
+
readonly exitCode: number;
|
|
366
|
+
}> & AtomicTextPresenterContract<ContractSchemaOutput<Schema>, TextEnabled>;
|
|
367
|
+
type VariantSchemaMap = Record<string, ContractSchema>;
|
|
368
|
+
type DataVariantDefinitionsForSchemas<Schemas extends VariantSchemaMap, TextEnabled extends boolean> = Readonly<{
|
|
369
|
+
readonly [Variant in keyof Schemas]: AtomicVariantDefinitionForSchema<Schemas[Variant], TextEnabled>;
|
|
370
|
+
}>;
|
|
371
|
+
type FailureVariantDefinitionsForSchemas<Schemas extends VariantSchemaMap, TextEnabled extends boolean> = Readonly<{
|
|
372
|
+
readonly [Variant in keyof Schemas]: AtomicVariantDefinitionForSchema<Schemas[Variant], TextEnabled>;
|
|
373
|
+
}>;
|
|
374
|
+
type FailureVariantTextContract<Command extends string, Failures, TextEnabled extends boolean> = NamedVariantTextContract<Command, "failure", Failures, TextEnabled, FailureVariantDefinitions<false>>;
|
|
375
|
+
type StreamRecordTextContract<Command extends string, Records, TextEnabled extends boolean> = NamedVariantTextContract<Command, "record", Records, TextEnabled, StreamRecordDefinitions<false>>;
|
|
376
|
+
type StreamRecordNameContract<Records> = InvalidVariantNames<Records> extends never ? unknown : ContractTypeError<"streamRecordMustBeLowerCamelCase", Readonly<{
|
|
377
|
+
readonly records: InvalidVariantNames<Records>;
|
|
378
|
+
}>>;
|
|
379
|
+
type StreamRecordDefinitionForSchema<Schema extends ContractSchema, TextEnabled extends boolean> = Readonly<{
|
|
380
|
+
readonly description: string;
|
|
381
|
+
readonly schema: Schema;
|
|
382
|
+
}> & ([TextEnabled] extends [false] ? Readonly<{
|
|
383
|
+
readonly text?: never;
|
|
384
|
+
}> : Readonly<{
|
|
385
|
+
readonly text?: StreamTextPresenter<ContractSchemaOutput<Schema>>;
|
|
386
|
+
}>);
|
|
387
|
+
type StreamRecordDefinitionsForSchemas<Schemas extends VariantSchemaMap, TextEnabled extends boolean> = Readonly<{
|
|
388
|
+
readonly [Variant in keyof Schemas]: StreamRecordDefinitionForSchema<Schemas[Variant], TextEnabled>;
|
|
389
|
+
}>;
|
|
390
|
+
export interface CompletionRootCommandDefinition<Command extends string, Dependencies, Failures extends FailureVariantDefinitions = Readonly<Record<never, never>>, Fields extends FieldDefinitions = Readonly<Record<never, never>>, InputSchema extends ContractSchema = ContractSchema<EmptyCliInput>, TextEnabled extends boolean = boolean> {
|
|
391
|
+
readonly kind: "rootCommand";
|
|
392
|
+
readonly name: string;
|
|
393
|
+
readonly description: string;
|
|
394
|
+
readonly helpSupplement?: TextLines;
|
|
395
|
+
readonly usageConstraints?: readonly UsageConstraint<Fields>[];
|
|
396
|
+
readonly fields?: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
397
|
+
readonly input: InputSchema & RawFieldInputContract<Command, Fields, InputSchema>;
|
|
398
|
+
readonly success: CompletionSuccessDefinition<Command, TextEnabled>;
|
|
399
|
+
readonly failures: Failures & ClosedAtomicVariants<Failures> & FailureVariantNameContract<Failures> & FailureVariantTextContract<Command, Failures, TextEnabled>;
|
|
400
|
+
readonly handler: (context: CompletionHandlerContext<Command, Dependencies, Failures, ContractSchemaOutput<InputSchema>>) => CompletionFact<Command> | FailureFactUnion<Command, Failures> | Promise<CompletionFact<Command> | FailureFactUnion<Command, Failures>>;
|
|
401
|
+
}
|
|
402
|
+
export interface DataRootCommandDefinition<Command extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, Variants extends DataVariantDefinitions, Failures extends FailureVariantDefinitions> {
|
|
403
|
+
readonly kind: "rootCommand";
|
|
404
|
+
readonly name: string;
|
|
405
|
+
readonly description: string;
|
|
406
|
+
readonly helpSupplement?: TextLines;
|
|
407
|
+
readonly usageConstraints?: readonly UsageConstraint<Fields>[];
|
|
408
|
+
readonly fields: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
409
|
+
readonly input: InputSchema & RawFieldInputContract<Command, Fields, InputSchema>;
|
|
410
|
+
readonly success: Readonly<{
|
|
411
|
+
readonly kind: "data";
|
|
412
|
+
readonly variants: Variants & ClosedAtomicVariants<Variants> & DataVariantNameContract<Variants>;
|
|
413
|
+
}>;
|
|
414
|
+
readonly failures: Failures & ClosedAtomicVariants<Failures> & FailureVariantNameContract<Failures>;
|
|
415
|
+
readonly handler: (context: DataHandlerContext<Command, Dependencies, ContractSchemaOutput<InputSchema>, Variants, Failures>) => DataFactUnion<Command, Variants> | FailureFactUnion<Command, Failures> | Promise<DataFactUnion<Command, Variants> | FailureFactUnion<Command, Failures>>;
|
|
416
|
+
}
|
|
417
|
+
export interface StreamRootCommandDefinition<Command extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions, TextEnabled extends boolean = boolean> {
|
|
418
|
+
readonly kind: "rootCommand";
|
|
419
|
+
readonly name: string;
|
|
420
|
+
readonly description: string;
|
|
421
|
+
readonly helpSupplement?: TextLines;
|
|
422
|
+
readonly usageConstraints?: readonly UsageConstraint<Fields>[];
|
|
423
|
+
readonly fields?: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
424
|
+
readonly input: InputSchema & RawFieldInputContract<Command, Fields, InputSchema>;
|
|
425
|
+
readonly success: Readonly<{
|
|
426
|
+
readonly kind: "stream";
|
|
427
|
+
readonly records: Records & StreamRecordDefinitions<TextEnabled> & ClosedStreamRecords<Records> & StreamRecordNameContract<Records>;
|
|
428
|
+
}> & (TextEnabled extends true ? Readonly<{
|
|
429
|
+
readonly text: CompletionTextPresenter;
|
|
430
|
+
}> : TextEnabled extends false ? Readonly<{
|
|
431
|
+
readonly text?: never;
|
|
432
|
+
}> : Readonly<{
|
|
433
|
+
readonly text?: CompletionTextPresenter;
|
|
434
|
+
}>);
|
|
435
|
+
readonly failures: Failures & ClosedAtomicVariants<Failures> & FailureVariantNameContract<Failures>;
|
|
436
|
+
readonly handler: (context: StreamHandlerContext<Command, Dependencies, ContractSchemaOutput<InputSchema>, Records, Failures>) => AsyncGenerator<StreamRecordFactUnion<Command, Records>, StreamSuccessFact<Command> | FailureFactUnion<Command, Failures>, void>;
|
|
437
|
+
}
|
|
438
|
+
export type RootCommandDefinition<Command extends string, Dependencies> = CompletionRootCommandDefinition<Command, Dependencies, FailureVariantDefinitions, FieldDefinitions, ContractSchema> | DataRootCommandDefinition<Command, Dependencies, FieldDefinitions, ContractSchema, DataVariantDefinitions, FailureVariantDefinitions> | StreamRootCommandDefinition<Command, Dependencies, FieldDefinitions, ContractSchema, StreamRecordDefinitions, FailureVariantDefinitions>;
|
|
439
|
+
export interface RootGroupDefinition {
|
|
440
|
+
readonly kind: "rootGroup";
|
|
441
|
+
readonly parent?: never;
|
|
442
|
+
readonly name: string;
|
|
443
|
+
readonly aliases?: readonly string[];
|
|
444
|
+
readonly description: string;
|
|
445
|
+
readonly helpSupplement?: TextLines;
|
|
446
|
+
readonly handler?: never;
|
|
447
|
+
}
|
|
448
|
+
export interface CommandGroupDefinition<Parent extends string = string> {
|
|
449
|
+
readonly kind: "commandGroup";
|
|
450
|
+
readonly parent: Parent;
|
|
451
|
+
readonly name: string;
|
|
452
|
+
readonly aliases?: readonly string[];
|
|
453
|
+
readonly description: string;
|
|
454
|
+
readonly helpSupplement?: TextLines;
|
|
455
|
+
readonly handler?: never;
|
|
456
|
+
}
|
|
457
|
+
type HierarchyCommandFacts<Parent extends string = string> = Readonly<{
|
|
458
|
+
readonly kind: "command";
|
|
459
|
+
readonly parent: Parent;
|
|
460
|
+
readonly aliases?: readonly string[];
|
|
461
|
+
readonly helpSupplement?: TextLines;
|
|
462
|
+
readonly [executableCommandType]: true;
|
|
463
|
+
}>;
|
|
464
|
+
export type ExecutableCommandDefinition<Command extends string = string, Dependencies = unknown> = (Omit<CompletionRootCommandDefinition<Command, Dependencies, FailureVariantDefinitions, FieldDefinitions, ContractSchema>, "kind"> & HierarchyCommandFacts) | (Omit<DataRootCommandDefinition<Command, Dependencies, FieldDefinitions, ContractSchema, DataVariantDefinitions, FailureVariantDefinitions>, "kind"> & HierarchyCommandFacts) | (Omit<StreamRootCommandDefinition<Command, Dependencies, FieldDefinitions, ContractSchema, StreamRecordDefinitions, FailureVariantDefinitions>, "kind"> & HierarchyCommandFacts);
|
|
465
|
+
export type CommandNodeDefinition = CommandGroupDefinition | (HierarchyCommandFacts & Readonly<{
|
|
466
|
+
readonly name: string;
|
|
467
|
+
readonly description: string;
|
|
468
|
+
readonly fields?: unknown;
|
|
469
|
+
readonly input: ContractSchema;
|
|
470
|
+
readonly success: Readonly<{
|
|
471
|
+
readonly kind: "completion";
|
|
472
|
+
}> | Readonly<{
|
|
473
|
+
readonly kind: "data";
|
|
474
|
+
readonly variants: DataVariantDefinitions;
|
|
475
|
+
}> | Readonly<{
|
|
476
|
+
readonly kind: "stream";
|
|
477
|
+
readonly records: StreamRecordDefinitions;
|
|
478
|
+
readonly text?: CompletionTextPresenter;
|
|
479
|
+
}>;
|
|
480
|
+
readonly failures: FailureVariantDefinitions;
|
|
481
|
+
readonly handler: unknown;
|
|
482
|
+
}>) | RootGroupDefinition;
|
|
483
|
+
export type HierarchyCliDefinition<Root extends string> = RootCliDefinitionBase<Root> & Readonly<{
|
|
484
|
+
readonly commands: Readonly<Record<string, CommandNodeDefinition>> & Readonly<Record<Root, RootGroupDefinition>>;
|
|
485
|
+
}>;
|
|
486
|
+
type HierarchyRawInput<Commands> = {
|
|
487
|
+
[Command in keyof Commands]: Commands[Command] extends Readonly<{
|
|
488
|
+
readonly kind: "command";
|
|
489
|
+
}> ? RawFieldInput<HierarchyCommandFields<Commands[Command]>> : never;
|
|
490
|
+
}[keyof Commands];
|
|
491
|
+
type HierarchyResult<Commands> = {
|
|
492
|
+
[Command in keyof Commands]: Commands[Command] extends Readonly<{
|
|
493
|
+
readonly kind: "command";
|
|
494
|
+
readonly success: Readonly<{
|
|
495
|
+
readonly kind: "data";
|
|
496
|
+
readonly variants: infer Variants extends DataVariantDefinitions;
|
|
497
|
+
}>;
|
|
498
|
+
readonly failures: infer Failures extends FailureVariantDefinitions;
|
|
499
|
+
}> ? DataFactUnion<Extract<Command, string>, Variants> | FailureFactUnion<Extract<Command, string>, Failures> : Commands[Command] extends Readonly<{
|
|
500
|
+
readonly kind: "command";
|
|
501
|
+
readonly success: Readonly<{
|
|
502
|
+
readonly kind: "completion";
|
|
503
|
+
}>;
|
|
504
|
+
readonly failures: infer Failures extends FailureVariantDefinitions;
|
|
505
|
+
}> ? CompletionFact<Extract<Command, string>> | FailureFactUnion<Extract<Command, string>, Failures> : Commands[Command] extends Readonly<{
|
|
506
|
+
readonly kind: "command";
|
|
507
|
+
readonly success: Readonly<{
|
|
508
|
+
readonly kind: "stream";
|
|
509
|
+
readonly records: StreamRecordDefinitions;
|
|
510
|
+
}>;
|
|
511
|
+
readonly failures: infer Failures extends FailureVariantDefinitions;
|
|
512
|
+
}> ? StreamSuccessFact<Extract<Command, string>> | FailureFactUnion<Extract<Command, string>, Failures> : never;
|
|
513
|
+
}[keyof Commands];
|
|
514
|
+
type HierarchyCommandFields<Node> = Node extends Readonly<{
|
|
515
|
+
readonly kind: "command" | "rootCommand";
|
|
516
|
+
readonly fields: infer Fields extends FieldDefinitions;
|
|
517
|
+
}> ? Fields : Readonly<Record<never, never>>;
|
|
518
|
+
type KnownInputKeys<Input> = string extends keyof Input ? never : Extract<keyof Input, string>;
|
|
519
|
+
type EffectiveFieldSetMismatch<Fields, Input> = Exclude<Extract<keyof Fields, string>, KnownInputKeys<Input>> | Exclude<KnownInputKeys<Input>, Extract<keyof Fields, string>>;
|
|
520
|
+
type IncompatibleRawInputIssues<Command extends string, Fields extends FieldDefinitions, Input> = {
|
|
521
|
+
[Field in IncompatibleRawInputKeys<Fields, Input>]: ContractTypeError<"fieldInputMustAcceptRawValue", Readonly<{
|
|
522
|
+
readonly command: Command;
|
|
523
|
+
readonly field: Field;
|
|
524
|
+
readonly rawValue: RawSchemaInputValue<Fields[Field]>;
|
|
525
|
+
readonly schemaInput: Field extends keyof Input ? Input[Field] : never;
|
|
526
|
+
}>>;
|
|
527
|
+
}[IncompatibleRawInputKeys<Fields, Input>];
|
|
528
|
+
type HierarchyInputIssues<Commands> = {
|
|
529
|
+
[Command in keyof Commands & string]: Commands[Command] extends Readonly<{
|
|
530
|
+
readonly kind: "command";
|
|
531
|
+
readonly input: infer InputSchema extends ContractSchema;
|
|
532
|
+
}> ? EffectiveFieldSetMismatch<HierarchyCommandFields<Commands[Command]>, ContractSchemaInput<InputSchema>> extends never ? IncompatibleRawInputKeys<HierarchyCommandFields<Commands[Command]>, ContractSchemaInput<InputSchema>> extends never ? never : IncompatibleRawInputIssues<Command, HierarchyCommandFields<Commands[Command]>, ContractSchemaInput<InputSchema>> : ContractTypeError<"fieldSetDoesNotMatchSchemaInput", Readonly<{
|
|
533
|
+
readonly command: Command;
|
|
534
|
+
readonly fieldsWithoutSchemaInput: Exclude<keyof HierarchyCommandFields<Commands[Command]> & string, KnownInputKeys<ContractSchemaInput<InputSchema>>>;
|
|
535
|
+
readonly schemaInputWithoutFields: Exclude<KnownInputKeys<ContractSchemaInput<InputSchema>>, keyof HierarchyCommandFields<Commands[Command]>>;
|
|
536
|
+
}>> : never;
|
|
537
|
+
}[keyof Commands & string];
|
|
538
|
+
type HierarchyUsageConstraints<Node> = Node extends Readonly<{
|
|
539
|
+
readonly usageConstraints?: infer Constraints;
|
|
540
|
+
}> ? Exclude<Constraints, undefined> : never;
|
|
541
|
+
type UsageConstraintValueFields<Values> = Values extends readonly (infer Value)[] ? Value extends Readonly<{
|
|
542
|
+
readonly field: infer Field extends string;
|
|
543
|
+
}> ? Field : never : never;
|
|
544
|
+
type InvalidForbiddenCombinationValue<Command extends string, Value, Fields extends FieldDefinitions> = Value extends Readonly<{
|
|
545
|
+
readonly field: infer Field extends keyof Fields & string;
|
|
546
|
+
readonly value: infer Actual;
|
|
547
|
+
}> ? Fields[Field] extends FlagDefinition ? Actual extends boolean ? never : ContractTypeError<"invalidUsageConstraintValue", Readonly<{
|
|
548
|
+
readonly command: Command;
|
|
549
|
+
readonly constraint: "forbiddenCombination";
|
|
550
|
+
readonly member: "values.value";
|
|
551
|
+
readonly field: Field;
|
|
552
|
+
readonly actual: Actual;
|
|
553
|
+
readonly expected: boolean;
|
|
554
|
+
}>> : Fields[Field] extends ValueOptionDefinition ? Actual extends string ? never : ContractTypeError<"invalidUsageConstraintValue", Readonly<{
|
|
555
|
+
readonly command: Command;
|
|
556
|
+
readonly constraint: "forbiddenCombination";
|
|
557
|
+
readonly member: "values.value";
|
|
558
|
+
readonly field: Field;
|
|
559
|
+
readonly actual: Actual;
|
|
560
|
+
readonly expected: string;
|
|
561
|
+
}>> : ContractTypeError<"inapplicableUsageConstraintField", Readonly<{
|
|
562
|
+
readonly command: Command;
|
|
563
|
+
readonly constraint: "forbiddenCombination";
|
|
564
|
+
readonly member: "values.field";
|
|
565
|
+
readonly field: Field;
|
|
566
|
+
readonly kind: Fields[Field]["kind"];
|
|
567
|
+
}>> : never;
|
|
568
|
+
type InvalidForbiddenCombinationValues<Command extends string, Values extends readonly unknown[], Fields extends FieldDefinitions> = InvalidForbiddenCombinationValue<Command, Values[number], Fields>;
|
|
569
|
+
type InvalidUsageConstraintForFields<Command extends string, Constraint, Fields extends FieldDefinitions> = Constraint extends Readonly<{
|
|
570
|
+
readonly kind: "requires";
|
|
571
|
+
readonly field: infer Field extends string;
|
|
572
|
+
readonly requires: infer Required extends string;
|
|
573
|
+
}> ? Exclude<Field, keyof Fields> extends never ? Exclude<Required, keyof Fields> extends never ? never : ContractTypeError<"unknownUsageConstraintField", Readonly<{
|
|
574
|
+
readonly command: Command;
|
|
575
|
+
readonly constraint: "requires";
|
|
576
|
+
readonly member: "requires";
|
|
577
|
+
readonly field: Exclude<Required, keyof Fields>;
|
|
578
|
+
}>> : ContractTypeError<"unknownUsageConstraintField", Readonly<{
|
|
579
|
+
readonly command: Command;
|
|
580
|
+
readonly constraint: "requires";
|
|
581
|
+
readonly member: "field";
|
|
582
|
+
readonly field: Exclude<Field, keyof Fields>;
|
|
583
|
+
}>> : Constraint extends Readonly<{
|
|
584
|
+
readonly kind: "exclusive";
|
|
585
|
+
readonly fields: readonly (infer Field extends string)[];
|
|
586
|
+
}> ? Exclude<Field, keyof Fields> extends never ? never : ContractTypeError<"unknownUsageConstraintField", Readonly<{
|
|
587
|
+
readonly command: Command;
|
|
588
|
+
readonly constraint: "exclusive";
|
|
589
|
+
readonly member: "fields";
|
|
590
|
+
readonly field: Exclude<Field, keyof Fields>;
|
|
591
|
+
}>> : Constraint extends Readonly<{
|
|
592
|
+
readonly kind: "forbiddenCombination";
|
|
593
|
+
readonly values: infer Values extends readonly unknown[];
|
|
594
|
+
}> ? Exclude<UsageConstraintValueFields<Values>, keyof Fields> extends never ? [
|
|
595
|
+
InvalidForbiddenCombinationValues<Command, Values, Fields>
|
|
596
|
+
] extends [never] ? Constraint extends ForbiddenCombinationUsageConstraint<Fields> ? never : ContractTypeError<"invalidUsageConstraint", Readonly<{
|
|
597
|
+
readonly command: Command;
|
|
598
|
+
readonly constraint: "forbiddenCombination";
|
|
599
|
+
readonly member: "values";
|
|
600
|
+
}>> : InvalidForbiddenCombinationValues<Command, Values, Fields> : ContractTypeError<"unknownUsageConstraintField", Readonly<{
|
|
601
|
+
readonly command: Command;
|
|
602
|
+
readonly constraint: "forbiddenCombination";
|
|
603
|
+
readonly member: "values.field";
|
|
604
|
+
readonly field: Exclude<UsageConstraintValueFields<Values>, keyof Fields>;
|
|
605
|
+
}>> : ContractTypeError<"invalidEffectiveUsageConstraint", Readonly<{
|
|
606
|
+
readonly command: Command;
|
|
607
|
+
}>>;
|
|
608
|
+
type InvalidCommandUsageConstraintIssues<Commands> = {
|
|
609
|
+
[Command in keyof Commands & string]: Commands[Command] extends Readonly<{
|
|
610
|
+
readonly kind: "command" | "rootCommand";
|
|
611
|
+
}> ? HierarchyUsageConstraints<Commands[Command]> extends never ? never : HierarchyUsageConstraints<Commands[Command]> extends readonly (infer Constraint)[] ? InvalidUsageConstraintForFields<Command, Constraint, HierarchyCommandFields<Commands[Command]>> extends never ? never : InvalidUsageConstraintForFields<Command, Constraint, HierarchyCommandFields<Commands[Command]>> : ContractTypeError<"invalidEffectiveUsageConstraint", Readonly<{
|
|
612
|
+
readonly command: Command;
|
|
613
|
+
}>> : never;
|
|
614
|
+
}[keyof Commands & string];
|
|
615
|
+
type RootIdentityContract<Root extends string> = string extends Root ? unknown : IsLowerCamelCase<Root> extends true ? unknown : ContractTypeError<"commandMustBeLowerCamelCase", Readonly<{
|
|
616
|
+
readonly command: Root;
|
|
617
|
+
}>>;
|
|
618
|
+
type RootCliDefinitionBase<Root extends string> = RootIdentityContract<Root> & {
|
|
619
|
+
readonly root: Root;
|
|
620
|
+
readonly help: HelpCapability;
|
|
621
|
+
readonly version?: VersionCapability;
|
|
622
|
+
readonly output: OutputCapability;
|
|
623
|
+
readonly usageFailureExitCode: number;
|
|
624
|
+
};
|
|
625
|
+
export type CompletionRootCliDefinition<Root extends string, Dependencies, Failures extends FailureVariantDefinitions = Readonly<Record<never, never>>, Fields extends FieldDefinitions = Readonly<Record<never, never>>, InputSchema extends ContractSchema = ContractSchema<EmptyCliInput>, TextEnabled extends boolean = boolean> = RootCliDefinitionBase<Root> & Readonly<{
|
|
626
|
+
readonly commands: Readonly<{
|
|
627
|
+
readonly [Command in Root]: CompletionRootCommandDefinition<Command, Dependencies, Failures, Fields, InputSchema, TextEnabled>;
|
|
628
|
+
}>;
|
|
629
|
+
}>;
|
|
630
|
+
export type DataRootCliDefinition<Root extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, Variants extends DataVariantDefinitions, Failures extends FailureVariantDefinitions> = RootCliDefinitionBase<Root> & Readonly<{
|
|
631
|
+
readonly commands: Readonly<{
|
|
632
|
+
readonly [Command in Root]: DataRootCommandDefinition<Command, Dependencies, Fields, InputSchema, Variants, Failures>;
|
|
633
|
+
}>;
|
|
634
|
+
}>;
|
|
635
|
+
export type StreamRootCliDefinition<Root extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions, TextEnabled extends boolean = boolean> = RootCliDefinitionBase<Root> & Readonly<{
|
|
636
|
+
readonly commands: Readonly<{
|
|
637
|
+
readonly [Command in Root]: StreamRootCommandDefinition<Command, Dependencies, Fields, InputSchema, Records, Failures, TextEnabled>;
|
|
638
|
+
}>;
|
|
639
|
+
}>;
|
|
640
|
+
export type RootCliDefinition<Root extends string, Dependencies> = CompletionRootCliDefinition<Root, Dependencies, FailureVariantDefinitions, FieldDefinitions, ContractSchema> | DataRootCliDefinition<Root, Dependencies, FieldDefinitions, ContractSchema, DataVariantDefinitions, FailureVariantDefinitions> | StreamRootCliDefinition<Root, Dependencies, FieldDefinitions, ContractSchema, StreamRecordDefinitions, FailureVariantDefinitions>;
|
|
641
|
+
interface FieldGrammarBase<Field extends string> {
|
|
642
|
+
readonly key: Field;
|
|
643
|
+
readonly description: string;
|
|
644
|
+
readonly required: boolean;
|
|
645
|
+
readonly default?: JsonValue;
|
|
646
|
+
readonly choices?: readonly string[];
|
|
647
|
+
}
|
|
648
|
+
export interface PositionalGrammar<Field extends string = string> extends FieldGrammarBase<Field> {
|
|
649
|
+
readonly kind: "positional";
|
|
650
|
+
}
|
|
651
|
+
export interface VariadicPositionalGrammar<Field extends string = string> extends FieldGrammarBase<Field> {
|
|
652
|
+
readonly kind: "variadicPositional";
|
|
653
|
+
}
|
|
654
|
+
export interface FlagGrammar<Field extends string = string> extends FieldGrammarBase<Field> {
|
|
655
|
+
readonly kind: "flag";
|
|
656
|
+
readonly longOption: CanonicalLongOption<string>;
|
|
657
|
+
readonly shortAlias?: ShortOptionAlias<string>;
|
|
658
|
+
readonly negatedLongOption?: CanonicalLongOption<string>;
|
|
659
|
+
}
|
|
660
|
+
export interface RepeatableOptionGrammar<Field extends string = string> extends FieldGrammarBase<Field> {
|
|
661
|
+
readonly kind: "repeatableOption";
|
|
662
|
+
readonly longOption: CanonicalLongOption<string>;
|
|
663
|
+
readonly shortAlias?: ShortOptionAlias<string>;
|
|
664
|
+
}
|
|
665
|
+
export interface ValueOptionGrammar<Field extends string = string> extends FieldGrammarBase<Field> {
|
|
666
|
+
readonly kind: "valueOption";
|
|
667
|
+
readonly longOption: CanonicalLongOption<string>;
|
|
668
|
+
readonly shortAlias?: ShortOptionAlias<string>;
|
|
669
|
+
}
|
|
670
|
+
export type FieldGrammar<Field extends string = string> = FlagGrammar<Field> | PositionalGrammar<Field> | RepeatableOptionGrammar<Field> | VariadicPositionalGrammar<Field> | ValueOptionGrammar<Field>;
|
|
671
|
+
export interface RootCommandGrammar<Root extends string> {
|
|
672
|
+
readonly kind: "rootCommand";
|
|
673
|
+
readonly id: Root;
|
|
674
|
+
readonly name: string;
|
|
675
|
+
readonly description: string;
|
|
676
|
+
readonly helpSupplement?: readonly string[];
|
|
677
|
+
readonly fields: readonly FieldGrammar[];
|
|
678
|
+
readonly usageConstraints?: readonly UsageConstraintGrammar[];
|
|
679
|
+
readonly usage: CommandUsage<Root>;
|
|
680
|
+
}
|
|
681
|
+
interface GroupGrammarBase<Command extends string> {
|
|
682
|
+
readonly id: Command;
|
|
683
|
+
readonly name: string;
|
|
684
|
+
readonly aliases: readonly string[];
|
|
685
|
+
readonly description: string;
|
|
686
|
+
readonly helpSupplement?: readonly string[];
|
|
687
|
+
readonly usage: CommandUsage<Command>;
|
|
688
|
+
}
|
|
689
|
+
export interface RootGroupGrammar<Root extends string> extends GroupGrammarBase<Root> {
|
|
690
|
+
readonly kind: "rootGroup";
|
|
691
|
+
}
|
|
692
|
+
export interface CommandGroupGrammar<Command extends string = string> extends GroupGrammarBase<Command> {
|
|
693
|
+
readonly kind: "commandGroup";
|
|
694
|
+
readonly parent: string;
|
|
695
|
+
}
|
|
696
|
+
export interface ExecutableCommandGrammar<Command extends string = string> extends GroupGrammarBase<Command> {
|
|
697
|
+
readonly kind: "command";
|
|
698
|
+
readonly parent: string;
|
|
699
|
+
readonly fields: readonly FieldGrammar[];
|
|
700
|
+
readonly usageConstraints?: readonly UsageConstraintGrammar[];
|
|
701
|
+
}
|
|
702
|
+
export type CommandGrammar<Command extends string = string> = CommandGroupGrammar<Command> | ExecutableCommandGrammar<Command>;
|
|
703
|
+
export type CliRootKind = "rootCommand" | "rootGroup";
|
|
704
|
+
export interface CliGrammar<Root extends string, RootKind extends CliRootKind = CliRootKind> {
|
|
705
|
+
readonly root: RootKind extends "rootGroup" ? RootGroupGrammar<Root> : RootCommandGrammar<Root>;
|
|
706
|
+
readonly nodes: RootKind extends "rootGroup" ? readonly CommandGrammar[] : readonly [];
|
|
707
|
+
readonly controls: Readonly<{
|
|
708
|
+
readonly help: Readonly<{
|
|
709
|
+
readonly longOption: "--help";
|
|
710
|
+
readonly shortAlias?: "-h";
|
|
711
|
+
readonly headings?: HelpHeadings;
|
|
712
|
+
readonly wording?: HelpFactWording;
|
|
713
|
+
}>;
|
|
714
|
+
readonly version?: Readonly<{
|
|
715
|
+
readonly longOption: "--version";
|
|
716
|
+
readonly shortAlias?: "-V";
|
|
717
|
+
readonly value: string;
|
|
718
|
+
readonly description?: string;
|
|
719
|
+
}>;
|
|
720
|
+
readonly output: Readonly<{
|
|
721
|
+
readonly defaultFormat: OutputFormat;
|
|
722
|
+
readonly formats: readonly OutputFormat[];
|
|
723
|
+
readonly selector?: "--output-format";
|
|
724
|
+
readonly compatibilityFlags?: Readonly<Record<string, OutputFormat>>;
|
|
725
|
+
}>;
|
|
726
|
+
}>;
|
|
727
|
+
}
|
|
728
|
+
export interface SchemaManifest {
|
|
729
|
+
readonly inputSchema: JsonObject;
|
|
730
|
+
readonly outputSchema: JsonObject;
|
|
731
|
+
}
|
|
732
|
+
export interface DataVariantManifest extends SchemaManifest {
|
|
733
|
+
readonly description: string;
|
|
734
|
+
readonly exitCode: number;
|
|
735
|
+
}
|
|
736
|
+
export type FailureVariantManifest = DataVariantManifest;
|
|
737
|
+
export type CommandSuccessManifest = Readonly<{
|
|
738
|
+
readonly kind: "completion";
|
|
739
|
+
}> | Readonly<{
|
|
740
|
+
readonly kind: "data";
|
|
741
|
+
readonly variants: Readonly<Record<string, DataVariantManifest>>;
|
|
742
|
+
}> | Readonly<{
|
|
743
|
+
readonly kind: "stream";
|
|
744
|
+
readonly records: Readonly<Record<string, StreamRecordManifest>>;
|
|
745
|
+
readonly text?: Readonly<{
|
|
746
|
+
readonly recordFraming: "fragment";
|
|
747
|
+
}>;
|
|
748
|
+
}>;
|
|
749
|
+
export interface RootCommandManifest {
|
|
750
|
+
readonly kind: "rootCommand";
|
|
751
|
+
readonly name: string;
|
|
752
|
+
readonly description: string;
|
|
753
|
+
readonly helpSupplement?: readonly string[];
|
|
754
|
+
readonly fields: readonly FieldGrammar[];
|
|
755
|
+
readonly usageConstraints?: readonly UsageConstraintGrammar[];
|
|
756
|
+
readonly input: SchemaManifest;
|
|
757
|
+
readonly success: CommandSuccessManifest;
|
|
758
|
+
readonly failures: Readonly<Record<string, FailureVariantManifest>>;
|
|
759
|
+
}
|
|
760
|
+
export interface CommandGroupManifest {
|
|
761
|
+
readonly kind: "rootGroup" | "commandGroup";
|
|
762
|
+
readonly parent?: string;
|
|
763
|
+
readonly name: string;
|
|
764
|
+
readonly aliases: readonly string[];
|
|
765
|
+
readonly description: string;
|
|
766
|
+
readonly helpSupplement?: readonly string[];
|
|
767
|
+
}
|
|
768
|
+
export interface ExecutableCommandManifest extends Omit<RootCommandManifest, "kind"> {
|
|
769
|
+
readonly kind: "command";
|
|
770
|
+
readonly parent: string;
|
|
771
|
+
readonly aliases: readonly string[];
|
|
772
|
+
readonly helpSupplement?: readonly string[];
|
|
773
|
+
}
|
|
774
|
+
export type UsageConstraintGrammar = RequiresUsageConstraint | ExclusiveUsageConstraint | ForbiddenCombinationUsageConstraint;
|
|
775
|
+
export interface CliManifest<Root extends string, RootKind extends CliRootKind = CliRootKind> {
|
|
776
|
+
readonly schemaVersion: "3";
|
|
777
|
+
readonly root: Root;
|
|
778
|
+
readonly commands: RootKind extends "rootGroup" ? Readonly<Record<string, CommandGroupManifest | ExecutableCommandManifest>> : Readonly<Record<Root, RootCommandManifest>>;
|
|
779
|
+
readonly controls: CliGrammar<Root, RootKind>["controls"];
|
|
780
|
+
readonly usageFailure: Readonly<{
|
|
781
|
+
readonly exitCode: number;
|
|
782
|
+
readonly wire: JsonObject;
|
|
783
|
+
}>;
|
|
784
|
+
readonly wire: RootKind extends "rootGroup" ? Readonly<Record<string, CommandWireManifest>> : CommandWireManifest;
|
|
785
|
+
}
|
|
786
|
+
export interface CommandWireManifest {
|
|
787
|
+
readonly completion?: JsonObject;
|
|
788
|
+
readonly data?: Readonly<Record<string, JsonObject>>;
|
|
789
|
+
readonly failure?: Readonly<Record<string, JsonObject>>;
|
|
790
|
+
readonly stream?: Readonly<{
|
|
791
|
+
readonly header: JsonObject;
|
|
792
|
+
readonly records: Readonly<Record<string, JsonObject>>;
|
|
793
|
+
readonly terminal: JsonObject;
|
|
794
|
+
readonly line: JsonObject;
|
|
795
|
+
}>;
|
|
796
|
+
}
|
|
797
|
+
type HierarchyGrammarNode<Command extends string, Node> = Node extends Readonly<{
|
|
798
|
+
readonly kind: "commandGroup";
|
|
799
|
+
readonly parent: infer Parent extends string;
|
|
800
|
+
}> ? CommandGroupGrammar<Command> & Readonly<{
|
|
801
|
+
readonly parent: Parent;
|
|
802
|
+
}> : Node extends Readonly<{
|
|
803
|
+
readonly kind: "command";
|
|
804
|
+
readonly parent: infer Parent extends string;
|
|
805
|
+
}> ? ExecutableCommandGrammar<Command> & Readonly<{
|
|
806
|
+
readonly parent: Parent;
|
|
807
|
+
}> : never;
|
|
808
|
+
type HierarchyNodeUnion<Commands, Root extends string> = {
|
|
809
|
+
[Command in Exclude<keyof Commands, Root>]: HierarchyGrammarNode<Extract<Command, string>, Commands[Command]>;
|
|
810
|
+
}[Exclude<keyof Commands, Root>];
|
|
811
|
+
export interface HierarchyCliGrammar<Root extends string, Commands> {
|
|
812
|
+
readonly root: RootGroupGrammar<Root>;
|
|
813
|
+
readonly nodes: readonly HierarchyNodeUnion<Commands, Root>[];
|
|
814
|
+
readonly controls: CliGrammar<Root, "rootGroup">["controls"];
|
|
815
|
+
}
|
|
816
|
+
type HierarchyManifestNode<Node> = Node extends Readonly<{
|
|
817
|
+
readonly kind: "rootGroup";
|
|
818
|
+
}> ? CommandGroupManifest & Readonly<{
|
|
819
|
+
readonly kind: "rootGroup";
|
|
820
|
+
}> : Node extends Readonly<{
|
|
821
|
+
readonly kind: "commandGroup";
|
|
822
|
+
readonly parent: infer Parent extends string;
|
|
823
|
+
}> ? CommandGroupManifest & Readonly<{
|
|
824
|
+
readonly kind: "commandGroup";
|
|
825
|
+
readonly parent: Parent;
|
|
826
|
+
}> : Node extends Readonly<{
|
|
827
|
+
readonly kind: "command";
|
|
828
|
+
readonly parent: infer Parent extends string;
|
|
829
|
+
}> ? ExecutableCommandManifest & Readonly<{
|
|
830
|
+
readonly parent: Parent;
|
|
831
|
+
}> : never;
|
|
832
|
+
type HierarchyExecutableKeys<Commands> = {
|
|
833
|
+
[Command in keyof Commands]: Commands[Command] extends Readonly<{
|
|
834
|
+
readonly kind: "command";
|
|
835
|
+
}> ? Command : never;
|
|
836
|
+
}[keyof Commands];
|
|
837
|
+
export interface HierarchyCliManifest<Root extends string, Commands> {
|
|
838
|
+
readonly schemaVersion: "3";
|
|
839
|
+
readonly root: Root;
|
|
840
|
+
readonly commands: Readonly<{
|
|
841
|
+
[Command in keyof Commands]: HierarchyManifestNode<Commands[Command]>;
|
|
842
|
+
}>;
|
|
843
|
+
readonly controls: HierarchyCliGrammar<Root, Commands>["controls"];
|
|
844
|
+
readonly usageFailure: Readonly<{
|
|
845
|
+
readonly exitCode: number;
|
|
846
|
+
readonly wire: JsonObject;
|
|
847
|
+
}>;
|
|
848
|
+
readonly wire: Readonly<{
|
|
849
|
+
[Command in HierarchyExecutableKeys<Commands>]: CommandWireManifest;
|
|
850
|
+
}>;
|
|
851
|
+
}
|
|
852
|
+
export interface CliContract<Root extends string = string, Dependencies = unknown, RawInput = Readonly<Record<string, unknown>>, Result extends OutcomeFact = OutcomeFact, RootKind extends CliRootKind = CliRootKind, Commands = never> {
|
|
853
|
+
readonly grammar: [Commands] extends [never] ? CliGrammar<Root, RootKind> : HierarchyCliGrammar<Root, Commands>;
|
|
854
|
+
readonly manifest: [Commands] extends [never] ? CliManifest<Root, RootKind> : HierarchyCliManifest<Root, Commands>;
|
|
855
|
+
readonly [cliContractType]: Readonly<{
|
|
856
|
+
readonly dependencies: Dependencies;
|
|
857
|
+
readonly rawInput: RawInput;
|
|
858
|
+
readonly result: Result;
|
|
859
|
+
readonly root: Root;
|
|
860
|
+
readonly commands: [Commands] extends [never] ? Root : keyof Commands;
|
|
861
|
+
}>;
|
|
862
|
+
}
|
|
863
|
+
export type CliContractDependencies<Contract> = Contract extends CliContract<infer _Root, infer Dependencies, unknown, OutcomeFact, CliRootKind, infer _Commands> ? Dependencies : never;
|
|
864
|
+
export type CliContractRawInput<Contract> = Contract extends CliContract<infer _Root, unknown, infer RawInput, OutcomeFact, CliRootKind, infer _Commands> ? RawInput : never;
|
|
865
|
+
export type CliContractResult<Contract> = Contract extends CliContract<infer _Root, unknown, unknown, infer Result, CliRootKind, infer _Commands> ? Result : never;
|
|
866
|
+
export type CliContractRoot<Contract> = Contract extends CliContract<infer Root, unknown, unknown, OutcomeFact, CliRootKind, infer Commands> ? [Commands] extends [never] ? Root : Extract<keyof Commands, string> : never;
|
|
867
|
+
type HasTextPresenter<Value> = Value extends Readonly<{
|
|
868
|
+
readonly text: unknown;
|
|
869
|
+
}> ? true : false;
|
|
870
|
+
type PresentTextVariants<Variants> = {
|
|
871
|
+
[Variant in keyof Variants & string]: HasTextPresenter<Variants[Variant]> extends true ? Variant : never;
|
|
872
|
+
}[keyof Variants & string];
|
|
873
|
+
type UnexpectedVariantTextIssue<Command extends string, Location extends "data" | "failure" | "record", Variants> = [PresentTextVariants<Variants>] extends [never] ? never : ContractTypeError<"unexpectedTextPresenter", Readonly<{
|
|
874
|
+
readonly command: Command;
|
|
875
|
+
readonly location: Location;
|
|
876
|
+
readonly variant: PresentTextVariants<Variants>;
|
|
877
|
+
readonly unexpected: "text";
|
|
878
|
+
}>>;
|
|
879
|
+
type UnexpectedSuccessTextIssue<Command extends string, Location extends "completion" | "streamSuccess", Success> = HasTextPresenter<Success> extends true ? ContractTypeError<"unexpectedTextPresenter", Readonly<{
|
|
880
|
+
readonly command: Command;
|
|
881
|
+
readonly location: Location;
|
|
882
|
+
readonly unexpected: "text";
|
|
883
|
+
}>> : never;
|
|
884
|
+
type UnexpectedHierarchyTextIssues<Commands> = {
|
|
885
|
+
[Command in keyof Commands & string]: Commands[Command] extends Readonly<{
|
|
886
|
+
readonly kind: "command" | "rootCommand";
|
|
887
|
+
readonly success: infer Success;
|
|
888
|
+
readonly failures: infer Failures;
|
|
889
|
+
}> ? Success extends Readonly<{
|
|
890
|
+
readonly kind: "completion";
|
|
891
|
+
}> ? UnexpectedSuccessTextIssue<Command, "completion", Success> | UnexpectedVariantTextIssue<Command, "failure", Failures> : Success extends Readonly<{
|
|
892
|
+
readonly variants: infer Variants;
|
|
893
|
+
}> ? UnexpectedVariantTextIssue<Command, "data", Variants> | UnexpectedVariantTextIssue<Command, "failure", Failures> : Success extends Readonly<{
|
|
894
|
+
readonly kind: "stream";
|
|
895
|
+
readonly records: infer Records;
|
|
896
|
+
}> ? UnexpectedSuccessTextIssue<Command, "streamSuccess", Success> | UnexpectedVariantTextIssue<Command, "record", Records> | UnexpectedVariantTextIssue<Command, "failure", Failures> : never : never;
|
|
897
|
+
}[keyof Commands & string];
|
|
898
|
+
type HierarchyUsageValidation<Commands> = [
|
|
899
|
+
InvalidCommandUsageConstraintIssues<Commands>
|
|
900
|
+
] extends [never] ? [HierarchyInputIssues<Commands>] extends [never] ? readonly [] : readonly [HierarchyInputIssues<Commands>] : readonly [InvalidCommandUsageConstraintIssues<Commands>];
|
|
901
|
+
type HierarchyCommandTextContract<Command extends string, Definition> = Definition extends Readonly<{
|
|
902
|
+
readonly success: infer Success;
|
|
903
|
+
readonly failures: infer Failures;
|
|
904
|
+
}> ? Success extends Readonly<{
|
|
905
|
+
readonly kind: "completion";
|
|
906
|
+
}> ? FailureVariantTextContract<Command, Failures, true> & (HasTextPresenter<Success> extends true ? unknown : ContractTypeError<"missingTextPresenter", Readonly<{
|
|
907
|
+
readonly command: Command;
|
|
908
|
+
readonly location: "completion";
|
|
909
|
+
readonly missing: "text";
|
|
910
|
+
}>>) : Success extends Readonly<{
|
|
911
|
+
readonly kind: "data";
|
|
912
|
+
readonly variants: infer Variants;
|
|
913
|
+
}> ? DataVariantTextContract<Command, Variants, true> & FailureVariantTextContract<Command, Failures, true> : Success extends Readonly<{
|
|
914
|
+
readonly kind: "stream";
|
|
915
|
+
readonly records: infer Records;
|
|
916
|
+
}> ? StreamRecordTextContract<Command, Records, true> & FailureVariantTextContract<Command, Failures, true> & (HasTextPresenter<Success> extends true ? unknown : ContractTypeError<"missingTextPresenter", Readonly<{
|
|
917
|
+
readonly command: Command;
|
|
918
|
+
readonly location: "streamSuccess";
|
|
919
|
+
readonly missing: "text";
|
|
920
|
+
}>>) : unknown : unknown;
|
|
921
|
+
type HierarchyTextIssues<Commands> = {
|
|
922
|
+
[Command in keyof Commands & string]: Commands[Command] extends HierarchyCommandTextContract<Command, Commands[Command]> ? never : HierarchyCommandTextContract<Command, Commands[Command]>;
|
|
923
|
+
}[keyof Commands & string];
|
|
924
|
+
type HierarchyTextValidation<Commands> = [
|
|
925
|
+
HierarchyTextIssues<Commands>
|
|
926
|
+
] extends [never] ? unknown : HierarchyTextIssues<Commands>;
|
|
927
|
+
type HierarchyOutputValidation<Commands, Output extends OutputCapability> = Output extends OutputCapability<infer Formats> ? [Formats] extends [readonly ["structured", "text"]] ? [HierarchyTextIssues<Commands>] extends [never] ? HierarchyUsageValidation<Commands> : readonly [HierarchyTextIssues<Commands>] : [Formats] extends [readonly ["structured"]] ? [UnexpectedHierarchyTextIssues<Commands>] extends [never] ? HierarchyUsageValidation<Commands> : readonly [UnexpectedHierarchyTextIssues<Commands>] : HierarchyUsageValidation<Commands> : HierarchyUsageValidation<Commands>;
|
|
928
|
+
type ValidationIntersection<Validation extends readonly unknown[]> = Validation extends readonly [] ? unknown : Validation extends readonly [infer Error] ? Error : never;
|
|
929
|
+
type HierarchyContract<Commands, Output extends OutputCapability> = [
|
|
930
|
+
TextEnabledForOutput<Output>
|
|
931
|
+
] extends [true] ? HierarchyTextValidation<Commands> & ValidationIntersection<HierarchyUsageValidation<Commands>> : ValidationIntersection<HierarchyOutputValidation<Commands, Output>>;
|
|
932
|
+
type TextEnabledForOutput<Output extends OutputCapability> = Output extends OutputCapability<infer Formats> ? [Formats] extends [never] ? boolean : [Formats] extends [readonly ["structured", "text"]] ? true : [Formats] extends [readonly ["structured"]] ? false : boolean : boolean;
|
|
933
|
+
type EmptyRawObject = Readonly<Record<never, never>>;
|
|
934
|
+
type DistributedInputStringKeys<Input> = Input extends unknown ? Extract<keyof Input, string> : never;
|
|
935
|
+
type MissingRootFallbackFieldsContract<Command extends string, InputSchema extends ContractSchema> = ContractTypeError<"fieldSetDoesNotMatchSchemaInput", Readonly<{
|
|
936
|
+
readonly command: Command;
|
|
937
|
+
readonly fieldsWithoutSchemaInput: never;
|
|
938
|
+
readonly schemaInputWithoutFields: DistributedInputStringKeys<ContractSchemaInput<InputSchema>>;
|
|
939
|
+
}>>;
|
|
940
|
+
type RootFallbackRawFieldInputContract<Command extends string, Fields extends FieldDefinitions, InputSchema extends ContractSchema> = FieldDefinitions extends Fields ? EmptyRawObject extends ContractSchemaInput<InputSchema> ? unknown : MissingRootFallbackFieldsContract<Command, InputSchema> : RawFieldInputContract<Command, Fields, InputSchema>;
|
|
941
|
+
type RootFallbackKind = "completion" | "data" | "stream";
|
|
942
|
+
type RootFallbackHandlerContext<Command extends string, Dependencies, InputSchema extends ContractSchema, Variants extends DataVariantDefinitions, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions, Kind extends RootFallbackKind> = {
|
|
943
|
+
readonly completion: CompletionHandlerContext<Command, Dependencies, Failures, ContractSchemaOutput<InputSchema>>;
|
|
944
|
+
readonly data: DataHandlerContext<Command, Dependencies, ContractSchemaOutput<InputSchema>, Variants, Failures>;
|
|
945
|
+
readonly stream: StreamHandlerContext<Command, Dependencies, ContractSchemaOutput<InputSchema>, Records, Failures>;
|
|
946
|
+
}[Kind];
|
|
947
|
+
type RootFallbackHandlerResult<Command extends string, Variants extends DataVariantDefinitions, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions, Kind extends RootFallbackKind> = {
|
|
948
|
+
readonly completion: CompletionFact<Command> | FailureFactUnion<Command, Failures> | Promise<CompletionFact<Command> | FailureFactUnion<Command, Failures>>;
|
|
949
|
+
readonly data: DataFactUnion<Command, Variants> | FailureFactUnion<Command, Failures> | Promise<DataFactUnion<Command, Variants> | FailureFactUnion<Command, Failures>>;
|
|
950
|
+
readonly stream: AsyncGenerator<StreamRecordFactUnion<Command, Records>, StreamSuccessFact<Command> | FailureFactUnion<Command, Failures>, void>;
|
|
951
|
+
}[Kind];
|
|
952
|
+
type RootNodeFromCommands<Root extends string, Commands> = Commands extends Readonly<Record<Root, infer Node>> ? Node : never;
|
|
953
|
+
type RootCommandRawInput<Root extends string, Commands> = RootNodeFromCommands<Root, Commands> extends Readonly<{
|
|
954
|
+
readonly fields: infer Fields extends FieldDefinitions;
|
|
955
|
+
}> ? RawFieldInput<Fields> : EmptyCliInput;
|
|
956
|
+
type RootCommandResult<Root extends string, Commands> = RootNodeFromCommands<Root, Commands> extends Readonly<{
|
|
957
|
+
readonly success: infer Success;
|
|
958
|
+
readonly failures: infer Failures extends FailureVariantDefinitions;
|
|
959
|
+
}> ? Success extends Readonly<{
|
|
960
|
+
readonly kind: "completion";
|
|
961
|
+
}> ? CompletionFact<Root> | FailureFactUnion<Root, Failures> : Success extends Readonly<{
|
|
962
|
+
readonly kind: "data";
|
|
963
|
+
readonly variants: infer Variants extends DataVariantDefinitions;
|
|
964
|
+
}> ? DataFactUnion<Root, Variants> | FailureFactUnion<Root, Failures> : Success extends Readonly<{
|
|
965
|
+
readonly kind: "stream";
|
|
966
|
+
}> ? StreamSuccessFact<Root> | FailureFactUnion<Root, Failures> : never : never;
|
|
967
|
+
type RootFallbackCliDefinition<Root extends string, _Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, VariantSchemas extends VariantSchemaMap, Variants, RecordSchemas extends VariantSchemaMap, Records, FailureSchemas extends VariantSchemaMap, Failures, TextEnabled extends boolean> = RootCliDefinitionBase<Root> & Readonly<{
|
|
968
|
+
readonly commands: Readonly<{
|
|
969
|
+
readonly [Command in Root]: Readonly<{
|
|
970
|
+
readonly kind: "rootCommand";
|
|
971
|
+
readonly name: string;
|
|
972
|
+
readonly description: string;
|
|
973
|
+
readonly helpSupplement?: TextLines;
|
|
974
|
+
readonly usageConstraints?: readonly UsageConstraint[];
|
|
975
|
+
}> & Readonly<{
|
|
976
|
+
readonly input: InputSchema & RootFallbackRawFieldInputContract<Command, Fields, InputSchema>;
|
|
977
|
+
readonly failures: Failures & FailureVariantDefinitionsForSchemas<FailureSchemas, boolean> & FailureVariantNameContract<Failures> & FailureVariantTextContract<Command, Failures, TextEnabled>;
|
|
978
|
+
}> & (Readonly<{
|
|
979
|
+
readonly fields: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
980
|
+
readonly success: Readonly<{
|
|
981
|
+
readonly kind: "data";
|
|
982
|
+
readonly variants: Variants & DataVariantDefinitionsForSchemas<VariantSchemas, boolean> & DataVariantNameContract<Variants> & DataVariantTextContract<Command, Variants, TextEnabled>;
|
|
983
|
+
}>;
|
|
984
|
+
}> | Readonly<{
|
|
985
|
+
readonly fields?: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
986
|
+
readonly success: CompletionSuccessDefinition<Root, TextEnabled>;
|
|
987
|
+
}> | Readonly<{
|
|
988
|
+
readonly fields?: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
989
|
+
readonly success: (Readonly<{
|
|
990
|
+
readonly kind: "stream";
|
|
991
|
+
readonly records: Records & StreamRecordDefinitionsForSchemas<RecordSchemas, boolean> & StreamRecordNameContract<Records>;
|
|
992
|
+
readonly text: CompletionTextPresenter;
|
|
993
|
+
}> & StreamRecordTextContract<Command, Records, TextEnabled>) | (Readonly<{
|
|
994
|
+
readonly kind: "stream";
|
|
995
|
+
readonly records: Records & StreamRecordDefinitionsForSchemas<RecordSchemas, boolean> & StreamRecordNameContract<Records>;
|
|
996
|
+
readonly text?: never;
|
|
997
|
+
}> & ([TextEnabled] extends [true] ? ContractTypeError<"missingTextPresenter", Readonly<{
|
|
998
|
+
readonly command: Command;
|
|
999
|
+
readonly location: "streamSuccess";
|
|
1000
|
+
readonly missing: "text";
|
|
1001
|
+
}>> : unknown));
|
|
1002
|
+
}>);
|
|
1003
|
+
}>;
|
|
1004
|
+
}>;
|
|
1005
|
+
type RootFallbackHandlerDefinition<Root extends string, Dependencies, InputSchema extends ContractSchema, Variants extends DataVariantDefinitions, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions, Kind extends RootFallbackKind> = Readonly<{
|
|
1006
|
+
readonly commands: Readonly<{
|
|
1007
|
+
readonly [Command in Root]: Readonly<{
|
|
1008
|
+
readonly success: Readonly<{
|
|
1009
|
+
readonly kind: Kind;
|
|
1010
|
+
}>;
|
|
1011
|
+
readonly handler: (context: RootFallbackHandlerContext<Command, Dependencies, InputSchema, Variants, Records, Failures, NoInfer<Kind>>) => RootFallbackHandlerResult<Command, Variants, Records, Failures, NoInfer<Kind>>;
|
|
1012
|
+
}>;
|
|
1013
|
+
}>;
|
|
1014
|
+
}>;
|
|
1015
|
+
type RootFallbackNodeDefinition<Root extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, VariantSchemas extends VariantSchemaMap, Variants, RecordSchemas extends VariantSchemaMap, Records, FailureSchemas extends VariantSchemaMap, Failures, TextEnabled extends boolean, Kind extends RootFallbackKind> = (RootFallbackCliDefinition<Root, Dependencies, Fields, InputSchema, VariantSchemas, Variants, RecordSchemas, Records, FailureSchemas, Failures, TextEnabled> & RootFallbackHandlerDefinition<Root, Dependencies, InputSchema, DataVariantDefinitionsForSchemas<VariantSchemas, boolean>, StreamRecordDefinitionsForSchemas<RecordSchemas, boolean>, FailureVariantDefinitionsForSchemas<FailureSchemas, boolean>, Kind>)["commands"][Root];
|
|
1016
|
+
export interface DefineCli<Dependencies> {
|
|
1017
|
+
/**
|
|
1018
|
+
* 为命令组创建可执行后代,再把返回记录展开到同一个 `commands` 对象中交给
|
|
1019
|
+
* `defineCli()` 装配。后代只声明自己的输入和结果;根级 output 的全树约束在最终
|
|
1020
|
+
* 装配处统一判定。
|
|
1021
|
+
*/
|
|
1022
|
+
readonly command: <const Command extends string>(command: Command) => DefineCommand<Command, Dependencies>;
|
|
1023
|
+
/**
|
|
1024
|
+
* 装配根命令或命令组。命令组的后代在 `commands` 中合并后统一检查
|
|
1025
|
+
* 根级 output 与每个结果位置的关系;静态事实在这里被拒绝,动态值
|
|
1026
|
+
* 继续由定义期的闭合问题说明原因。
|
|
1027
|
+
*/
|
|
1028
|
+
<const Root extends string, const Fields extends FieldDefinitions, InputSchema extends ContractSchema, const VariantSchemas extends VariantSchemaMap, const Variants, const RecordSchemas extends VariantSchemaMap, const Records, const FailureSchemas extends VariantSchemaMap, const Failures, const Output extends OutputCapability, const Kind extends RootFallbackKind, const Commands, const Definition extends object>(definition: Definition & ClosedRootDefinition<Definition> & RootCliDefinitionBase<Root> & Readonly<{
|
|
1029
|
+
readonly output: Output;
|
|
1030
|
+
readonly commands: Commands & ClosedRootCommands<Commands> & Readonly<Record<Root, RootFallbackNodeDefinition<Root, Dependencies, Fields, InputSchema, VariantSchemas, Variants, RecordSchemas, Records, FailureSchemas, Failures, boolean, Kind> | RootGroupDefinition>>;
|
|
1031
|
+
}> & (Commands extends Readonly<Record<Root, {
|
|
1032
|
+
readonly kind: "rootGroup";
|
|
1033
|
+
}>> ? HierarchyCliDefinition<Root> & HierarchyContract<Commands, Output> : ValidationIntersection<HierarchyOutputValidation<Commands, Output>>)): Commands extends Readonly<Record<Root, {
|
|
1034
|
+
readonly kind: "rootGroup";
|
|
1035
|
+
}>> ? CliContract<Root, Dependencies, HierarchyRawInput<Commands>, HierarchyResult<Commands>, "rootGroup", Commands> : CliContract<Root, Dependencies, RootCommandRawInput<Root, Commands>, RootCommandResult<Root, Commands>, "rootCommand">;
|
|
1036
|
+
}
|
|
1037
|
+
type HierarchyCommandInput<Definition> = Omit<Definition, "kind"> & Omit<HierarchyCommandFacts, typeof executableCommandType>;
|
|
1038
|
+
type HierarchyCompletionCommandDefinition<Command extends string, Dependencies, Failures extends FailureVariantDefinitions, Fields extends FieldDefinitions, InputSchema extends ContractSchema> = Omit<CompletionRootCommandDefinition<Command, Dependencies, Failures, Fields, InputSchema>, "fields" | "input" | "usageConstraints"> & Readonly<{
|
|
1039
|
+
readonly fields?: CheckedFieldDefinitions<Fields> & FieldIdentityContract<Fields>;
|
|
1040
|
+
readonly input: InputSchema;
|
|
1041
|
+
}>;
|
|
1042
|
+
type HierarchyDataCommandDefinition<Command extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, Variants extends DataVariantDefinitions, Failures extends FailureVariantDefinitions> = Omit<DataRootCommandDefinition<Command, Dependencies, Fields, InputSchema, Variants, Failures>, "fields" | "input" | "usageConstraints"> & Readonly<{
|
|
1043
|
+
readonly fields: CheckedFieldDefinitions<Fields> & FieldIdentityContract<Fields>;
|
|
1044
|
+
readonly input: InputSchema;
|
|
1045
|
+
}>;
|
|
1046
|
+
type HierarchyStreamCommandDefinition<Command extends string, Dependencies, Fields extends FieldDefinitions, InputSchema extends ContractSchema, Records extends StreamRecordDefinitions, Failures extends FailureVariantDefinitions> = Omit<StreamRootCommandDefinition<Command, Dependencies, Fields, InputSchema, Records, Failures>, "fields" | "input" | "usageConstraints"> & Readonly<{
|
|
1047
|
+
readonly fields: CheckedFieldDefinitions<Fields> & FieldIdentityContract<Fields>;
|
|
1048
|
+
readonly input: InputSchema;
|
|
1049
|
+
}>;
|
|
1050
|
+
type UsageConstraintProperty<Constraints> = Constraints extends readonly unknown[] ? Readonly<{
|
|
1051
|
+
readonly usageConstraints: Constraints;
|
|
1052
|
+
}> : unknown;
|
|
1053
|
+
type ActualFailureDefinitions<Failures> = Failures extends FailureVariantDefinitions ? Failures : never;
|
|
1054
|
+
type RootFallbackFieldsProperty<Fields extends FieldDefinitions, InputSchema extends ContractSchema> = Readonly<{
|
|
1055
|
+
readonly fields: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
1056
|
+
readonly success: Readonly<{
|
|
1057
|
+
readonly kind: "data" | "stream";
|
|
1058
|
+
}>;
|
|
1059
|
+
}> | Readonly<{
|
|
1060
|
+
readonly fields?: CheckedFieldDefinitions<Fields> & FieldDefinitionsForInput<ContractSchemaInput<InputSchema>> & FieldIdentityContract<Fields>;
|
|
1061
|
+
readonly success: Readonly<{
|
|
1062
|
+
readonly kind: "completion";
|
|
1063
|
+
}>;
|
|
1064
|
+
}>;
|
|
1065
|
+
/** 为具名叶命令生成可展开到根契约 `commands` 的定义。 */
|
|
1066
|
+
export interface DefineCommand<Command extends string, Dependencies> {
|
|
1067
|
+
<const Definition extends object, const Parent extends string, const Fields extends FieldDefinitions, InputSchema extends ContractSchema, const VariantSchemas extends VariantSchemaMap, const Variants, const RecordSchemas extends VariantSchemaMap, const Records, const FailureSchemas extends VariantSchemaMap, const Failures, const Kind extends RootFallbackKind>(definition: Definition & ClosedCommandDefinition<Definition> & Omit<RootFallbackCliDefinition<Command, Dependencies, Fields, InputSchema, VariantSchemas, Variants, RecordSchemas, Records, FailureSchemas, Failures, boolean>["commands"][Command], "kind" | "fields"> & RootFallbackFieldsProperty<Fields, InputSchema> & RootFallbackHandlerDefinition<Command, Dependencies, InputSchema, DataVariantDefinitionsForSchemas<VariantSchemas, boolean>, StreamRecordDefinitionsForSchemas<RecordSchemas, boolean>, ActualFailureDefinitions<Failures>, Kind>["commands"][Command] & Omit<HierarchyCommandFacts<Parent>, typeof executableCommandType>): Readonly<Record<Command, Definition & HierarchyCommandFacts<Parent>>>;
|
|
1068
|
+
<const Definition extends object, const Parent extends string, const Failures extends FailureVariantDefinitions, const Constraints extends readonly unknown[] | undefined = undefined>(definition: Definition & ClosedCommandDefinition<Definition> & HierarchyCommandInput<HierarchyCompletionCommandDefinition<Command, Dependencies, Failures, Readonly<Record<never, never>>, ContractSchema<EmptyCliInput>>> & Readonly<{
|
|
1069
|
+
readonly parent: Parent;
|
|
1070
|
+
readonly usageConstraints?: Constraints & readonly UsageConstraint[];
|
|
1071
|
+
}>): Readonly<Record<Command, Definition & Omit<HierarchyCompletionCommandDefinition<Command, Dependencies, Failures, Readonly<Record<never, never>>, ContractSchema<EmptyCliInput>>, "kind" | "success" | "failures"> & UsageConstraintProperty<Constraints> & HierarchyCommandFacts<Parent>>>;
|
|
1072
|
+
<const Definition extends object, const Fields extends FieldDefinitions, InputSchema extends ContractSchema, const Parent extends string, const Failures extends FailureVariantDefinitions, const Constraints extends readonly unknown[] | undefined = undefined>(definition: Definition & ClosedCommandDefinition<Definition> & HierarchyCommandInput<HierarchyCompletionCommandDefinition<Command, Dependencies, Failures, Fields, InputSchema>> & Readonly<{
|
|
1073
|
+
readonly fields: Fields;
|
|
1074
|
+
readonly parent: Parent;
|
|
1075
|
+
readonly usageConstraints?: Constraints & readonly UsageConstraint[];
|
|
1076
|
+
}>): Readonly<Record<Command, Definition & Omit<HierarchyCompletionCommandDefinition<Command, Dependencies, Failures, Fields, InputSchema>, "kind" | "success" | "failures"> & UsageConstraintProperty<Constraints> & HierarchyCommandFacts<Parent>>>;
|
|
1077
|
+
<const Definition extends object, const Fields extends FieldDefinitions, InputSchema extends ContractSchema, const Parent extends string, const Variants extends DataVariantDefinitions, const Failures extends FailureVariantDefinitions, const Constraints extends readonly unknown[] | undefined = undefined>(definition: Definition & ClosedCommandDefinition<Definition> & HierarchyCommandInput<HierarchyDataCommandDefinition<Command, Dependencies, Fields, InputSchema, Variants, Failures>> & Readonly<{
|
|
1078
|
+
readonly parent: Parent;
|
|
1079
|
+
readonly usageConstraints?: Constraints & readonly UsageConstraint[];
|
|
1080
|
+
}>): Readonly<Record<Command, Definition & Omit<HierarchyDataCommandDefinition<Command, Dependencies, Fields, InputSchema, Variants, Failures>, "kind" | "success" | "failures"> & UsageConstraintProperty<Constraints> & HierarchyCommandFacts<Parent>>>;
|
|
1081
|
+
<const Definition extends object, const Fields extends FieldDefinitions, InputSchema extends ContractSchema, const Parent extends string, const Records extends StreamRecordDefinitions, const Failures extends FailureVariantDefinitions, const Constraints extends readonly unknown[] | undefined = undefined>(definition: Definition & ClosedCommandDefinition<Definition> & HierarchyCommandInput<HierarchyStreamCommandDefinition<Command, Dependencies, Fields, InputSchema, Records, Failures>> & Readonly<{
|
|
1082
|
+
readonly parent: Parent;
|
|
1083
|
+
readonly usageConstraints?: Constraints & readonly UsageConstraint[];
|
|
1084
|
+
}>): Readonly<Record<Command, Definition & Omit<HierarchyStreamCommandDefinition<Command, Dependencies, Fields, InputSchema, Records, Failures>, "kind" | "success" | "failures"> & UsageConstraintProperty<Constraints> & HierarchyCommandFacts<Parent>>>;
|
|
1085
|
+
}
|
|
1086
|
+
interface RuntimeCompiledCli {
|
|
1087
|
+
readonly contract: CliContract;
|
|
1088
|
+
readonly root: string;
|
|
1089
|
+
readonly usageFailureExitCode: number;
|
|
1090
|
+
readonly commands: Readonly<Record<string, RuntimeCompiledCommand>>;
|
|
1091
|
+
}
|
|
1092
|
+
type RuntimeCompiledSuccess = Readonly<{
|
|
1093
|
+
readonly kind: "completion";
|
|
1094
|
+
readonly text?: unknown;
|
|
1095
|
+
}> | Readonly<{
|
|
1096
|
+
readonly kind: "data";
|
|
1097
|
+
readonly variants: Readonly<Record<string, RuntimeAtomicVariant>>;
|
|
1098
|
+
}> | Readonly<{
|
|
1099
|
+
readonly kind: "stream";
|
|
1100
|
+
readonly records: Readonly<Record<string, RuntimeStreamRecord>>;
|
|
1101
|
+
readonly text?: unknown;
|
|
1102
|
+
}>;
|
|
1103
|
+
interface RuntimeCompiledCommandBase {
|
|
1104
|
+
readonly id: string;
|
|
1105
|
+
readonly parent?: string;
|
|
1106
|
+
readonly name: string;
|
|
1107
|
+
readonly aliases: readonly string[];
|
|
1108
|
+
readonly description: string;
|
|
1109
|
+
readonly helpSupplement?: readonly string[];
|
|
1110
|
+
readonly usage: CommandUsage<string>;
|
|
1111
|
+
}
|
|
1112
|
+
interface RuntimeCompiledGroup extends RuntimeCompiledCommandBase {
|
|
1113
|
+
readonly kind: "commandGroup" | "rootGroup";
|
|
1114
|
+
}
|
|
1115
|
+
export interface RuntimeCompiledExecutable extends RuntimeCompiledCommandBase {
|
|
1116
|
+
readonly kind: "command" | "rootCommand";
|
|
1117
|
+
readonly fields: readonly FieldGrammar[];
|
|
1118
|
+
readonly usageConstraints: readonly UsageConstraintGrammar[];
|
|
1119
|
+
readonly input: ContractSchema;
|
|
1120
|
+
readonly success: RuntimeCompiledSuccess;
|
|
1121
|
+
readonly failures: Readonly<Record<string, RuntimeAtomicVariant>>;
|
|
1122
|
+
readonly handler: unknown;
|
|
1123
|
+
}
|
|
1124
|
+
type RuntimeCompiledCommand = RuntimeCompiledGroup | RuntimeCompiledExecutable;
|
|
1125
|
+
export declare function isCompiledExecutable(command: RuntimeCompiledCommand): command is RuntimeCompiledExecutable;
|
|
1126
|
+
/**
|
|
1127
|
+
* 显式装配全树帮助。`headings` 是可选段落标题;`wording` 按实际帮助事实
|
|
1128
|
+
* 提供必要模板,由 defineCli 检查完整性;核心不生成默认自然语言。
|
|
1129
|
+
*/
|
|
1130
|
+
export declare function helpCapability(definition?: undefined): HelpCapability;
|
|
1131
|
+
export declare function helpCapability<const Definition extends HelpCapabilityDefinition>(definition: Definition & RejectUnknownProperties<Definition, (typeof definitionPropertyKeys.capability.help)[number]> & (Definition extends Readonly<{
|
|
1132
|
+
readonly headings: infer Headings;
|
|
1133
|
+
}> ? Readonly<{
|
|
1134
|
+
readonly headings: RejectUnknownProperties<Headings, keyof HelpHeadings>;
|
|
1135
|
+
}> : unknown) & (Definition extends Readonly<{
|
|
1136
|
+
readonly wording: infer Wording;
|
|
1137
|
+
}> ? Readonly<{
|
|
1138
|
+
readonly wording: RejectUnknownProperties<Wording, keyof HelpFactWording>;
|
|
1139
|
+
}> : unknown)): HelpCapability;
|
|
1140
|
+
/**
|
|
1141
|
+
* 在根契约显式装配版本提前请求,并自动覆盖整棵命令树。`value` 与可选
|
|
1142
|
+
* `description` 均由消费者拥有;核心只注册固定 spelling、投影帮助并写出 value,
|
|
1143
|
+
* 不读取包元数据、不添加前缀或默认说明,也不把版本当作命令输入。
|
|
1144
|
+
*/
|
|
1145
|
+
export declare function versionCapability<const Definition extends VersionCapabilityDefinition>(definition: Definition & RejectUnknownProperties<Definition, (typeof definitionPropertyKeys.capability.version)[number]>): VersionCapability;
|
|
1146
|
+
/**
|
|
1147
|
+
* 在根契约显式装配一次应用结果的输出格式能力,并自动覆盖整棵命令树。
|
|
1148
|
+
* 它把 selector 与兼容 flag 保留为调用控制,不进入命令 input 或 handler;帮助、版本
|
|
1149
|
+
* 与用法失败使用各自固定投影。`defaultFormat`、text 支持和兼容映射必须由消费者
|
|
1150
|
+
* 显式选择,不能在命令节点另行装配格式或输出 profile。
|
|
1151
|
+
*/
|
|
1152
|
+
export declare function outputCapability<const Definition extends OutputCapabilityDefinition>(definition: Definition & RejectUnknownProperties<Definition, (typeof definitionPropertyKeys.capability.output)[number]>): OutputCapability<OutputFormatsFor<Definition>>;
|
|
1153
|
+
/**
|
|
1154
|
+
* 定义一个闭合 CLI 契约。根级 help 与 output 能力在此处一次装配,并据此约束根命令的结果投影;
|
|
1155
|
+
* 动态声明仍会在定义期报告 `ContractDefinitionError`,不能以它替代静态可判定声明的类型检查。
|
|
1156
|
+
* @see {@link https://github.com/YKDZ/cli-contract/tree/v0.2.1/packages/example | 端到端示例}
|
|
1157
|
+
*/
|
|
1158
|
+
export declare function defineCli<Dependencies = undefined>(): DefineCli<Dependencies>;
|
|
1159
|
+
export declare function getCompiledCli(contract: CliContract): RuntimeCompiledCli;
|
|
1160
|
+
export declare function usageFailureHelpArgv(commands: Readonly<Record<string, Readonly<{
|
|
1161
|
+
readonly name: string;
|
|
1162
|
+
readonly parent?: string;
|
|
1163
|
+
}>>>, command: string): readonly string[];
|
|
1164
|
+
export declare function formatFieldUsage(field: FieldGrammar, includeShortAlias?: boolean): string;
|