toolcraft 0.0.19 → 0.0.20
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
CHANGED
|
@@ -942,28 +942,16 @@ function formatCommandRows(group, scope, casing, globalLongOptionFlags) {
|
|
|
942
942
|
description: child.description ?? ""
|
|
943
943
|
}));
|
|
944
944
|
}
|
|
945
|
-
function
|
|
946
|
-
const
|
|
945
|
+
function formatGlobalOptionsLine(ctx) {
|
|
946
|
+
const flags = [];
|
|
947
947
|
if (ctx.presetsEnabled) {
|
|
948
|
-
|
|
949
|
-
flags: "--preset <path>",
|
|
950
|
-
description: "Load parameter defaults from a JSON file"
|
|
951
|
-
});
|
|
948
|
+
flags.push("--preset <path>");
|
|
952
949
|
}
|
|
953
|
-
|
|
954
|
-
flags: "--yes",
|
|
955
|
-
description: "Accept defaults, skip prompts"
|
|
956
|
-
}, {
|
|
957
|
-
flags: "--output <format>",
|
|
958
|
-
description: "Output format: rich, md, json."
|
|
959
|
-
});
|
|
950
|
+
flags.push("--yes", "--output <format>");
|
|
960
951
|
if (ctx.showVersion) {
|
|
961
|
-
|
|
962
|
-
flags: "--version",
|
|
963
|
-
description: "Show version"
|
|
964
|
-
});
|
|
952
|
+
flags.push("--version");
|
|
965
953
|
}
|
|
966
|
-
return
|
|
954
|
+
return `${text.section("Options:")} ${flags.join(" ")}`;
|
|
967
955
|
}
|
|
968
956
|
function collectSchemaGlobalFieldRows(group, scope, casing, globalLongOptionFlags) {
|
|
969
957
|
const seen = new Map();
|
|
@@ -1023,11 +1011,14 @@ function renderGroupHelp(group, breadcrumb, scope, casing, globalOptions, rootUs
|
|
|
1023
1011
|
sections.push(`${text.sectionHeader("Commands")}\n${formatHelpCommandList(commandRows)}`);
|
|
1024
1012
|
}
|
|
1025
1013
|
if (isRoot) {
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1014
|
+
const schemaGlobalRows = collectSchemaGlobalFieldRows(group, scope, casing, globalLongOptionFlags);
|
|
1015
|
+
const builtInLine = formatGlobalOptionsLine(globalOptions);
|
|
1016
|
+
if (schemaGlobalRows.length > 0) {
|
|
1017
|
+
sections.push(`${text.sectionHeader("Options")}\n${formatHelpOptionList(schemaGlobalRows)}\n${builtInLine}`);
|
|
1018
|
+
}
|
|
1019
|
+
else {
|
|
1020
|
+
sections.push(builtInLine);
|
|
1021
|
+
}
|
|
1031
1022
|
}
|
|
1032
1023
|
return renderHelpDocument({
|
|
1033
1024
|
breadcrumb,
|
|
@@ -1177,12 +1168,12 @@ function createNodeCommand(node, casing, globalLongOptionFlags, execute, presets
|
|
|
1177
1168
|
return group;
|
|
1178
1169
|
}
|
|
1179
1170
|
function addGlobalOptions(command, presetsEnabled) {
|
|
1171
|
+
const options = [];
|
|
1180
1172
|
if (presetsEnabled) {
|
|
1181
|
-
|
|
1173
|
+
options.push(new Option("--preset <path>", "Load parameter defaults from a JSON file."));
|
|
1182
1174
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
.option("--output <format>", "Output format.", (value) => {
|
|
1175
|
+
options.push(new Option("--yes", "Accept defaults and skip prompts."));
|
|
1176
|
+
options.push(new Option("--output <format>", "Output format.").argParser((value) => {
|
|
1186
1177
|
if (value === "rich" || value === "md" || value === "json") {
|
|
1187
1178
|
return value;
|
|
1188
1179
|
}
|
|
@@ -1193,11 +1184,15 @@ function addGlobalOptions(command, presetsEnabled) {
|
|
|
1193
1184
|
candidates: ["rich", "markdown", "json"],
|
|
1194
1185
|
threshold: 3
|
|
1195
1186
|
}));
|
|
1196
|
-
})
|
|
1197
|
-
|
|
1187
|
+
}));
|
|
1188
|
+
options.push(new Option("--debug [mode]", "Print stack traces for unexpected errors.")
|
|
1198
1189
|
.preset("trim")
|
|
1199
|
-
.argParser(parseDebugStackMode))
|
|
1200
|
-
|
|
1190
|
+
.argParser(parseDebugStackMode));
|
|
1191
|
+
options.push(new Option("--verbose", "Print detailed runtime diagnostics."));
|
|
1192
|
+
for (const option of options) {
|
|
1193
|
+
option.hideHelp(true);
|
|
1194
|
+
command.addOption(option);
|
|
1195
|
+
}
|
|
1201
1196
|
}
|
|
1202
1197
|
function parseDebugStackMode(value) {
|
|
1203
1198
|
if (value === true || value === "trim") {
|
|
@@ -1235,6 +1230,9 @@ function formatResolvedValue(value) {
|
|
|
1235
1230
|
}
|
|
1236
1231
|
return JSON.stringify(value);
|
|
1237
1232
|
}
|
|
1233
|
+
function fieldPromptLabel(field) {
|
|
1234
|
+
return field.positionalIndex === undefined ? field.optionFlag : `<${field.displayPath}>`;
|
|
1235
|
+
}
|
|
1238
1236
|
async function promptForField(field) {
|
|
1239
1237
|
const schema = field.schema;
|
|
1240
1238
|
if (schema.kind === "enum") {
|
|
@@ -1245,7 +1243,7 @@ async function promptForField(field) {
|
|
|
1245
1243
|
value
|
|
1246
1244
|
}));
|
|
1247
1245
|
const selected = await select({
|
|
1248
|
-
message: field.description ?? field
|
|
1246
|
+
message: field.description ?? fieldPromptLabel(field),
|
|
1249
1247
|
options,
|
|
1250
1248
|
initialValue: field.hasDefault ? field.defaultValue : undefined
|
|
1251
1249
|
});
|
|
@@ -1257,7 +1255,7 @@ async function promptForField(field) {
|
|
|
1257
1255
|
}
|
|
1258
1256
|
if (field.schema.kind === "boolean") {
|
|
1259
1257
|
const selected = await confirm({
|
|
1260
|
-
message: field
|
|
1258
|
+
message: fieldPromptLabel(field),
|
|
1261
1259
|
initialValue: field.hasDefault ? Boolean(field.defaultValue) : undefined
|
|
1262
1260
|
});
|
|
1263
1261
|
if (isCancel(selected)) {
|
|
@@ -1267,7 +1265,7 @@ async function promptForField(field) {
|
|
|
1267
1265
|
return selected;
|
|
1268
1266
|
}
|
|
1269
1267
|
const entered = await promptText({
|
|
1270
|
-
message: field
|
|
1268
|
+
message: fieldPromptLabel(field),
|
|
1271
1269
|
initialValue: field.hasDefault && field.defaultValue !== undefined
|
|
1272
1270
|
? formatResolvedValue(field.defaultValue)
|
|
1273
1271
|
: undefined
|
|
@@ -58,7 +58,7 @@ export type SpinnerOptions = {
|
|
|
58
58
|
message: (message?: string) => void;
|
|
59
59
|
};
|
|
60
60
|
export interface WithSpinnerOptions<T> {
|
|
61
|
-
message: string;
|
|
61
|
+
message: string | (() => string);
|
|
62
62
|
fn: () => Promise<T>;
|
|
63
63
|
stopMessage?: (result: T) => string;
|
|
64
64
|
subtext?: (result: T) => string | undefined;
|
|
@@ -80,6 +80,7 @@ function formatElapsed(ms) {
|
|
|
80
80
|
}
|
|
81
81
|
export async function withSpinner(options) {
|
|
82
82
|
const { message, fn, stopMessage, subtext } = options;
|
|
83
|
+
const readMessage = () => (typeof message === "function" ? message() : message);
|
|
83
84
|
if (resolveOutputFormat() === "json") {
|
|
84
85
|
const result = await fn();
|
|
85
86
|
const sub = subtext ? subtext(result) : undefined;
|
|
@@ -106,9 +107,9 @@ export async function withSpinner(options) {
|
|
|
106
107
|
}
|
|
107
108
|
const s = spinner();
|
|
108
109
|
const start = Date.now();
|
|
109
|
-
s.start(
|
|
110
|
+
s.start(readMessage());
|
|
110
111
|
const timer = setInterval(() => {
|
|
111
|
-
s.message(`${
|
|
112
|
+
s.message(`${readMessage()} [${formatElapsed(Date.now() - start)}]`);
|
|
112
113
|
}, 1000);
|
|
113
114
|
try {
|
|
114
115
|
const result = await fn();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"jsonc-parser": "^3.3.1",
|
|
51
51
|
"smol-toml": "^1.3.0",
|
|
52
52
|
"tiny-stdio-mcp-server": "^0.1.0",
|
|
53
|
-
"toolcraft-schema": "^0.0.
|
|
53
|
+
"toolcraft-schema": "^0.0.20",
|
|
54
54
|
"yaml": "^2.8.2"
|
|
55
55
|
},
|
|
56
56
|
"files": [
|