@kjanat/dreamcli 3.0.1 → 4.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +951 -1
- package/README.md +7 -3
- package/dist/core/cli/builtins.d.mts +47 -0
- package/dist/core/cli/builtins.mjs +135 -0
- package/dist/core/cli/compiled.d.mts +29 -0
- package/dist/core/cli/compiled.mjs +76 -0
- package/dist/core/cli/dispatch.d.mts +9 -85
- package/dist/core/cli/help-links.d.mts +2 -14
- package/dist/core/cli/index.d.mts +282 -101
- package/dist/core/cli/index.mjs +497 -264
- package/dist/core/cli/planner.d.mts +13 -86
- package/dist/core/cli/planner.mjs +47 -30
- package/dist/core/cli/plugin.d.mts +1 -1
- package/dist/core/cli/propagate.mjs +1 -1
- package/dist/core/cli/reserved-flags.d.mts +1 -0
- package/dist/core/cli/reserved-flags.mjs +158 -0
- package/dist/core/cli/root-help.d.mts +1 -47
- package/dist/core/cli/root-help.mjs +37 -47
- package/dist/core/cli/root-output-flags.d.mts +1 -0
- package/dist/core/cli/root-output-flags.mjs +169 -0
- package/dist/core/cli/root-surface.d.mts +1 -68
- package/dist/core/cli/root-surface.mjs +2 -2
- package/dist/core/cli/runtime-preflight.d.mts +1 -199
- package/dist/core/cli/runtime-preflight.mjs +67 -17
- package/dist/core/completion/index.d.mts +2 -2
- package/dist/core/completion/shells/bash.d.mts +0 -1
- package/dist/core/completion/shells/bash.mjs +2 -1
- package/dist/core/completion/shells/fish.d.mts +0 -1
- package/dist/core/completion/shells/fish.mjs +2 -1
- package/dist/core/completion/shells/powershell.d.mts +0 -1
- package/dist/core/completion/shells/powershell.mjs +2 -1
- package/dist/core/completion/shells/shared.d.mts +3 -114
- package/dist/core/completion/shells/shared.mjs +9 -39
- package/dist/core/completion/shells/zsh.d.mts +0 -1
- package/dist/core/completion/shells/zsh.mjs +2 -1
- package/dist/core/config/index.d.mts +3 -3
- package/dist/core/config/index.mjs +2 -2
- package/dist/core/config/package-json.d.mts +2 -33
- package/dist/core/config/package-json.mjs +1 -34
- package/dist/core/errors/index.d.mts +7 -7
- package/dist/core/execution/index.d.mts +1 -48
- package/dist/core/execution/index.mjs +42 -27
- package/dist/core/help/ansi.d.mts +0 -11
- package/dist/core/help/index.d.mts +3 -35
- package/dist/core/help/index.mjs +29 -6
- package/dist/core/help/theme.d.mts +1 -21
- package/dist/core/json-schema/index.d.mts +279 -10
- package/dist/core/json-schema/index.mjs +482 -237
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +79 -7
- package/dist/core/json-schema/meta-descriptions.generated.mjs +40 -6
- package/dist/core/output/activity.d.mts +1 -193
- package/dist/core/output/activity.mjs +1 -1
- package/dist/core/output/bind.d.mts +1 -37
- package/dist/core/output/contracts.d.mts +7 -13
- package/dist/core/output/contracts.mjs +1 -1
- package/dist/core/output/display-value.d.mts +1 -19
- package/dist/core/output/index.d.mts +5 -187
- package/dist/core/output/index.mjs +44 -9
- package/dist/core/output/renderers.d.mts +1 -45
- package/dist/core/output/writer.d.mts +0 -1
- package/dist/core/parse/index.d.mts +27 -5
- package/dist/core/parse/index.mjs +350 -227
- package/dist/core/parse/occurrences.d.mts +89 -0
- package/dist/core/parse/occurrences.mjs +114 -0
- package/dist/core/prompt/index.d.mts +3 -3
- package/dist/core/read-flags/index.d.mts +150 -0
- package/dist/core/read-flags/index.mjs +217 -0
- package/dist/core/resolve/args.d.mts +35 -4
- package/dist/core/resolve/args.mjs +132 -55
- package/dist/core/resolve/coerce.d.mts +66 -9
- package/dist/core/resolve/coerce.mjs +834 -270
- package/dist/core/resolve/config.d.mts +1 -10
- package/dist/core/resolve/contracts.d.mts +67 -44
- package/dist/core/resolve/errors.mjs +29 -21
- package/dist/core/resolve/flags.d.mts +36 -9
- package/dist/core/resolve/flags.mjs +129 -151
- package/dist/core/resolve/index.d.mts +8 -6
- package/dist/core/resolve/index.mjs +51 -18
- package/dist/core/resolve/path-checks.d.mts +47 -0
- package/dist/core/resolve/path-checks.mjs +102 -0
- package/dist/core/resolve/redaction.d.mts +12 -0
- package/dist/core/resolve/redaction.mjs +14 -0
- package/dist/core/resolve/stages.d.mts +85 -0
- package/dist/core/resolve/stages.mjs +170 -0
- package/dist/core/resolve/standard.d.mts +1 -24
- package/dist/core/resolve/standard.mjs +141 -43
- package/dist/core/schema/activity.d.mts +16 -16
- package/dist/core/schema/arg.d.mts +849 -71
- package/dist/core/schema/arg.mjs +727 -54
- package/dist/core/schema/brand.d.mts +17 -0
- package/dist/core/schema/cardinality.d.mts +301 -0
- package/dist/core/schema/cardinality.mjs +514 -0
- package/dist/core/schema/command.d.mts +181 -112
- package/dist/core/schema/command.mjs +305 -42
- package/dist/core/schema/flag.d.mts +515 -173
- package/dist/core/schema/flag.mjs +576 -78
- package/dist/core/schema/index.d.mts +11 -8
- package/dist/core/schema/index.mjs +10 -0
- package/dist/core/schema/middleware.d.mts +15 -12
- package/dist/core/schema/number-constraints.d.mts +5 -5
- package/dist/core/schema/prompt.d.mts +4 -4
- package/dist/core/schema/provenance.d.mts +99 -0
- package/dist/core/schema/provenance.mjs +28 -0
- package/dist/core/schema/run.d.mts +21 -60
- package/dist/core/schema/source.d.mts +179 -0
- package/dist/core/schema/source.mjs +206 -0
- package/dist/core/schema/standard.d.mts +12 -19
- package/dist/core/schema/stdin.d.mts +87 -0
- package/dist/core/schema/stdin.mjs +91 -0
- package/dist/core/schema/string-constraints.d.mts +16 -5
- package/dist/core/schema/string-constraints.mjs +18 -1
- package/dist/core/schema/value-parsers.d.mts +81 -9
- package/dist/core/schema/value-parsers.mjs +19 -1
- package/dist/core/schema/value.d.mts +242 -0
- package/dist/core/schema/value.mjs +573 -0
- package/dist/core/testkit/index.d.mts +28 -3
- package/dist/core/testkit/index.mjs +40 -26
- package/dist/index.d.mts +21 -16
- package/dist/index.mjs +10 -6
- package/dist/runtime/adapter.d.mts +3 -3
- package/dist/runtime/deno.d.mts +3 -3
- package/dist/runtime/detect.d.mts +2 -2
- package/dist/runtime/node.d.mts +3 -3
- package/dist/runtime/paths.d.mts +1 -31
- package/dist/runtime.d.mts +4 -4
- package/dist/strings.d.mts +1 -16
- package/dist/testkit.d.mts +2 -2
- package/dist/testkit.mjs +1 -1
- package/dist/version.d.mts +0 -13
- package/dist/version.mjs +2 -2
- package/dreamcli.schema.json +368 -78
- package/examples/interactive.ts +6 -5
- package/package.json +9 -9
- package/skills/cli-creation/SKILL.md +72 -16
- package/skills/cli-creation/references/pattern-cookbook.md +169 -11
- package/dist/core/resolve/property.d.mts +0 -51
- package/dist/core/resolve/property.mjs +0 -53
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ValidationError } from "../errors/index.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { argValueSchema, valueEnumValues } from "../schema/value.mjs";
|
|
3
|
+
import { argCardinality, dedupe } from "../schema/cardinality.mjs";
|
|
4
|
+
import { argCollectedNothing, sourceBindings } from "../schema/source.mjs";
|
|
5
|
+
import { resolvePromptConfig } from "../prompt/index.mjs";
|
|
6
|
+
import { echoesValue } from "./redaction.mjs";
|
|
7
|
+
import { coerceArgValue, finishCliArgValue } from "./coerce.mjs";
|
|
3
8
|
import { isNonEmpty, throwAggregatedErrors } from "./errors.mjs";
|
|
9
|
+
import { pathValuesOf, validatePathChecks } from "./path-checks.mjs";
|
|
10
|
+
import { readCliValue, runStages } from "./stages.mjs";
|
|
11
|
+
import { COMPATIBLE_PROMPT_KINDS, promptCompatibilityError } from "./flags.mjs";
|
|
4
12
|
//#region src/core/resolve/args.ts
|
|
5
13
|
/**
|
|
6
14
|
* Internal arg resolution helpers.
|
|
@@ -8,76 +16,57 @@ import { isNonEmpty, throwAggregatedErrors } from "./errors.mjs";
|
|
|
8
16
|
* @module dreamcli/core/resolve/args
|
|
9
17
|
* @internal
|
|
10
18
|
*/
|
|
11
|
-
/**
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Walk every declared arg through the resolution chain
|
|
21
|
+
* (cli -> stdin -> env -> config -> prompt -> default), collecting deprecations
|
|
22
|
+
* and throwing aggregated errors.
|
|
23
|
+
*
|
|
24
|
+
* @param argEntries - Declared positionals in CLI order.
|
|
25
|
+
* @param parsedArgs - Values the parser read off argv.
|
|
26
|
+
* @param options - External state and collectors for this pass.
|
|
27
|
+
* @returns Fully resolved arg values keyed by arg name.
|
|
28
|
+
*/
|
|
29
|
+
async function resolveArgs(argEntries, parsedArgs, options) {
|
|
13
30
|
const resolved = {};
|
|
14
31
|
const errors = [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
const state = {
|
|
33
|
+
env: options.env,
|
|
34
|
+
config: options.config,
|
|
35
|
+
stdinData: options.stdinData,
|
|
36
|
+
canPrompt: options.prompter !== void 0
|
|
37
|
+
};
|
|
38
|
+
for (const { name, schema } of argEntries) {
|
|
39
|
+
const bindings = sourceBindings(schema);
|
|
40
|
+
const outcome = await runStages(bindings, stageInput(name, schema, parsedArgs, bindings, options.prompter), state);
|
|
41
|
+
if (outcome.kind === "error") {
|
|
42
|
+
errors.push(outcome.error);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (outcome.kind === "value") {
|
|
46
|
+
if (schema.deprecated !== void 0 && outcome.provenance.stage !== "default") options.deprecations.push({
|
|
21
47
|
kind: "arg",
|
|
22
48
|
name,
|
|
23
49
|
message: schema.deprecated
|
|
24
50
|
});
|
|
25
|
-
resolved[name] =
|
|
51
|
+
resolved[name] = outcome.value;
|
|
52
|
+
options.provenance[name] = outcome.provenance;
|
|
26
53
|
continue;
|
|
27
54
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const coerced = coerceArgStringValue(name, { kind: "stdin" }, stdinData, schema);
|
|
31
|
-
if (coerced.ok) {
|
|
32
|
-
if (schema.deprecated !== void 0) deprecations.push({
|
|
33
|
-
kind: "arg",
|
|
34
|
-
name,
|
|
35
|
-
message: schema.deprecated
|
|
36
|
-
});
|
|
37
|
-
resolved[name] = coerced.value;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
errors.push(coerced.error);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (schema.envVar !== void 0) {
|
|
45
|
-
const envValue = env[schema.envVar];
|
|
46
|
-
if (envValue !== void 0) {
|
|
47
|
-
const coerced = coerceArgStringValue(name, {
|
|
48
|
-
kind: "env",
|
|
49
|
-
envVar: schema.envVar
|
|
50
|
-
}, envValue, schema);
|
|
51
|
-
if (coerced.ok) {
|
|
52
|
-
if (schema.deprecated !== void 0) deprecations.push({
|
|
53
|
-
kind: "arg",
|
|
54
|
-
name,
|
|
55
|
-
message: schema.deprecated
|
|
56
|
-
});
|
|
57
|
-
resolved[name] = coerced.value;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
errors.push(coerced.error);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (schema.defaultValue !== void 0) {
|
|
65
|
-
resolved[name] = schema.defaultValue;
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (schema.variadic) {
|
|
55
|
+
const cardinality = argCardinality(schema);
|
|
56
|
+
if (cardinality.kind === "many" || cardinality.kind === "entries") {
|
|
69
57
|
if (schema.presence === "required") {
|
|
70
58
|
errors.push(new ValidationError(`Missing required argument <${name}>`, {
|
|
71
59
|
code: "REQUIRED_ARG",
|
|
72
60
|
details: {
|
|
73
61
|
arg: name,
|
|
74
|
-
variadic: true
|
|
62
|
+
...schema.variadic ? { variadic: true } : {}
|
|
75
63
|
},
|
|
76
|
-
suggest: buildRequiredArgSuggest(name, schema,
|
|
64
|
+
suggest: buildRequiredArgSuggest(name, schema, schema.variadic)
|
|
77
65
|
}));
|
|
78
66
|
continue;
|
|
79
67
|
}
|
|
80
|
-
resolved[name] = [];
|
|
68
|
+
resolved[name] = cardinality.kind === "many" ? [] : {};
|
|
69
|
+
options.provenance[name] = { stage: "default" };
|
|
81
70
|
continue;
|
|
82
71
|
}
|
|
83
72
|
if (schema.presence === "required") {
|
|
@@ -90,13 +79,101 @@ function resolveArgs(argEntries, parsedArgs, stdinData, env, deprecations) {
|
|
|
90
79
|
}
|
|
91
80
|
resolved[name] = void 0;
|
|
92
81
|
}
|
|
82
|
+
for (const { name, schema } of argEntries) {
|
|
83
|
+
if (!schema.unique) continue;
|
|
84
|
+
const value = Object.hasOwn(resolved, name) ? resolved[name] : void 0;
|
|
85
|
+
if (Array.isArray(value)) resolved[name] = [...dedupe(value)];
|
|
86
|
+
}
|
|
87
|
+
if (options.stat !== void 0) for (const { name, schema } of argEntries) {
|
|
88
|
+
const checks = argValueSchema(schema).pathChecks;
|
|
89
|
+
if (checks === void 0) continue;
|
|
90
|
+
const echo = echoesValue(Object.hasOwn(options.provenance, name) ? options.provenance[name] : void 0);
|
|
91
|
+
for (const value of pathValuesOf(Object.hasOwn(resolved, name) ? resolved[name] : void 0)) {
|
|
92
|
+
const violation = await validatePathChecks({
|
|
93
|
+
kind: "arg",
|
|
94
|
+
name
|
|
95
|
+
}, value, checks, options.stat, options.mkdir, echo);
|
|
96
|
+
if (violation !== void 0) errors.push(violation);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
93
99
|
if (isNonEmpty(errors)) throwAggregatedErrors(errors);
|
|
94
100
|
return resolved;
|
|
95
101
|
}
|
|
102
|
+
/** Assemble what one arg contributes to its own resolution. */
|
|
103
|
+
function stageInput(name, schema, parsedArgs, bindings, prompter) {
|
|
104
|
+
const present = Object.hasOwn(parsedArgs, name);
|
|
105
|
+
const parsedValue = present ? parsedArgs[name] : void 0;
|
|
106
|
+
return {
|
|
107
|
+
cli: argCollectedNothing(schema, parsedValue) ? { kind: "absent" } : readCliValue(present, parsedValue, bindings),
|
|
108
|
+
coerce: (binding, raw) => coerceArgValue(name, binding, raw, schema),
|
|
109
|
+
finishCli: (value, stdinData, stdin) => finishCliArgValue(name, schema, value, stdinData, stdin),
|
|
110
|
+
runPrompt: async (binding) => prompter === void 0 ? {
|
|
111
|
+
ok: false,
|
|
112
|
+
error: void 0
|
|
113
|
+
} : resolveArgPromptValue(name, schema, binding, prompter)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The prompt kinds an arg accepts, read off its value and cardinality axes.
|
|
118
|
+
*
|
|
119
|
+
* An arg that collects several values takes the prompt a `flag.array()` takes,
|
|
120
|
+
* since the two aggregate the same way; every other arg takes what its kind
|
|
121
|
+
* takes on the flag surface.
|
|
122
|
+
*
|
|
123
|
+
* @param schema - The arg schema to read.
|
|
124
|
+
* @returns The compatible prompt kinds, and the word a diagnostic names the arg by.
|
|
125
|
+
*/
|
|
126
|
+
function argPromptCompatibility(schema) {
|
|
127
|
+
if (argCardinality(schema).kind === "many") return {
|
|
128
|
+
allowed: COMPATIBLE_PROMPT_KINDS.array,
|
|
129
|
+
kindWord: `variadic ${schema.kind}`
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
allowed: COMPATIBLE_PROMPT_KINDS[schema.kind],
|
|
133
|
+
kindWord: schema.kind
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validate prompt/arg compatibility, run the prompt engine, and coerce the result.
|
|
138
|
+
*
|
|
139
|
+
* The compatibility table is the one flags use, read through the value and
|
|
140
|
+
* cardinality axes, so the two surfaces accept the same prompt kinds for the
|
|
141
|
+
* same value.
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
async function resolveArgPromptValue(argName, schema, binding, prompter) {
|
|
145
|
+
const promptConfig = binding.prompt;
|
|
146
|
+
const { allowed, kindWord } = argPromptCompatibility(schema);
|
|
147
|
+
if (!allowed.includes(promptConfig.kind)) return {
|
|
148
|
+
ok: false,
|
|
149
|
+
error: promptCompatibilityError({
|
|
150
|
+
reference: `<${argName}>`,
|
|
151
|
+
singular: "argument",
|
|
152
|
+
plural: "arguments",
|
|
153
|
+
details: {
|
|
154
|
+
arg: argName,
|
|
155
|
+
argKind: schema.kind
|
|
156
|
+
}
|
|
157
|
+
}, kindWord, promptConfig.kind, allowed)
|
|
158
|
+
};
|
|
159
|
+
const resolvedConfig = resolvePromptConfig(promptConfig, valueEnumValues(argValueSchema(schema)));
|
|
160
|
+
const result = await prompter.promptOne(resolvedConfig);
|
|
161
|
+
if (!result.answered) return {
|
|
162
|
+
ok: false,
|
|
163
|
+
error: void 0
|
|
164
|
+
};
|
|
165
|
+
if (promptConfig.kind === "input" && promptConfig.default === void 0 && typeof result.value === "string" && result.value.trim() === "") return {
|
|
166
|
+
ok: false,
|
|
167
|
+
error: void 0
|
|
168
|
+
};
|
|
169
|
+
return coerceArgValue(argName, binding, result.value, schema);
|
|
170
|
+
}
|
|
96
171
|
function buildRequiredArgSuggest(name, schema, variadic) {
|
|
97
172
|
const sources = [variadic ? `Provide at least one value for <${name}>` : `Provide a value for <${name}>`];
|
|
98
|
-
|
|
173
|
+
const stdin = schema.stdin;
|
|
174
|
+
if (stdin !== void 0) sources.push(stdin.when === "dash" ? `pass '-' to read stdin` : stdin.when === "missing" ? `pipe a value to stdin` : `pipe a value to stdin or pass '-'`);
|
|
99
175
|
if (schema.envVar !== void 0) sources.push(`set ${schema.envVar}`);
|
|
176
|
+
if (schema.configPath !== void 0) sources.push(`add ${schema.configPath} to config`);
|
|
100
177
|
if (sources.length === 1) return sources[0];
|
|
101
178
|
if (sources.length === 2) return `${sources[0]} or ${sources[1]}`;
|
|
102
179
|
return `${sources.slice(0, -1).join(", ")}, or ${sources[sources.length - 1]}`;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ArgSchema } from "../schema/arg.mjs";
|
|
2
1
|
import { FlagSchema } from "../schema/flag.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { ArgSchema } from "../schema/arg.mjs";
|
|
4
3
|
import { ValidationError } from "../errors/index.mjs";
|
|
5
4
|
import "../schema/index.mjs";
|
|
5
|
+
import { DecodedSourceBinding, StdinSourceBinding } from "../schema/source.mjs";
|
|
6
6
|
//#region src/core/resolve/coerce.d.ts
|
|
7
|
-
type CoerceSource = FlagDiagnosticSource;
|
|
8
7
|
/** Discriminated result of a value coercion attempt — success with the coerced value, or failure with a structured validation error. */
|
|
9
8
|
type CoerceResult = {
|
|
10
9
|
readonly ok: true;
|
|
@@ -13,10 +12,68 @@ type CoerceResult = {
|
|
|
13
12
|
readonly ok: false;
|
|
14
13
|
readonly error: ValidationError;
|
|
15
14
|
};
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Coerce a raw value from stdin/env/config/prompt into what a flag declares.
|
|
17
|
+
*
|
|
18
|
+
* The cardinality axis decides how many values the source carries and how they
|
|
19
|
+
* combine; the value axis decides what each one means; the binding decides how
|
|
20
|
+
* the source's text splits and whether a single value is trimmed.
|
|
21
|
+
*/
|
|
22
|
+
declare function coerceValue(flagName: string, binding: DecodedSourceBinding, raw: unknown, schema: FlagSchema): CoerceResult;
|
|
23
|
+
/**
|
|
24
|
+
* Coerce a value from a non-CLI source into the type declared by an arg schema,
|
|
25
|
+
* redacting the raw value in error diagnostics.
|
|
26
|
+
*
|
|
27
|
+
* Every source outside argv may carry a secret a user piped, exported, or
|
|
28
|
+
* stored, so the arg surface reports the failure without echoing the value.
|
|
29
|
+
*
|
|
30
|
+
* @param argName - Name of the positional the value belongs to.
|
|
31
|
+
* @param binding - The stage that produced the value.
|
|
32
|
+
* @param raw - The value that stage produced.
|
|
33
|
+
* @param schema - Runtime descriptor of the arg.
|
|
34
|
+
* @returns The coerced value, or a redacted {@link ValidationError}.
|
|
35
|
+
*/
|
|
36
|
+
declare function coerceArgValue(argName: string, binding: DecodedSourceBinding, raw: unknown, schema: ArgSchema): CoerceResult;
|
|
37
|
+
/** What finishing a CLI-sourced value produced. */
|
|
38
|
+
type CliFinish = {
|
|
39
|
+
readonly kind: "value";
|
|
40
|
+
readonly value: unknown;
|
|
41
|
+
readonly viaStdin: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "error";
|
|
44
|
+
readonly error: ValidationError;
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: "absent";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Finish the CLI value of a flag, splicing stdin into occurrence order.
|
|
50
|
+
*
|
|
51
|
+
* A scalar keeps what the parser produced. A collection carries its occurrences
|
|
52
|
+
* in the order they were typed, and an occurrence of `-` stands for the whole
|
|
53
|
+
* stdin source at that position: what the buffer decodes to is spliced in
|
|
54
|
+
* there, so `--tag before --tag - --tag after` over `'a\nb\n'` resolves to
|
|
55
|
+
* `['before', 'a', 'b', 'after']`.
|
|
56
|
+
*
|
|
57
|
+
* @param flagName - Canonical flag name.
|
|
58
|
+
* @param schema - The flag being resolved.
|
|
59
|
+
* @param value - What the parser produced for it.
|
|
60
|
+
* @param stdinData - The pre-read stdin buffer, when one was read.
|
|
61
|
+
* @param stdin - The flag's stdin source, when it declares one.
|
|
62
|
+
* @returns The finished value, a failure, or absence when only `-` was given
|
|
63
|
+
* and nothing was piped.
|
|
64
|
+
*/
|
|
65
|
+
declare function finishCliFlagValue(flagName: string, schema: FlagSchema, value: unknown, stdinData: string | null | undefined, stdin: StdinSourceBinding | undefined): CliFinish;
|
|
66
|
+
/**
|
|
67
|
+
* Finish the CLI value of a positional, splicing stdin into occurrence order.
|
|
68
|
+
*
|
|
69
|
+
* @param argName - Positional arg name.
|
|
70
|
+
* @param schema - The arg being resolved.
|
|
71
|
+
* @param value - What the parser produced for it.
|
|
72
|
+
* @param stdinData - The pre-read stdin buffer, when one was read.
|
|
73
|
+
* @param stdin - The arg's stdin source, when it declares one.
|
|
74
|
+
* @returns The finished value, a failure, or absence when only `-` was given
|
|
75
|
+
* and nothing was piped.
|
|
76
|
+
*/
|
|
77
|
+
declare function finishCliArgValue(argName: string, schema: ArgSchema, value: unknown, stdinData: string | null | undefined, stdin: StdinSourceBinding | undefined): CliFinish;
|
|
21
78
|
//#endregion
|
|
22
|
-
export { type CoerceResult,
|
|
79
|
+
export { type CliFinish, type CoerceResult, coerceArgValue, coerceValue, finishCliArgValue, finishCliFlagValue };
|