toolcraft 0.0.11 → 0.0.12
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/cli.js +274 -160
- package/dist/renderer.d.ts +8 -2
- package/dist/renderer.js +71 -12
- package/node_modules/@poe-code/design-system/dist/components/help-formatter-plain.d.ts +4 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter-plain.js +132 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter.js +116 -7
- package/node_modules/@poe-code/design-system/dist/components/index.d.ts +2 -2
- package/node_modules/@poe-code/design-system/dist/components/index.js +1 -1
- package/node_modules/@poe-code/design-system/dist/components/text.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/components/text.js +8 -0
- package/node_modules/@poe-code/design-system/dist/index.d.ts +3 -2
- package/node_modules/@poe-code/design-system/dist/index.js +2 -1
- package/node_modules/@poe-code/task-list/README.md +49 -5
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.d.ts +19 -0
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.js +62 -0
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues.d.ts +13 -0
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues.js +627 -0
- package/node_modules/@poe-code/task-list/dist/backends/markdown-dir.js +253 -41
- package/node_modules/@poe-code/task-list/dist/backends/utils.d.ts +7 -1
- package/node_modules/@poe-code/task-list/dist/backends/utils.js +21 -0
- package/node_modules/@poe-code/task-list/dist/backends/yaml-file.js +171 -16
- package/node_modules/@poe-code/task-list/dist/index.d.ts +3 -1
- package/node_modules/@poe-code/task-list/dist/index.js +1 -1
- package/node_modules/@poe-code/task-list/dist/open.d.ts +4 -2
- package/node_modules/@poe-code/task-list/dist/open.js +27 -3
- package/node_modules/@poe-code/task-list/dist/types.d.ts +51 -3
- package/node_modules/@poe-code/task-list/dist/types.js +25 -0
- package/node_modules/@poe-code/task-list/package.json +1 -0
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { access, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Command as CommanderCommand, CommanderError, InvalidArgumentError, Option } from "commander";
|
|
4
|
-
import { cancel, confirm, createLogger, formatCommandList, formatOptionList, getTheme, isCancel, note, promptText, renderTable, resetOutputFormatCache, select, text
|
|
4
|
+
import { cancel, confirm, createLogger, formatCommandList, formatOptionList, getTheme, helpFormatterPlain, isCancel, note, promptText, renderTable, resetOutputFormatCache, select, text } from "@poe-code/design-system";
|
|
5
5
|
import { ApprovalDeclinedError, UserError, assertCommandRequirements, getCommandSourcePath, resolveCommandSecrets } from "./index.js";
|
|
6
6
|
import { mergeApprovalsGroup } from "./human-in-loop/approvals-commands.js";
|
|
7
7
|
import { invokeWithHumanInLoop } from "./human-in-loop/index.js";
|
|
@@ -28,7 +28,7 @@ function normalizeRoots(roots, argv) {
|
|
|
28
28
|
name: inferProgramName(argv),
|
|
29
29
|
aliases: [],
|
|
30
30
|
secrets: {},
|
|
31
|
-
children: roots
|
|
31
|
+
children: roots
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
const HELP_FLAGS = new Set(["--help", "-h"]);
|
|
@@ -56,7 +56,9 @@ function splitWords(value) {
|
|
|
56
56
|
const isUppercase = char !== lower && char === upper;
|
|
57
57
|
const previous = value[index - 1];
|
|
58
58
|
const next = value[index + 1];
|
|
59
|
-
const previousIsLowercase = previous !== undefined &&
|
|
59
|
+
const previousIsLowercase = previous !== undefined &&
|
|
60
|
+
previous === previous.toLowerCase() &&
|
|
61
|
+
previous !== previous.toUpperCase();
|
|
60
62
|
const nextIsLowercase = next !== undefined && next === next.toLowerCase() && next !== next.toUpperCase();
|
|
61
63
|
if (isUppercase && current.length > 0 && (previousIsLowercase || nextIsLowercase)) {
|
|
62
64
|
words.push(current.toLowerCase());
|
|
@@ -116,7 +118,7 @@ function createSyntheticEnumSchema(values) {
|
|
|
116
118
|
}
|
|
117
119
|
return {
|
|
118
120
|
kind: "enum",
|
|
119
|
-
values: values
|
|
121
|
+
values: values
|
|
120
122
|
};
|
|
121
123
|
}
|
|
122
124
|
function getRequiredBranchFingerprint(branch, casing) {
|
|
@@ -130,7 +132,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
130
132
|
const collected = {
|
|
131
133
|
dynamicFields: [],
|
|
132
134
|
fields: [],
|
|
133
|
-
variants: []
|
|
135
|
+
variants: []
|
|
134
136
|
};
|
|
135
137
|
for (const [key, rawChildSchema] of Object.entries(schema.shape)) {
|
|
136
138
|
const nextPath = [...path, key];
|
|
@@ -160,14 +162,14 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
160
162
|
optional: runtimeOptional,
|
|
161
163
|
hasDefault: false,
|
|
162
164
|
defaultValue: undefined,
|
|
163
|
-
requiredWhenActive
|
|
165
|
+
requiredWhenActive
|
|
164
166
|
};
|
|
165
167
|
collected.fields.push(controlField);
|
|
166
168
|
const branches = [];
|
|
167
169
|
for (const [branchId, branchSchema] of Object.entries(childSchema.branches)) {
|
|
168
170
|
const branch = collectFields(branchSchema, casing, globalLongOptionFlags, nextPath, true, {
|
|
169
171
|
id: variantId,
|
|
170
|
-
branchId
|
|
172
|
+
branchId
|
|
171
173
|
});
|
|
172
174
|
collected.dynamicFields.push(...branch.dynamicFields);
|
|
173
175
|
collected.fields.push(...branch.fields);
|
|
@@ -181,7 +183,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
181
183
|
.map((field) => field.id),
|
|
182
184
|
requiredFieldIds: branch.fields
|
|
183
185
|
.filter((field) => field.requiredWhenActive)
|
|
184
|
-
.map((field) => field.id)
|
|
186
|
+
.map((field) => field.id)
|
|
185
187
|
});
|
|
186
188
|
}
|
|
187
189
|
collected.variants.push({
|
|
@@ -189,7 +191,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
189
191
|
controlDisplayPath: controlField.displayPath,
|
|
190
192
|
controlFieldId: controlField.id,
|
|
191
193
|
optional: runtimeOptional,
|
|
192
|
-
branches
|
|
194
|
+
branches
|
|
193
195
|
});
|
|
194
196
|
continue;
|
|
195
197
|
}
|
|
@@ -212,7 +214,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
212
214
|
hasDefault: false,
|
|
213
215
|
defaultValue: undefined,
|
|
214
216
|
requiredWhenActive,
|
|
215
|
-
synthetic: true
|
|
217
|
+
synthetic: true
|
|
216
218
|
};
|
|
217
219
|
collected.fields.push(controlField);
|
|
218
220
|
const branches = [];
|
|
@@ -220,7 +222,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
220
222
|
const branchId = branchIds[index] ?? "";
|
|
221
223
|
const branch = collectFields(branchSchema, casing, globalLongOptionFlags, nextPath, true, {
|
|
222
224
|
id: variantId,
|
|
223
|
-
branchId
|
|
225
|
+
branchId
|
|
224
226
|
});
|
|
225
227
|
collected.dynamicFields.push(...branch.dynamicFields);
|
|
226
228
|
collected.fields.push(...branch.fields);
|
|
@@ -234,7 +236,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
234
236
|
.map((field) => field.id),
|
|
235
237
|
requiredFieldIds: branch.fields
|
|
236
238
|
.filter((field) => field.requiredWhenActive)
|
|
237
|
-
.map((field) => field.id)
|
|
239
|
+
.map((field) => field.id)
|
|
238
240
|
});
|
|
239
241
|
});
|
|
240
242
|
collected.variants.push({
|
|
@@ -242,7 +244,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
242
244
|
controlDisplayPath,
|
|
243
245
|
controlFieldId: controlField.id,
|
|
244
246
|
optional: runtimeOptional,
|
|
245
|
-
branches
|
|
247
|
+
branches
|
|
246
248
|
});
|
|
247
249
|
continue;
|
|
248
250
|
}
|
|
@@ -261,7 +263,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
261
263
|
requiredWhenActive,
|
|
262
264
|
schema: childSchema,
|
|
263
265
|
variantId: variantContext?.id,
|
|
264
|
-
variantBranchId: variantContext?.branchId
|
|
266
|
+
variantBranchId: variantContext?.branchId
|
|
265
267
|
});
|
|
266
268
|
continue;
|
|
267
269
|
}
|
|
@@ -280,7 +282,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
280
282
|
requiredWhenActive,
|
|
281
283
|
schema: childSchema,
|
|
282
284
|
variantId: variantContext?.id,
|
|
283
|
-
variantBranchId: variantContext?.branchId
|
|
285
|
+
variantBranchId: variantContext?.branchId
|
|
284
286
|
});
|
|
285
287
|
continue;
|
|
286
288
|
}
|
|
@@ -299,7 +301,7 @@ function collectFields(schema, casing, globalLongOptionFlags, path = [], inherit
|
|
|
299
301
|
defaultValue: childSchema.default,
|
|
300
302
|
requiredWhenActive,
|
|
301
303
|
variantId: variantContext?.id,
|
|
302
|
-
variantBranchId: variantContext?.branchId
|
|
304
|
+
variantBranchId: variantContext?.branchId
|
|
303
305
|
});
|
|
304
306
|
}
|
|
305
307
|
return collected;
|
|
@@ -460,10 +462,12 @@ function createOption(field, globalLongOptionFlags) {
|
|
|
460
462
|
const mainOption = createCommanderOption(`${flags} [value]`, field.description, field);
|
|
461
463
|
mainOption.preset(true);
|
|
462
464
|
// Commander v14 passes the preset value through argParser too, so guard with typeof check
|
|
463
|
-
mainOption.argParser((value) => typeof value === "boolean"
|
|
465
|
+
mainOption.argParser((value) => typeof value === "boolean"
|
|
466
|
+
? value
|
|
467
|
+
: commanderValue(parseBooleanText(value, field.displayPath)));
|
|
464
468
|
return [
|
|
465
469
|
mainOption,
|
|
466
|
-
createCommanderOption(`--no-${field.optionFlag.slice(2)}`, field.description, field)
|
|
470
|
+
createCommanderOption(`--no-${field.optionFlag.slice(2)}`, field.description, field)
|
|
467
471
|
];
|
|
468
472
|
}
|
|
469
473
|
if (field.schema.kind === "array") {
|
|
@@ -474,16 +478,17 @@ function createOption(field, globalLongOptionFlags) {
|
|
|
474
478
|
return NULL_OPTION_VALUE;
|
|
475
479
|
}
|
|
476
480
|
return [...(previous ?? []), ...parsed];
|
|
477
|
-
})
|
|
481
|
+
})
|
|
478
482
|
];
|
|
479
483
|
}
|
|
480
484
|
if (field.schema.kind === "json") {
|
|
481
485
|
return [
|
|
482
|
-
createCommanderOption(`${flags} <json>`, field.description, field).argParser((value) => commanderValue(parseJsonText(value, field.displayPath)))
|
|
486
|
+
createCommanderOption(`${flags} <json>`, field.description, field).argParser((value) => commanderValue(parseJsonText(value, field.displayPath)))
|
|
483
487
|
];
|
|
484
488
|
}
|
|
485
489
|
const option = createCommanderOption(`${flags} <value>`, field.description, field);
|
|
486
|
-
if (field.schema.kind === "enum" &&
|
|
490
|
+
if (field.schema.kind === "enum" &&
|
|
491
|
+
field.schema.values.every((value) => typeof value === "string")) {
|
|
487
492
|
option.choices([...field.schema.values]);
|
|
488
493
|
}
|
|
489
494
|
option.argParser((value) => commanderValue(parseScalarValue(value, field.schema, field.displayPath)));
|
|
@@ -491,7 +496,9 @@ function createOption(field, globalLongOptionFlags) {
|
|
|
491
496
|
}
|
|
492
497
|
const ALWAYS_GLOBAL_LONG_OPTION_FLAGS = ["--yes", "--output", "--verbose"];
|
|
493
498
|
function getGlobalLongOptionFlags(presetsEnabled) {
|
|
494
|
-
return new Set(presetsEnabled
|
|
499
|
+
return new Set(presetsEnabled
|
|
500
|
+
? ["--preset", ...ALWAYS_GLOBAL_LONG_OPTION_FLAGS]
|
|
501
|
+
: ALWAYS_GLOBAL_LONG_OPTION_FLAGS);
|
|
495
502
|
}
|
|
496
503
|
function createCommanderOption(flags, description, field) {
|
|
497
504
|
const option = new Option(flags, description);
|
|
@@ -562,35 +569,23 @@ function resolveHelpTarget(root, argv, scope, rootDisplayName) {
|
|
|
562
569
|
}
|
|
563
570
|
return {
|
|
564
571
|
breadcrumb,
|
|
565
|
-
node: current
|
|
572
|
+
node: current
|
|
566
573
|
};
|
|
567
574
|
}
|
|
568
|
-
function describeSchemaType(schema) {
|
|
569
|
-
switch (schema.kind) {
|
|
570
|
-
case "string":
|
|
571
|
-
return "string";
|
|
572
|
-
case "number":
|
|
573
|
-
return "number";
|
|
574
|
-
case "boolean":
|
|
575
|
-
return "boolean";
|
|
576
|
-
case "enum":
|
|
577
|
-
return "value";
|
|
578
|
-
case "array":
|
|
579
|
-
return `${describeSchemaType(unwrapOptional(schema.item))}...`;
|
|
580
|
-
case "json":
|
|
581
|
-
return "json";
|
|
582
|
-
default:
|
|
583
|
-
throw new UserError("Unsupported CLI schema kind.");
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
575
|
function formatHelpFieldFlags(field, globalLongOptionFlags) {
|
|
587
576
|
if (field.positionalIndex !== undefined) {
|
|
588
577
|
return formatPositionalToken(field);
|
|
589
578
|
}
|
|
590
579
|
if (field.schema.kind === "boolean") {
|
|
591
|
-
|
|
580
|
+
if (field.defaultValue === true) {
|
|
581
|
+
return `--no-${field.optionFlag.slice(2)}`;
|
|
582
|
+
}
|
|
583
|
+
return formatOptionFlags(field, globalLongOptionFlags);
|
|
592
584
|
}
|
|
593
|
-
return `${formatOptionFlags(field, globalLongOptionFlags)} <${
|
|
585
|
+
return `${formatOptionFlags(field, globalLongOptionFlags)} <${describeHelpValueToken(field.schema, {
|
|
586
|
+
displayPath: field.displayPath,
|
|
587
|
+
optionFlag: field.optionFlag
|
|
588
|
+
})}>`;
|
|
594
589
|
}
|
|
595
590
|
function appendHelpMetadata(description, metadata) {
|
|
596
591
|
if (metadata.length === 0) {
|
|
@@ -612,6 +607,90 @@ function formatHelpFieldDescription(field) {
|
|
|
612
607
|
}
|
|
613
608
|
return appendHelpMetadata(description, metadata);
|
|
614
609
|
}
|
|
610
|
+
function describeKnownStringFormat(format) {
|
|
611
|
+
switch (format) {
|
|
612
|
+
case "date":
|
|
613
|
+
return "date";
|
|
614
|
+
case "date-time":
|
|
615
|
+
return "datetime";
|
|
616
|
+
case "uri":
|
|
617
|
+
return "url";
|
|
618
|
+
case "email":
|
|
619
|
+
return "email";
|
|
620
|
+
default:
|
|
621
|
+
return undefined;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function describeKnownStringPattern(pattern) {
|
|
625
|
+
if (pattern === undefined) {
|
|
626
|
+
return undefined;
|
|
627
|
+
}
|
|
628
|
+
if (pattern === "^\\d{4}-\\d{2}-\\d{2}$") {
|
|
629
|
+
return "YYYY-MM-DD";
|
|
630
|
+
}
|
|
631
|
+
if (pattern.startsWith("^\\d{4}-\\d{2}-\\d{2}T")) {
|
|
632
|
+
return "YYYY-MM-DDTHH:MM:SS";
|
|
633
|
+
}
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
function stripLongOptionPrefix(optionFlag) {
|
|
637
|
+
return optionFlag.startsWith("--") ? optionFlag.slice(2) : optionFlag;
|
|
638
|
+
}
|
|
639
|
+
function getLastSegment(value, separator) {
|
|
640
|
+
const segments = value.split(separator);
|
|
641
|
+
return segments[segments.length - 1] ?? value;
|
|
642
|
+
}
|
|
643
|
+
function matchesFieldNameSuffix(name, suffix) {
|
|
644
|
+
const lowerName = name.toLowerCase();
|
|
645
|
+
const lowerSuffix = suffix.toLowerCase();
|
|
646
|
+
return (lowerName === lowerSuffix ||
|
|
647
|
+
name.endsWith(suffix) ||
|
|
648
|
+
lowerName.endsWith(`-${lowerSuffix}`) ||
|
|
649
|
+
lowerName.endsWith(`_${lowerSuffix}`));
|
|
650
|
+
}
|
|
651
|
+
function describeFieldNameValueToken(displayPath, optionFlag) {
|
|
652
|
+
const displayName = getLastSegment(displayPath, ".");
|
|
653
|
+
const optionName = getLastSegment(stripLongOptionPrefix(optionFlag), ".");
|
|
654
|
+
const candidates = [displayName, optionName];
|
|
655
|
+
const suffixTokens = [
|
|
656
|
+
["Path", "path"],
|
|
657
|
+
["Paths", "path"],
|
|
658
|
+
["File", "path"],
|
|
659
|
+
["Files", "path"],
|
|
660
|
+
["Url", "url"],
|
|
661
|
+
["Email", "email"],
|
|
662
|
+
["Name", "name"],
|
|
663
|
+
["Id", "id"]
|
|
664
|
+
];
|
|
665
|
+
for (const [suffix, token] of suffixTokens) {
|
|
666
|
+
if (candidates.some((candidate) => matchesFieldNameSuffix(candidate, suffix))) {
|
|
667
|
+
return token;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
function describeHelpValueToken(schema, field) {
|
|
673
|
+
if (schema.kind === "array") {
|
|
674
|
+
const itemSchema = unwrapOptional(schema.item);
|
|
675
|
+
if (itemSchema.kind === "array" || itemSchema.kind === "object") {
|
|
676
|
+
return "value...";
|
|
677
|
+
}
|
|
678
|
+
return `${describeHelpValueToken(itemSchema, field)}...`;
|
|
679
|
+
}
|
|
680
|
+
if (schema.kind === "json") {
|
|
681
|
+
return "json";
|
|
682
|
+
}
|
|
683
|
+
if (schema.kind === "string") {
|
|
684
|
+
const metadataToken = describeKnownStringFormat(schema.format) ?? describeKnownStringPattern(schema.pattern);
|
|
685
|
+
if (metadataToken !== undefined) {
|
|
686
|
+
return metadataToken;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (schema.kind === "enum") {
|
|
690
|
+
return "value";
|
|
691
|
+
}
|
|
692
|
+
return describeFieldNameValueToken(field.displayPath, field.optionFlag) ?? "value";
|
|
693
|
+
}
|
|
615
694
|
function describeDynamicFieldType(field) {
|
|
616
695
|
if (field.schema.kind === "record") {
|
|
617
696
|
const valueSchema = unwrapOptional(field.schema.value);
|
|
@@ -619,12 +698,18 @@ function describeDynamicFieldType(field) {
|
|
|
619
698
|
return "json";
|
|
620
699
|
}
|
|
621
700
|
if (valueSchema.kind === "array") {
|
|
622
|
-
return
|
|
701
|
+
return describeHelpValueToken(valueSchema, {
|
|
702
|
+
displayPath: field.optionPathDisplay,
|
|
703
|
+
optionFlag: field.optionFlag
|
|
704
|
+
});
|
|
623
705
|
}
|
|
624
706
|
if (valueSchema.kind === "object") {
|
|
625
707
|
return "value";
|
|
626
708
|
}
|
|
627
|
-
return
|
|
709
|
+
return describeHelpValueToken(valueSchema, {
|
|
710
|
+
displayPath: field.optionPathDisplay,
|
|
711
|
+
optionFlag: field.optionFlag
|
|
712
|
+
});
|
|
628
713
|
}
|
|
629
714
|
return "value";
|
|
630
715
|
}
|
|
@@ -663,10 +748,10 @@ function collectDynamicObjectHelpRows(schema, casing, optionPrefix, displayPrefi
|
|
|
663
748
|
hasDefault: false,
|
|
664
749
|
defaultValue: undefined,
|
|
665
750
|
requiredWhenActive: false,
|
|
666
|
-
schema: childSchema
|
|
667
|
-
}
|
|
751
|
+
schema: childSchema
|
|
752
|
+
}
|
|
668
753
|
})}>`,
|
|
669
|
-
description: appendHelpMetadata(description, metadata)
|
|
754
|
+
description: appendHelpMetadata(description, metadata)
|
|
670
755
|
});
|
|
671
756
|
continue;
|
|
672
757
|
}
|
|
@@ -676,9 +761,14 @@ function collectDynamicObjectHelpRows(schema, casing, optionPrefix, displayPrefi
|
|
|
676
761
|
}
|
|
677
762
|
rows.push({
|
|
678
763
|
flags: childSchema.kind === "boolean"
|
|
679
|
-
?
|
|
680
|
-
|
|
681
|
-
|
|
764
|
+
? childSchema.default === true
|
|
765
|
+
? `--no-${optionFlag.slice(2)}`
|
|
766
|
+
: optionFlag
|
|
767
|
+
: `${optionFlag} <${describeHelpValueToken(childSchema, {
|
|
768
|
+
displayPath,
|
|
769
|
+
optionFlag
|
|
770
|
+
})}>`,
|
|
771
|
+
description: appendHelpMetadata(description, metadata)
|
|
682
772
|
});
|
|
683
773
|
}
|
|
684
774
|
return rows;
|
|
@@ -697,15 +787,17 @@ function formatDynamicHelpFields(field, casing) {
|
|
|
697
787
|
return collectDynamicObjectHelpRows(itemSchema, casing, `${field.optionFlag}`, `${field.optionPathDisplay}`, metadata);
|
|
698
788
|
}
|
|
699
789
|
}
|
|
700
|
-
return [
|
|
790
|
+
return [
|
|
791
|
+
{
|
|
701
792
|
flags: `${field.optionFlag} <${describeDynamicFieldType(field)}>`,
|
|
702
|
-
description: appendHelpMetadata(field.description ?? field.optionPathDisplay, metadata)
|
|
703
|
-
}
|
|
793
|
+
description: appendHelpMetadata(field.description ?? field.optionPathDisplay, metadata)
|
|
794
|
+
}
|
|
795
|
+
];
|
|
704
796
|
}
|
|
705
797
|
function formatSecretRows(secrets) {
|
|
706
798
|
return Object.values(secrets).map((secret) => ({
|
|
707
799
|
flags: secret.env,
|
|
708
|
-
description: formatSecretDescription(secret)
|
|
800
|
+
description: formatSecretDescription(secret)
|
|
709
801
|
}));
|
|
710
802
|
}
|
|
711
803
|
function formatSecretDescription(secret) {
|
|
@@ -728,46 +820,39 @@ function formatCommandParameterTokens(command, casing, globalLongOptionFlags) {
|
|
|
728
820
|
.map((field) => wrapOptionalCommandParameterToken(formatHelpFieldFlags(field, globalLongOptionFlags), field.positionalIndex === undefined && (field.optional || field.hasDefault)))
|
|
729
821
|
.concat(collected.dynamicFields.flatMap((field) => formatCommandDynamicParameterTokens(field, casing)));
|
|
730
822
|
}
|
|
731
|
-
function formatCommandRowName(node,
|
|
823
|
+
function formatCommandRowName(node, casing, globalLongOptionFlags) {
|
|
732
824
|
const baseName = node.aliases.length === 0 ? node.name : `${node.name} (${node.aliases.join(", ")})`;
|
|
733
|
-
const parameterTokens = node.kind === "command"
|
|
825
|
+
const parameterTokens = node.kind === "command"
|
|
826
|
+
? formatCommandParameterTokens(node, casing, globalLongOptionFlags)
|
|
827
|
+
: [];
|
|
734
828
|
const name = parameterTokens.length === 0 ? baseName : `${baseName} ${parameterTokens.join(" ")}`;
|
|
735
|
-
return
|
|
829
|
+
return name;
|
|
736
830
|
}
|
|
737
|
-
function formatCommandRows(group, scope, casing, globalLongOptionFlags
|
|
738
|
-
return getVisibleChildren(group, scope).
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
};
|
|
743
|
-
if (child.kind === "command") {
|
|
744
|
-
return [row];
|
|
745
|
-
}
|
|
746
|
-
return [row, ...formatCommandRows(child, scope, casing, globalLongOptionFlags, depth + 1)];
|
|
747
|
-
});
|
|
831
|
+
function formatCommandRows(group, scope, casing, globalLongOptionFlags) {
|
|
832
|
+
return getVisibleChildren(group, scope).map((child) => ({
|
|
833
|
+
name: formatCommandRowName(child, casing, globalLongOptionFlags),
|
|
834
|
+
description: child.description ?? ""
|
|
835
|
+
}));
|
|
748
836
|
}
|
|
749
|
-
function formatGlobalOptionRows(
|
|
837
|
+
function formatGlobalOptionRows(ctx) {
|
|
750
838
|
const rows = [];
|
|
751
|
-
if (presetsEnabled) {
|
|
839
|
+
if (ctx.presetsEnabled) {
|
|
752
840
|
rows.push({
|
|
753
841
|
flags: "--preset <path>",
|
|
754
|
-
description: "Load parameter defaults from a JSON file"
|
|
842
|
+
description: "Load parameter defaults from a JSON file"
|
|
755
843
|
});
|
|
756
844
|
}
|
|
757
845
|
rows.push({
|
|
758
846
|
flags: "--yes",
|
|
759
|
-
description: "Accept defaults, skip prompts"
|
|
847
|
+
description: "Accept defaults, skip prompts"
|
|
760
848
|
}, {
|
|
761
849
|
flags: "--output <format>",
|
|
762
|
-
description: "Output format
|
|
763
|
-
}, {
|
|
764
|
-
flags: "-h, --help",
|
|
765
|
-
description: "Show help",
|
|
850
|
+
description: "Output format: rich, md, json."
|
|
766
851
|
});
|
|
767
|
-
if (showVersion) {
|
|
852
|
+
if (ctx.showVersion) {
|
|
768
853
|
rows.push({
|
|
769
854
|
flags: "--version",
|
|
770
|
-
description: "Show version"
|
|
855
|
+
description: "Show version"
|
|
771
856
|
});
|
|
772
857
|
}
|
|
773
858
|
return rows;
|
|
@@ -775,45 +860,58 @@ function formatGlobalOptionRows(showVersion, presetsEnabled) {
|
|
|
775
860
|
function renderHelpSections(sections) {
|
|
776
861
|
return sections.filter((section) => section.length > 0).join("\n\n");
|
|
777
862
|
}
|
|
863
|
+
function formatHelpCommandList(rows) {
|
|
864
|
+
return process.stdout.isTTY === false
|
|
865
|
+
? helpFormatterPlain.formatCommandList(rows)
|
|
866
|
+
: formatCommandList(rows);
|
|
867
|
+
}
|
|
868
|
+
function formatHelpOptionList(rows) {
|
|
869
|
+
return process.stdout.isTTY === false
|
|
870
|
+
? helpFormatterPlain.formatOptionList(rows)
|
|
871
|
+
: formatOptionList(rows);
|
|
872
|
+
}
|
|
778
873
|
function buildUsageLine(breadcrumb, rootUsageName, suffix) {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
const
|
|
783
|
-
return
|
|
874
|
+
const visibleBreadcrumb = breadcrumb.filter((segment) => segment.length > 0);
|
|
875
|
+
const usageBreadcrumb = breadcrumb[0] === "" ? [rootUsageName, ...visibleBreadcrumb] : visibleBreadcrumb;
|
|
876
|
+
const subPath = usageBreadcrumb.slice(1).join(" ");
|
|
877
|
+
const tokens = [rootUsageName, subPath, suffix].filter((segment) => segment.length > 0);
|
|
878
|
+
return tokens.join(" ");
|
|
784
879
|
}
|
|
785
|
-
function renderGroupHelp(group, breadcrumb, scope, casing,
|
|
880
|
+
function renderGroupHelp(group, breadcrumb, scope, casing, globalOptions, rootUsageName) {
|
|
786
881
|
const sections = [];
|
|
787
|
-
const globalLongOptionFlags = getGlobalLongOptionFlags(presetsEnabled);
|
|
882
|
+
const globalLongOptionFlags = getGlobalLongOptionFlags(globalOptions.presetsEnabled);
|
|
788
883
|
const commandRows = formatCommandRows(group, scope, casing, globalLongOptionFlags);
|
|
789
884
|
if (commandRows.length > 0) {
|
|
790
|
-
sections.push(`${text.
|
|
885
|
+
sections.push(`${text.sectionHeader("Commands")}\n${formatHelpCommandList(commandRows)}`);
|
|
791
886
|
}
|
|
792
|
-
sections.push(`${text.
|
|
887
|
+
sections.push(`${text.sectionHeader("Options")}\n${formatHelpOptionList(formatGlobalOptionRows(globalOptions))}`);
|
|
793
888
|
return renderHelpDocument({
|
|
794
889
|
breadcrumb,
|
|
795
|
-
|
|
890
|
+
rootUsageName,
|
|
891
|
+
usageLine: buildUsageLine(breadcrumb, rootUsageName, "[command] [options]"),
|
|
796
892
|
description: group.description,
|
|
797
893
|
requiresAuth: group.requires?.auth === true,
|
|
798
|
-
sections
|
|
894
|
+
sections
|
|
799
895
|
});
|
|
800
896
|
}
|
|
801
|
-
function renderLeafHelp(command, breadcrumb, casing,
|
|
897
|
+
function renderLeafHelp(command, breadcrumb, casing, globalOptions, rootUsageName) {
|
|
802
898
|
const sections = [];
|
|
803
|
-
const globalLongOptionFlags = getGlobalLongOptionFlags(presetsEnabled);
|
|
899
|
+
const globalLongOptionFlags = getGlobalLongOptionFlags(globalOptions.presetsEnabled);
|
|
804
900
|
const collected = collectFields(command.params, casing, globalLongOptionFlags);
|
|
805
901
|
const fields = assignPositionals(collected.fields, command.positional);
|
|
806
|
-
const optionRows = fields
|
|
902
|
+
const optionRows = fields
|
|
903
|
+
.map((field) => ({
|
|
807
904
|
flags: formatHelpFieldFlags(field, globalLongOptionFlags),
|
|
808
|
-
description: formatHelpFieldDescription(field)
|
|
809
|
-
}))
|
|
905
|
+
description: formatHelpFieldDescription(field)
|
|
906
|
+
}))
|
|
907
|
+
.concat(collected.dynamicFields.flatMap((field) => formatDynamicHelpFields(field, casing)));
|
|
810
908
|
if (optionRows.length > 0) {
|
|
811
|
-
sections.push(`${text.
|
|
909
|
+
sections.push(`${text.sectionHeader("Options")}\n${formatHelpOptionList(optionRows)}`);
|
|
812
910
|
}
|
|
813
|
-
sections.push(`${text.
|
|
911
|
+
sections.push(`${text.sectionHeader("Options")}\n${formatHelpOptionList(formatGlobalOptionRows(globalOptions))}`);
|
|
814
912
|
const secretRows = formatSecretRows(command.secrets);
|
|
815
913
|
if (secretRows.length > 0) {
|
|
816
|
-
sections.push(`${text.
|
|
914
|
+
sections.push(`${text.sectionHeader("Secrets (environment)")}\n${formatHelpOptionList(secretRows)}`);
|
|
817
915
|
}
|
|
818
916
|
const positionalFields = fields.filter((f) => f.positionalIndex !== undefined);
|
|
819
917
|
const usageSuffix = positionalFields.length > 0
|
|
@@ -821,24 +919,29 @@ function renderLeafHelp(command, breadcrumb, casing, presetsEnabled, rootUsageNa
|
|
|
821
919
|
: "[options]";
|
|
822
920
|
return renderHelpDocument({
|
|
823
921
|
breadcrumb,
|
|
922
|
+
rootUsageName,
|
|
824
923
|
usageLine: buildUsageLine(breadcrumb, rootUsageName, usageSuffix),
|
|
825
924
|
description: command.description,
|
|
826
925
|
requiresAuth: command.requires?.auth === true,
|
|
827
|
-
sections
|
|
926
|
+
sections
|
|
828
927
|
});
|
|
829
928
|
}
|
|
830
929
|
function renderHelpDocument(input) {
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
930
|
+
const title = input.breadcrumb.filter((segment) => segment.length > 0).join(" ") || input.rootUsageName;
|
|
931
|
+
const description = input.description ?? "";
|
|
932
|
+
const sentenceEndIndex = description.indexOf(". ");
|
|
933
|
+
const headingDescription = sentenceEndIndex === -1 ? description : description.slice(0, sentenceEndIndex + 1);
|
|
934
|
+
const remainingDescription = sentenceEndIndex === -1 ? "" : description.slice(sentenceEndIndex + 2);
|
|
935
|
+
const heading = headingDescription.length > 0 ? `${title} — ${headingDescription}` : title;
|
|
936
|
+
const lines = [text.heading(heading), ""];
|
|
937
|
+
if (remainingDescription.length > 0) {
|
|
938
|
+
lines.push(remainingDescription, "");
|
|
939
|
+
}
|
|
940
|
+
lines.push(`Usage: ${text.usageCommand(input.usageLine)}`, "");
|
|
838
941
|
if (input.requiresAuth) {
|
|
839
942
|
lines.push("Requires: authentication");
|
|
840
943
|
}
|
|
841
|
-
if (input.
|
|
944
|
+
if (input.requiresAuth) {
|
|
842
945
|
lines.push("");
|
|
843
946
|
}
|
|
844
947
|
lines.push(renderHelpSections(input.sections));
|
|
@@ -848,10 +951,17 @@ async function renderGeneratedHelp(root, argv, options) {
|
|
|
848
951
|
const target = resolveHelpTarget(root, argv, "cli", options.rootDisplayName);
|
|
849
952
|
const output = resolveHelpOutput(argv);
|
|
850
953
|
const casing = options.casing ?? "kebab";
|
|
954
|
+
const rootUsageName = options.rootUsageName ?? inferProgramName(argv);
|
|
851
955
|
await withOutputFormat(output, async () => {
|
|
852
956
|
const rendered = target.node.kind === "group"
|
|
853
|
-
? renderGroupHelp(target.node, target.breadcrumb, "cli", casing,
|
|
854
|
-
|
|
957
|
+
? renderGroupHelp(target.node, target.breadcrumb, "cli", casing, {
|
|
958
|
+
showVersion: options.version !== undefined,
|
|
959
|
+
presetsEnabled: options.presets === true
|
|
960
|
+
}, rootUsageName)
|
|
961
|
+
: renderLeafHelp(target.node, target.breadcrumb, casing, {
|
|
962
|
+
showVersion: options.version !== undefined,
|
|
963
|
+
presetsEnabled: options.presets === true
|
|
964
|
+
}, rootUsageName);
|
|
855
965
|
process.stdout.write(rendered);
|
|
856
966
|
});
|
|
857
967
|
}
|
|
@@ -896,7 +1006,7 @@ function createNodeCommand(node, casing, globalLongOptionFlags, execute, presets
|
|
|
896
1006
|
presetsEnabled,
|
|
897
1007
|
rawArgv: actionCommand.args,
|
|
898
1008
|
actionCommand,
|
|
899
|
-
variants: collected.variants
|
|
1009
|
+
variants: collected.variants
|
|
900
1010
|
});
|
|
901
1011
|
});
|
|
902
1012
|
return command;
|
|
@@ -973,12 +1083,12 @@ async function promptForField(field) {
|
|
|
973
1083
|
? await schema.loadOptions()
|
|
974
1084
|
: schema.values.map((value) => ({
|
|
975
1085
|
label: schema.labels?.[String(value)] ?? String(value),
|
|
976
|
-
value
|
|
1086
|
+
value
|
|
977
1087
|
}));
|
|
978
1088
|
const selected = await select({
|
|
979
1089
|
message: field.description ?? field.displayPath,
|
|
980
1090
|
options,
|
|
981
|
-
initialValue: field.hasDefault ? field.defaultValue : undefined
|
|
1091
|
+
initialValue: field.hasDefault ? field.defaultValue : undefined
|
|
982
1092
|
});
|
|
983
1093
|
if (isCancel(selected)) {
|
|
984
1094
|
cancel("Operation cancelled.");
|
|
@@ -989,7 +1099,7 @@ async function promptForField(field) {
|
|
|
989
1099
|
if (field.schema.kind === "boolean") {
|
|
990
1100
|
const selected = await confirm({
|
|
991
1101
|
message: field.displayPath,
|
|
992
|
-
initialValue: field.hasDefault ? Boolean(field.defaultValue) : undefined
|
|
1102
|
+
initialValue: field.hasDefault ? Boolean(field.defaultValue) : undefined
|
|
993
1103
|
});
|
|
994
1104
|
if (isCancel(selected)) {
|
|
995
1105
|
cancel("Operation cancelled.");
|
|
@@ -1001,7 +1111,7 @@ async function promptForField(field) {
|
|
|
1001
1111
|
message: field.displayPath,
|
|
1002
1112
|
initialValue: field.hasDefault && field.defaultValue !== undefined
|
|
1003
1113
|
? formatResolvedValue(field.defaultValue)
|
|
1004
|
-
: undefined
|
|
1114
|
+
: undefined
|
|
1005
1115
|
});
|
|
1006
1116
|
if (isCancel(entered)) {
|
|
1007
1117
|
cancel("Operation cancelled.");
|
|
@@ -1036,7 +1146,7 @@ function resolveOutput(resolvedFlags) {
|
|
|
1036
1146
|
const DESIGN_SYSTEM_OUTPUT_BY_MODE = {
|
|
1037
1147
|
rich: "terminal",
|
|
1038
1148
|
md: "markdown",
|
|
1039
|
-
json: "json"
|
|
1149
|
+
json: "json"
|
|
1040
1150
|
};
|
|
1041
1151
|
function toDesignSystemOutput(output) {
|
|
1042
1152
|
return DESIGN_SYSTEM_OUTPUT_BY_MODE[output];
|
|
@@ -1072,14 +1182,14 @@ function createFs() {
|
|
|
1072
1182
|
catch {
|
|
1073
1183
|
return false;
|
|
1074
1184
|
}
|
|
1075
|
-
}
|
|
1185
|
+
}
|
|
1076
1186
|
};
|
|
1077
1187
|
}
|
|
1078
1188
|
function createEnv(values = process.env) {
|
|
1079
1189
|
return {
|
|
1080
1190
|
get(key) {
|
|
1081
1191
|
return values[key];
|
|
1082
|
-
}
|
|
1192
|
+
}
|
|
1083
1193
|
};
|
|
1084
1194
|
}
|
|
1085
1195
|
function isPlainObject(value) {
|
|
@@ -1157,19 +1267,14 @@ async function loadPresetValues(fields, presetPath) {
|
|
|
1157
1267
|
let rawPreset;
|
|
1158
1268
|
try {
|
|
1159
1269
|
rawPreset = await readFile(presetPath, {
|
|
1160
|
-
encoding: "utf8"
|
|
1270
|
+
encoding: "utf8"
|
|
1161
1271
|
});
|
|
1162
1272
|
}
|
|
1163
1273
|
catch (error) {
|
|
1164
|
-
if (typeof error === "object" &&
|
|
1165
|
-
error !== null &&
|
|
1166
|
-
"code" in error &&
|
|
1167
|
-
error.code === "ENOENT") {
|
|
1274
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
1168
1275
|
throw new UserError(`Preset file "${presetPath}" was not found.`);
|
|
1169
1276
|
}
|
|
1170
|
-
const message = error instanceof Error && error.message.length > 0
|
|
1171
|
-
? error.message
|
|
1172
|
-
: "Unknown read error.";
|
|
1277
|
+
const message = error instanceof Error && error.message.length > 0 ? error.message : "Unknown read error.";
|
|
1173
1278
|
throw new UserError(`Preset file "${presetPath}" could not be read: ${message}`);
|
|
1174
1279
|
}
|
|
1175
1280
|
let parsedPreset;
|
|
@@ -1282,13 +1387,13 @@ function createFixtureResponse(response) {
|
|
|
1282
1387
|
if (response.body === undefined) {
|
|
1283
1388
|
return new Response(null, {
|
|
1284
1389
|
status,
|
|
1285
|
-
headers
|
|
1390
|
+
headers
|
|
1286
1391
|
});
|
|
1287
1392
|
}
|
|
1288
1393
|
if (typeof response.body === "string") {
|
|
1289
1394
|
return new Response(response.body, {
|
|
1290
1395
|
status,
|
|
1291
|
-
headers
|
|
1396
|
+
headers
|
|
1292
1397
|
});
|
|
1293
1398
|
}
|
|
1294
1399
|
if (!headers.has("content-type")) {
|
|
@@ -1296,7 +1401,7 @@ function createFixtureResponse(response) {
|
|
|
1296
1401
|
}
|
|
1297
1402
|
return new Response(JSON.stringify(response.body), {
|
|
1298
1403
|
status,
|
|
1299
|
-
headers
|
|
1404
|
+
headers
|
|
1300
1405
|
});
|
|
1301
1406
|
}
|
|
1302
1407
|
function createFixtureFetch(entries) {
|
|
@@ -1314,7 +1419,7 @@ function createFixtureFetch(entries) {
|
|
|
1314
1419
|
return null;
|
|
1315
1420
|
}
|
|
1316
1421
|
return new Response(null, {
|
|
1317
|
-
status: 204
|
|
1422
|
+
status: 204
|
|
1318
1423
|
});
|
|
1319
1424
|
};
|
|
1320
1425
|
}
|
|
@@ -1335,7 +1440,7 @@ function createFixtureFs(definition) {
|
|
|
1335
1440
|
return Boolean(existsEntries[filePath]);
|
|
1336
1441
|
}
|
|
1337
1442
|
return Object.prototype.hasOwnProperty.call(readFileEntries, filePath);
|
|
1338
|
-
}
|
|
1443
|
+
}
|
|
1339
1444
|
};
|
|
1340
1445
|
}
|
|
1341
1446
|
function resolveFixtureMethodResult(methodName, definition, args) {
|
|
@@ -1379,7 +1484,8 @@ function resolveFixtureMethodResult(methodName, definition, args) {
|
|
|
1379
1484
|
}
|
|
1380
1485
|
if (isPlainObject(definition)) {
|
|
1381
1486
|
const firstArg = args[0];
|
|
1382
|
-
if (typeof firstArg === "string" &&
|
|
1487
|
+
if (typeof firstArg === "string" &&
|
|
1488
|
+
Object.prototype.hasOwnProperty.call(definition, firstArg)) {
|
|
1383
1489
|
return Promise.resolve(definition[firstArg]);
|
|
1384
1490
|
}
|
|
1385
1491
|
}
|
|
@@ -1397,7 +1503,7 @@ function createFixtureService(definition) {
|
|
|
1397
1503
|
}
|
|
1398
1504
|
const methodName = String(property);
|
|
1399
1505
|
return async (...args) => resolveFixtureMethodResult(methodName, methods[methodName], args);
|
|
1400
|
-
}
|
|
1506
|
+
}
|
|
1401
1507
|
});
|
|
1402
1508
|
}
|
|
1403
1509
|
function resolveFixturePath(commandPath) {
|
|
@@ -1428,7 +1534,7 @@ async function loadFixtureScenario(command, selector) {
|
|
|
1428
1534
|
let rawFixture;
|
|
1429
1535
|
try {
|
|
1430
1536
|
rawFixture = await readFile(fixturePath, {
|
|
1431
|
-
encoding: "utf8"
|
|
1537
|
+
encoding: "utf8"
|
|
1432
1538
|
});
|
|
1433
1539
|
}
|
|
1434
1540
|
catch {
|
|
@@ -1452,7 +1558,7 @@ function resolveFixtureSecrets(command) {
|
|
|
1452
1558
|
function createFixtureEnvValues(command) {
|
|
1453
1559
|
const values = {
|
|
1454
1560
|
...process.env,
|
|
1455
|
-
POE_API_KEY: process.env.POE_API_KEY ?? "fixture-secret"
|
|
1561
|
+
POE_API_KEY: process.env.POE_API_KEY ?? "fixture-secret"
|
|
1456
1562
|
};
|
|
1457
1563
|
for (const secret of Object.values(command.secrets)) {
|
|
1458
1564
|
values[secret.env] = values[secret.env] ?? "fixture-secret";
|
|
@@ -1469,14 +1575,14 @@ async function resolveFixtureRuntime(command, services, requirementOptions) {
|
|
|
1469
1575
|
isFixture: false,
|
|
1470
1576
|
requirementOptions,
|
|
1471
1577
|
secrets: resolveCommandSecrets(command),
|
|
1472
|
-
services
|
|
1578
|
+
services
|
|
1473
1579
|
};
|
|
1474
1580
|
}
|
|
1475
1581
|
const scenario = await loadFixtureScenario(command, selector);
|
|
1476
1582
|
const scenarioServices = isPlainObject(scenario.services) ? scenario.services : {};
|
|
1477
1583
|
const customServiceNames = new Set([
|
|
1478
1584
|
...Object.keys(services),
|
|
1479
|
-
...Object.keys(scenarioServices).filter((name) => !RESERVED_SERVICE_NAMES.has(name))
|
|
1585
|
+
...Object.keys(scenarioServices).filter((name) => !RESERVED_SERVICE_NAMES.has(name))
|
|
1480
1586
|
]);
|
|
1481
1587
|
const fixtureServices = Object.fromEntries([...customServiceNames].map((name) => [name, createFixtureService(scenarioServices[name])]));
|
|
1482
1588
|
const fixtureEnvValues = createFixtureEnvValues(command);
|
|
@@ -1487,10 +1593,10 @@ async function resolveFixtureRuntime(command, services, requirementOptions) {
|
|
|
1487
1593
|
isFixture: true,
|
|
1488
1594
|
requirementOptions: {
|
|
1489
1595
|
...requirementOptions,
|
|
1490
|
-
env: fixtureEnvValues
|
|
1596
|
+
env: fixtureEnvValues
|
|
1491
1597
|
},
|
|
1492
1598
|
secrets: resolveFixtureSecrets(command),
|
|
1493
|
-
services: fixtureServices
|
|
1599
|
+
services: fixtureServices
|
|
1494
1600
|
};
|
|
1495
1601
|
}
|
|
1496
1602
|
function writeRichHeader(title) {
|
|
@@ -1544,25 +1650,25 @@ function consumeFieldValue(args, index, schema, label, inlineValue) {
|
|
|
1544
1650
|
if (inlineValue !== undefined) {
|
|
1545
1651
|
return {
|
|
1546
1652
|
nextIndex: index,
|
|
1547
|
-
value: parseScalarValue(inlineValue, schema, label)
|
|
1653
|
+
value: parseScalarValue(inlineValue, schema, label)
|
|
1548
1654
|
};
|
|
1549
1655
|
}
|
|
1550
1656
|
const next = args[index + 1];
|
|
1551
1657
|
if (next === "true" || next === "false" || (schema.nullable === true && next === "null")) {
|
|
1552
1658
|
return {
|
|
1553
1659
|
nextIndex: index + 1,
|
|
1554
|
-
value: parseScalarValue(next, schema, label)
|
|
1660
|
+
value: parseScalarValue(next, schema, label)
|
|
1555
1661
|
};
|
|
1556
1662
|
}
|
|
1557
1663
|
return {
|
|
1558
1664
|
nextIndex: index,
|
|
1559
|
-
value: true
|
|
1665
|
+
value: true
|
|
1560
1666
|
};
|
|
1561
1667
|
}
|
|
1562
1668
|
if (inlineValue !== undefined) {
|
|
1563
1669
|
return {
|
|
1564
1670
|
nextIndex: index,
|
|
1565
|
-
value: parseFieldInputValue(inlineValue, schema, label)
|
|
1671
|
+
value: parseFieldInputValue(inlineValue, schema, label)
|
|
1566
1672
|
};
|
|
1567
1673
|
}
|
|
1568
1674
|
if (schema.kind === "array") {
|
|
@@ -1578,7 +1684,7 @@ function consumeFieldValue(args, index, schema, label, inlineValue) {
|
|
|
1578
1684
|
if (parsed === null) {
|
|
1579
1685
|
return {
|
|
1580
1686
|
nextIndex: cursor,
|
|
1581
|
-
value: null
|
|
1687
|
+
value: null
|
|
1582
1688
|
};
|
|
1583
1689
|
}
|
|
1584
1690
|
values.push(...parsed);
|
|
@@ -1590,7 +1696,7 @@ function consumeFieldValue(args, index, schema, label, inlineValue) {
|
|
|
1590
1696
|
}
|
|
1591
1697
|
return {
|
|
1592
1698
|
nextIndex,
|
|
1593
|
-
value: values
|
|
1699
|
+
value: values
|
|
1594
1700
|
};
|
|
1595
1701
|
}
|
|
1596
1702
|
const next = args[index + 1];
|
|
@@ -1599,7 +1705,7 @@ function consumeFieldValue(args, index, schema, label, inlineValue) {
|
|
|
1599
1705
|
}
|
|
1600
1706
|
return {
|
|
1601
1707
|
nextIndex: index + 1,
|
|
1602
|
-
value: parseFieldInputValue(next, schema, label)
|
|
1708
|
+
value: parseFieldInputValue(next, schema, label)
|
|
1603
1709
|
};
|
|
1604
1710
|
}
|
|
1605
1711
|
function resolveDynamicLeaf(schema, rawSegments, casing, outputPath = [], displayPath = []) {
|
|
@@ -1614,7 +1720,7 @@ function resolveDynamicLeaf(schema, rawSegments, casing, outputPath = [], displa
|
|
|
1614
1720
|
return {
|
|
1615
1721
|
displayPath: toDisplayPath(displayPath),
|
|
1616
1722
|
path: outputPath,
|
|
1617
|
-
schema: unwrappedSchema
|
|
1723
|
+
schema: unwrappedSchema
|
|
1618
1724
|
};
|
|
1619
1725
|
}
|
|
1620
1726
|
throw new UserError(`Unsupported dynamic CLI schema kind "${unwrappedSchema.kind}".`);
|
|
@@ -1713,7 +1819,7 @@ function finalizeDynamicValue(schema, value, displayPath) {
|
|
|
1713
1819
|
}
|
|
1714
1820
|
return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
|
|
1715
1821
|
key,
|
|
1716
|
-
finalizeDynamicValue(unwrappedSchema.value, entryValue, displayPath.length === 0 ? key : `${displayPath}.${key}`)
|
|
1822
|
+
finalizeDynamicValue(unwrappedSchema.value, entryValue, displayPath.length === 0 ? key : `${displayPath}.${key}`)
|
|
1717
1823
|
]));
|
|
1718
1824
|
}
|
|
1719
1825
|
default:
|
|
@@ -1751,7 +1857,7 @@ function parseDynamicValues(dynamicFields, rawArgv, casing) {
|
|
|
1751
1857
|
const parsed = negated && leaf.schema.kind === "boolean"
|
|
1752
1858
|
? {
|
|
1753
1859
|
nextIndex: index,
|
|
1754
|
-
value: false
|
|
1860
|
+
value: false
|
|
1755
1861
|
}
|
|
1756
1862
|
: consumeFieldValue(rawArgv, index, leaf.schema, label, inlineValue);
|
|
1757
1863
|
setNestedValue(rawStore, leaf.path, parsed.value);
|
|
@@ -1765,8 +1871,8 @@ function parseDynamicValues(dynamicFields, rawArgv, casing) {
|
|
|
1765
1871
|
.filter((field) => rawValues.has(field.id))
|
|
1766
1872
|
.map((field) => [
|
|
1767
1873
|
field.id,
|
|
1768
|
-
finalizeDynamicValue(field.schema.kind === "record" ? field.schema : field.schema, rawValues.get(field.id), field.displayPath)
|
|
1769
|
-
]))
|
|
1874
|
+
finalizeDynamicValue(field.schema.kind === "record" ? field.schema : field.schema, rawValues.get(field.id), field.displayPath)
|
|
1875
|
+
]))
|
|
1770
1876
|
};
|
|
1771
1877
|
}
|
|
1772
1878
|
async function enforceVariantConstraints(params, fields, dynamicFields, variants, resolvedFieldValues, providedDynamicFieldIds, providedFieldIds, shouldPrompt) {
|
|
@@ -1913,7 +2019,7 @@ async function resolveParams(fields, dynamicFields, variants, positionalValues,
|
|
|
1913
2019
|
? parseDynamicValues(dynamicFields, rawArgv, casing)
|
|
1914
2020
|
: {
|
|
1915
2021
|
providedFieldIds: new Set(),
|
|
1916
|
-
values: new Map()
|
|
2022
|
+
values: new Map()
|
|
1917
2023
|
};
|
|
1918
2024
|
for (const field of dynamicFields) {
|
|
1919
2025
|
let value = dynamicResults.values.get(field.id);
|
|
@@ -1941,7 +2047,7 @@ async function executeCommand(state, services, requirementOptions, runtimeOption
|
|
|
1941
2047
|
logger,
|
|
1942
2048
|
renderTable,
|
|
1943
2049
|
getTheme,
|
|
1944
|
-
note
|
|
2050
|
+
note
|
|
1945
2051
|
};
|
|
1946
2052
|
const optionValues = state.actionCommand.optsWithGlobals();
|
|
1947
2053
|
const resolvedFlags = optionValues;
|
|
@@ -1956,16 +2062,19 @@ async function executeCommand(state, services, requirementOptions, runtimeOption
|
|
|
1956
2062
|
env: runtime.env,
|
|
1957
2063
|
progress(message) {
|
|
1958
2064
|
logger.info(message);
|
|
1959
|
-
}
|
|
2065
|
+
}
|
|
1960
2066
|
};
|
|
1961
2067
|
await withOutputFormat(output, async () => {
|
|
1962
2068
|
await assertCommandRequirements(state.command, preflightContext, runtime.requirementOptions);
|
|
1963
2069
|
const params = await resolveParams(state.fields, state.dynamicFields, state.variants, state.positionalValues, optionValues, state.rawArgv, state.casing, state.presetsEnabled ? resolvedFlags.preset : undefined, shouldPrompt);
|
|
1964
2070
|
const context = {
|
|
1965
2071
|
...preflightContext,
|
|
1966
|
-
params
|
|
2072
|
+
params
|
|
1967
2073
|
};
|
|
1968
|
-
if (state.command.confirm &&
|
|
2074
|
+
if (state.command.confirm &&
|
|
2075
|
+
!state.command.humanInLoop &&
|
|
2076
|
+
!resolvedFlags.yes &&
|
|
2077
|
+
process.stdin.isTTY) {
|
|
1969
2078
|
for (const field of state.fields) {
|
|
1970
2079
|
const value = field.path.reduce((current, segment) => current && typeof current === "object"
|
|
1971
2080
|
? current[segment]
|
|
@@ -1976,7 +2085,7 @@ async function executeCommand(state, services, requirementOptions, runtimeOption
|
|
|
1976
2085
|
}
|
|
1977
2086
|
const proceed = await confirm({
|
|
1978
2087
|
message: "Proceed?",
|
|
1979
|
-
initialValue: true
|
|
2088
|
+
initialValue: true
|
|
1980
2089
|
});
|
|
1981
2090
|
if (isCancel(proceed)) {
|
|
1982
2091
|
cancel("Operation cancelled.");
|
|
@@ -1994,7 +2103,10 @@ async function executeCommand(state, services, requirementOptions, runtimeOption
|
|
|
1994
2103
|
renderHumanInLoopPending(result);
|
|
1995
2104
|
return;
|
|
1996
2105
|
}
|
|
1997
|
-
renderResult(state.command, result, output, primitives);
|
|
2106
|
+
const renderStatus = renderResult(state.command, result, output, primitives);
|
|
2107
|
+
if (renderStatus.mcpError) {
|
|
2108
|
+
process.exitCode = 1;
|
|
2109
|
+
}
|
|
1998
2110
|
});
|
|
1999
2111
|
}
|
|
2000
2112
|
function handleRunError(error, verbose) {
|
|
@@ -2028,10 +2140,10 @@ export async function runCLI(roots, options = {}) {
|
|
|
2028
2140
|
const servicesWithBuiltIns = {
|
|
2029
2141
|
...services,
|
|
2030
2142
|
runtimeOptions,
|
|
2031
|
-
root
|
|
2143
|
+
root
|
|
2032
2144
|
};
|
|
2033
2145
|
const requirementOptions = {
|
|
2034
|
-
apiVersion: options.apiVersion
|
|
2146
|
+
apiVersion: options.apiVersion
|
|
2035
2147
|
};
|
|
2036
2148
|
validateServices(services);
|
|
2037
2149
|
if (hasHelpFlag(process.argv)) {
|
|
@@ -2072,6 +2184,8 @@ export async function runCLI(roots, options = {}) {
|
|
|
2072
2184
|
renderApprovalDeclined(error);
|
|
2073
2185
|
return;
|
|
2074
2186
|
}
|
|
2075
|
-
handleRunError(error, lastActionCommand
|
|
2187
|
+
handleRunError(error, lastActionCommand
|
|
2188
|
+
? Boolean(getResolvedFlags(lastActionCommand).verbose)
|
|
2189
|
+
: process.argv.includes("--verbose"));
|
|
2076
2190
|
}
|
|
2077
2191
|
}
|