toolcraft-openapi 0.0.129 → 0.0.131
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/composition.json +2 -2
- package/dist/generate.d.ts +5 -0
- package/dist/generate.js +20 -2
- package/node_modules/toolcraft-design/dist/components/help-formatter-plain.js +61 -25
- package/node_modules/toolcraft-design/dist/components/help-formatter.d.ts +17 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter.js +128 -29
- package/node_modules/toolcraft-design/dist/components/index.d.ts +2 -2
- package/node_modules/toolcraft-design/dist/components/index.js +1 -1
- package/node_modules/toolcraft-design/dist/help-formatter.d.ts +2 -2
- package/node_modules/toolcraft-design/dist/help-formatter.js +1 -1
- package/node_modules/toolcraft-design/dist/index.d.ts +2 -2
- package/node_modules/toolcraft-design/dist/index.js +1 -1
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +3 -3
package/dist/composition.json
CHANGED
package/dist/generate.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ type OpenApiScalarType = "string" | "number" | "integer" | "boolean";
|
|
|
7
7
|
type OpenApiSchemaType = OpenApiScalarType | "object" | "array";
|
|
8
8
|
type OpenApiJsonSchemaType = OpenApiSchemaType | "null";
|
|
9
9
|
export type GeneratedRequestLocation = Exclude<GeneratedParam["location"], "transport">;
|
|
10
|
+
export interface OpenApiTagObject {
|
|
11
|
+
name: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
10
14
|
export interface OpenApiDocument {
|
|
11
15
|
openapi?: string;
|
|
12
16
|
info?: {
|
|
@@ -15,6 +19,7 @@ export interface OpenApiDocument {
|
|
|
15
19
|
};
|
|
16
20
|
servers?: OpenApiServerObject[];
|
|
17
21
|
security?: OpenApiSecurityRequirementObject[];
|
|
22
|
+
tags?: OpenApiTagObject[];
|
|
18
23
|
paths?: Record<string, OpenApiPathItemObject | undefined>;
|
|
19
24
|
components?: {
|
|
20
25
|
securitySchemes?: Record<string, unknown>;
|
package/dist/generate.js
CHANGED
|
@@ -113,7 +113,7 @@ export function generate(document, options) {
|
|
|
113
113
|
path: command.filePath,
|
|
114
114
|
contents: createCommandFile(command)
|
|
115
115
|
})),
|
|
116
|
-
createIndexFile(commands),
|
|
116
|
+
createIndexFile(commands, normalizedDocument),
|
|
117
117
|
createClientFile(),
|
|
118
118
|
createCliFile({ brand, label }),
|
|
119
119
|
createMcpFile()
|
|
@@ -1844,8 +1844,22 @@ function resolveQueryObjectSerialization(parameter, operationId) {
|
|
|
1844
1844
|
}
|
|
1845
1845
|
throw new UserError(`Operation ${JSON.stringify(operationId)} uses unsupported query-object serialization for parameter ${JSON.stringify(parameter.name)}. Supported in v1: deepObject with explode true.`);
|
|
1846
1846
|
}
|
|
1847
|
-
function
|
|
1847
|
+
function collectTagDescriptions(document) {
|
|
1848
|
+
const descriptions = new Map();
|
|
1849
|
+
for (const tag of document.tags ?? []) {
|
|
1850
|
+
if (typeof tag.name !== "string" || tag.name.length === 0) {
|
|
1851
|
+
continue;
|
|
1852
|
+
}
|
|
1853
|
+
if (typeof tag.description !== "string" || tag.description.trim().length === 0) {
|
|
1854
|
+
continue;
|
|
1855
|
+
}
|
|
1856
|
+
descriptions.set(normalizeNoun(tag.name), tag.description.trim());
|
|
1857
|
+
}
|
|
1858
|
+
return descriptions;
|
|
1859
|
+
}
|
|
1860
|
+
function createIndexFile(commands, document) {
|
|
1848
1861
|
const groups = groupByNoun(commands);
|
|
1862
|
+
const tagDescriptions = collectTagDescriptions(document);
|
|
1849
1863
|
if (groups.length === 0) {
|
|
1850
1864
|
return {
|
|
1851
1865
|
path: "index.ts",
|
|
@@ -1863,8 +1877,12 @@ function createIndexFile(commands) {
|
|
|
1863
1877
|
lines.push("");
|
|
1864
1878
|
}
|
|
1865
1879
|
for (const { noun, commands: nounCommands } of groups) {
|
|
1880
|
+
const description = tagDescriptions.get(noun);
|
|
1866
1881
|
lines.push(`export const ${toCamelCase(noun)} = defineGroup({`);
|
|
1867
1882
|
lines.push(` name: ${JSON.stringify(noun)},`);
|
|
1883
|
+
if (description !== undefined) {
|
|
1884
|
+
lines.push(` description: ${JSON.stringify(description)},`);
|
|
1885
|
+
}
|
|
1868
1886
|
lines.push(` children: [${nounCommands.map((command) => command.exportName).join(", ")}],`);
|
|
1869
1887
|
lines.push("});");
|
|
1870
1888
|
lines.push("");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { joinHelpTokens } from "./help-formatter.js";
|
|
1
2
|
export function stripAnsi(value) {
|
|
2
3
|
let output = "";
|
|
3
4
|
for (let index = 0; index < value.length; index += 1) {
|
|
@@ -54,26 +55,49 @@ function splitWords(value) {
|
|
|
54
55
|
}
|
|
55
56
|
return words;
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
58
|
+
function leadingWhitespace(value) {
|
|
59
|
+
let index = 0;
|
|
60
|
+
while (index < value.length && isWhitespace(value[index])) {
|
|
61
|
+
index += 1;
|
|
62
|
+
}
|
|
63
|
+
return { prefix: value.slice(0, index), rest: value.slice(index) };
|
|
64
|
+
}
|
|
65
|
+
function takePrefix(value, width) {
|
|
66
|
+
return { prefix: value.slice(0, width), rest: value.slice(width) };
|
|
67
|
+
}
|
|
68
|
+
function wrapWords(value, width, continuationWidth = width) {
|
|
69
|
+
// Preserve leading whitespace only on the first wrapped line so hang-indented
|
|
70
|
+
// left cells (command depth prefixes) do not re-indent every continuation.
|
|
71
|
+
const { prefix, rest } = leadingWhitespace(value);
|
|
72
|
+
const firstContentWidth = Math.max(1, width - prefix.length);
|
|
73
|
+
const words = splitWords(rest);
|
|
59
74
|
if (words.length === 0) {
|
|
60
|
-
return [
|
|
75
|
+
return [prefix];
|
|
61
76
|
}
|
|
62
77
|
const lines = [];
|
|
63
78
|
let line = "";
|
|
79
|
+
let isFirstLine = true;
|
|
64
80
|
for (const word of words) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (line.length + 1 + word.length <= width) {
|
|
81
|
+
const limit = isFirstLine ? firstContentWidth : continuationWidth;
|
|
82
|
+
if (line && line.length + 1 + word.length <= limit) {
|
|
70
83
|
line += ` ${word}`;
|
|
71
84
|
continue;
|
|
72
85
|
}
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
if (line) {
|
|
87
|
+
lines.push(isFirstLine ? `${prefix}${line}` : line);
|
|
88
|
+
isFirstLine = false;
|
|
89
|
+
line = "";
|
|
90
|
+
}
|
|
91
|
+
let remaining = word;
|
|
92
|
+
while (remaining.length > (isFirstLine ? firstContentWidth : continuationWidth)) {
|
|
93
|
+
const chunk = takePrefix(remaining, isFirstLine ? firstContentWidth : continuationWidth);
|
|
94
|
+
lines.push(isFirstLine ? `${prefix}${chunk.prefix}` : chunk.prefix);
|
|
95
|
+
isFirstLine = false;
|
|
96
|
+
remaining = chunk.rest;
|
|
97
|
+
}
|
|
98
|
+
line = remaining;
|
|
75
99
|
}
|
|
76
|
-
lines.push(line);
|
|
100
|
+
lines.push(isFirstLine ? `${prefix}${line}` : line);
|
|
77
101
|
return lines;
|
|
78
102
|
}
|
|
79
103
|
export function formatColumns(opts) {
|
|
@@ -91,33 +115,43 @@ export function formatColumns(opts) {
|
|
|
91
115
|
const indent = opts.indent ?? 2;
|
|
92
116
|
const maxLeftContentWidth = Math.max(...rows.map((row) => row.left.length));
|
|
93
117
|
const leftWidth = clamp(maxLeftContentWidth + gap, minLeftWidth, maxLeftWidth);
|
|
94
|
-
const rightWidth = Math.max(
|
|
118
|
+
const rightWidth = Math.max(1, totalWidth - leftWidth - indent);
|
|
119
|
+
const leftWrapWidth = Math.max(1, totalWidth - indent);
|
|
95
120
|
const firstIndent = " ".repeat(indent);
|
|
96
121
|
const continuationIndent = " ".repeat(indent + leftWidth);
|
|
97
122
|
return rows
|
|
98
123
|
.flatMap((row) => {
|
|
124
|
+
let leftLeadingWidth = 0;
|
|
125
|
+
while (leftLeadingWidth < row.left.length && isWhitespace(row.left[leftLeadingWidth])) {
|
|
126
|
+
leftLeadingWidth += 1;
|
|
127
|
+
}
|
|
128
|
+
// Continuations hang under the left cell start (including depth prefix) by +2.
|
|
129
|
+
const leftHangIndent = " ".repeat(indent + leftLeadingWidth + 2);
|
|
130
|
+
const leftLines = wrapWords(row.left, leftWrapWidth, Math.max(1, totalWidth - leftHangIndent.length));
|
|
99
131
|
if (row.right.length === 0) {
|
|
100
|
-
return
|
|
132
|
+
return leftLines.map((line, index) => index === 0 ? `${firstIndent}${line}` : `${leftHangIndent}${line}`);
|
|
101
133
|
}
|
|
102
134
|
const rightLines = wrapWords(row.right, rightWidth);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
135
|
+
const leftFitsInColumn = row.left.length < leftWidth;
|
|
136
|
+
if (leftFitsInColumn && leftLines.length === 1) {
|
|
137
|
+
const firstLine = `${firstIndent}${padEndVisible(leftLines[0] ?? "", leftWidth)}${rightLines[0]}`;
|
|
138
|
+
const continuationLines = rightLines
|
|
139
|
+
.slice(1)
|
|
140
|
+
.map((line) => `${continuationIndent}${line}`);
|
|
141
|
+
return [firstLine, ...continuationLines];
|
|
108
142
|
}
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
.map((line) => `${continuationIndent}${line}`);
|
|
113
|
-
return [firstLine, ...continuationLines];
|
|
143
|
+
const renderedLeft = leftLines.map((line, index) => index === 0 ? `${firstIndent}${line}` : `${leftHangIndent}${line}`);
|
|
144
|
+
const renderedRight = rightLines.map((line) => `${continuationIndent}${line}`);
|
|
145
|
+
return [...renderedLeft, ...renderedRight];
|
|
114
146
|
})
|
|
115
147
|
.join("\n");
|
|
116
148
|
}
|
|
117
149
|
export function formatCommandList(commands) {
|
|
118
150
|
return formatColumns({
|
|
119
151
|
rows: commands.map((cmd) => ({
|
|
120
|
-
left: cmd.
|
|
152
|
+
left: `${" ".repeat((cmd.depth ?? 0) * 2)}${cmd.nameTokens !== undefined && cmd.nameTokens.length > 0
|
|
153
|
+
? joinHelpTokens(cmd.nameTokens)
|
|
154
|
+
: cmd.name}`,
|
|
121
155
|
right: cmd.description
|
|
122
156
|
}))
|
|
123
157
|
});
|
|
@@ -125,7 +159,9 @@ export function formatCommandList(commands) {
|
|
|
125
159
|
export function formatOptionList(options) {
|
|
126
160
|
return formatColumns({
|
|
127
161
|
rows: options.map((opt) => ({
|
|
128
|
-
left: opt.
|
|
162
|
+
left: opt.flagTokens !== undefined && opt.flagTokens.length > 0
|
|
163
|
+
? joinHelpTokens(opt.flagTokens)
|
|
164
|
+
: opt.flags,
|
|
129
165
|
right: opt.description
|
|
130
166
|
}))
|
|
131
167
|
});
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
export type HelpTokenRole = "command" | "argument" | "option" | "literal" | "dim";
|
|
2
|
+
export interface HelpToken {
|
|
3
|
+
text: string;
|
|
4
|
+
role: HelpTokenRole;
|
|
5
|
+
}
|
|
1
6
|
export interface CommandInfo {
|
|
2
7
|
name: string;
|
|
8
|
+
/** Structured tokens for TTY/markdown styling. Plain `name` is used when absent. */
|
|
9
|
+
nameTokens?: HelpToken[];
|
|
3
10
|
description: string;
|
|
11
|
+
/** Nesting depth relative to the help target. Depth 0 is a direct child. */
|
|
12
|
+
depth?: number;
|
|
4
13
|
}
|
|
5
14
|
export interface OptionInfo {
|
|
6
15
|
flags: string;
|
|
16
|
+
/** Structured tokens for TTY/markdown styling. Plain `flags` is used when absent. */
|
|
17
|
+
flagTokens?: HelpToken[];
|
|
7
18
|
description: string;
|
|
8
19
|
}
|
|
9
20
|
export interface FormatColumnsOptions {
|
|
@@ -18,6 +29,9 @@ export interface FormatColumnsOptions {
|
|
|
18
29
|
indent?: number;
|
|
19
30
|
}
|
|
20
31
|
export declare function formatColumns(opts: FormatColumnsOptions): string;
|
|
32
|
+
export declare function styleHelpToken(token: HelpToken): string;
|
|
33
|
+
export declare function joinHelpTokens(tokens: HelpToken[]): string;
|
|
34
|
+
export declare function renderHelpTokens(tokens: HelpToken[]): string;
|
|
21
35
|
export declare function formatCommand(name: string, description: string): string;
|
|
22
36
|
export declare function formatUsage(command: string, args?: string): string;
|
|
23
37
|
export declare function formatOption(flags: string, description: string): string;
|
|
@@ -30,4 +44,7 @@ export declare const helpFormatter: {
|
|
|
30
44
|
readonly formatOption: typeof formatOption;
|
|
31
45
|
readonly formatCommandList: typeof formatCommandList;
|
|
32
46
|
readonly formatOptionList: typeof formatOptionList;
|
|
47
|
+
readonly styleHelpToken: typeof styleHelpToken;
|
|
48
|
+
readonly joinHelpTokens: typeof joinHelpTokens;
|
|
49
|
+
readonly renderHelpTokens: typeof renderHelpTokens;
|
|
33
50
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
2
|
+
import { typography } from "../tokens/typography.js";
|
|
1
3
|
import { text } from "./text.js";
|
|
2
4
|
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
3
5
|
function normalizeInline(value) {
|
|
@@ -103,26 +105,67 @@ function splitWords(value) {
|
|
|
103
105
|
}
|
|
104
106
|
return words;
|
|
105
107
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
+
function leadingWhitespaceWidth(value) {
|
|
109
|
+
let index = 0;
|
|
110
|
+
while (index < value.length && isWhitespace(value[index])) {
|
|
111
|
+
index += 1;
|
|
112
|
+
}
|
|
113
|
+
return { prefix: value.slice(0, index), rest: value.slice(index) };
|
|
114
|
+
}
|
|
115
|
+
function takeVisiblePrefix(value, width) {
|
|
116
|
+
let visible = 0;
|
|
117
|
+
let index = 0;
|
|
118
|
+
while (index < value.length) {
|
|
119
|
+
const controlEnd = readControlSequence(value, index);
|
|
120
|
+
if (controlEnd !== undefined) {
|
|
121
|
+
index = controlEnd;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const segment = graphemeSegmenter.segment(value.slice(index))[Symbol.iterator]().next().value;
|
|
125
|
+
const cluster = segment?.segment ?? value[index] ?? "";
|
|
126
|
+
const nextWidth = clusterWidth(cluster);
|
|
127
|
+
if (visible > 0 && visible + nextWidth > width) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
visible += nextWidth;
|
|
131
|
+
index += cluster.length || 1;
|
|
132
|
+
}
|
|
133
|
+
return { prefix: value.slice(0, index), rest: value.slice(index) };
|
|
134
|
+
}
|
|
135
|
+
function wrapWords(value, width, continuationWidth = width) {
|
|
136
|
+
// Preserve leading whitespace only on the first wrapped line so hang-indented
|
|
137
|
+
// left cells (command depth prefixes) do not re-indent every continuation.
|
|
138
|
+
const { prefix, rest } = leadingWhitespaceWidth(value);
|
|
139
|
+
const prefixWidth = visibleWidth(prefix);
|
|
140
|
+
const firstContentWidth = Math.max(1, width - prefixWidth);
|
|
141
|
+
const words = splitWords(rest);
|
|
108
142
|
if (words.length === 0) {
|
|
109
|
-
return [
|
|
143
|
+
return [prefix];
|
|
110
144
|
}
|
|
111
145
|
const lines = [];
|
|
112
146
|
let line = "";
|
|
147
|
+
let isFirstLine = true;
|
|
113
148
|
for (const word of words) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (visibleWidth(line) + 1 + visibleWidth(word) <= width) {
|
|
149
|
+
const limit = isFirstLine ? firstContentWidth : continuationWidth;
|
|
150
|
+
if (line && visibleWidth(line) + 1 + visibleWidth(word) <= limit) {
|
|
119
151
|
line += ` ${word}`;
|
|
120
152
|
continue;
|
|
121
153
|
}
|
|
122
|
-
|
|
123
|
-
|
|
154
|
+
if (line) {
|
|
155
|
+
lines.push(isFirstLine ? `${prefix}${line}` : line);
|
|
156
|
+
isFirstLine = false;
|
|
157
|
+
line = "";
|
|
158
|
+
}
|
|
159
|
+
let remaining = word;
|
|
160
|
+
while (visibleWidth(remaining) > (isFirstLine ? firstContentWidth : continuationWidth)) {
|
|
161
|
+
const chunk = takeVisiblePrefix(remaining, isFirstLine ? firstContentWidth : continuationWidth);
|
|
162
|
+
lines.push(isFirstLine ? `${prefix}${chunk.prefix}` : chunk.prefix);
|
|
163
|
+
isFirstLine = false;
|
|
164
|
+
remaining = chunk.rest;
|
|
165
|
+
}
|
|
166
|
+
line = remaining;
|
|
124
167
|
}
|
|
125
|
-
lines.push(line);
|
|
168
|
+
lines.push(isFirstLine ? `${prefix}${line}` : line);
|
|
126
169
|
return lines;
|
|
127
170
|
}
|
|
128
171
|
function validateLayoutValue(value, name) {
|
|
@@ -150,29 +193,74 @@ export function formatColumns(opts) {
|
|
|
150
193
|
validateLayoutValue(indent, "indent");
|
|
151
194
|
const maxLeftContentWidth = Math.max(...rows.map((row) => visibleWidth(row.left)));
|
|
152
195
|
const leftWidth = clamp(maxLeftContentWidth + gap, minLeftWidth, maxLeftWidth);
|
|
153
|
-
const rightWidth = Math.max(
|
|
196
|
+
const rightWidth = Math.max(1, totalWidth - leftWidth - indent);
|
|
197
|
+
const leftWrapWidth = Math.max(1, totalWidth - indent);
|
|
154
198
|
const firstIndent = " ".repeat(indent);
|
|
155
199
|
const continuationIndent = " ".repeat(indent + leftWidth);
|
|
156
200
|
return rows
|
|
157
201
|
.flatMap((row) => {
|
|
202
|
+
const leftLeading = leadingWhitespaceWidth(row.left).prefix;
|
|
203
|
+
// Continuations hang under the left cell start (including depth prefix) by +2.
|
|
204
|
+
const leftHangIndent = " ".repeat(indent + visibleWidth(leftLeading) + 2);
|
|
205
|
+
const leftLines = wrapWords(row.left, leftWrapWidth, Math.max(1, totalWidth - visibleWidth(leftHangIndent)));
|
|
158
206
|
if (row.right.length === 0) {
|
|
159
|
-
return
|
|
207
|
+
return leftLines.map((line, index) => index === 0 ? `${firstIndent}${line}` : `${leftHangIndent}${line}`);
|
|
160
208
|
}
|
|
161
209
|
const rightLines = wrapWords(row.right, rightWidth);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
210
|
+
const leftFitsInColumn = visibleWidth(row.left) < leftWidth;
|
|
211
|
+
if (leftFitsInColumn && leftLines.length === 1) {
|
|
212
|
+
const firstLine = `${firstIndent}${padEndVisible(leftLines[0] ?? "", leftWidth)}${rightLines[0]}`;
|
|
213
|
+
const continuationLines = rightLines
|
|
214
|
+
.slice(1)
|
|
215
|
+
.map((line) => `${continuationIndent}${line}`);
|
|
216
|
+
return [firstLine, ...continuationLines];
|
|
167
217
|
}
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
.map((line) => `${continuationIndent}${line}`);
|
|
172
|
-
return [firstLine, ...continuationLines];
|
|
218
|
+
const renderedLeft = leftLines.map((line, index) => index === 0 ? `${firstIndent}${line}` : `${leftHangIndent}${line}`);
|
|
219
|
+
const renderedRight = rightLines.map((line) => `${continuationIndent}${line}`);
|
|
220
|
+
return [...renderedLeft, ...renderedRight];
|
|
173
221
|
})
|
|
174
222
|
.join("\n");
|
|
175
223
|
}
|
|
224
|
+
export function styleHelpToken(token) {
|
|
225
|
+
switch (token.role) {
|
|
226
|
+
case "command":
|
|
227
|
+
return text.command(token.text);
|
|
228
|
+
case "argument":
|
|
229
|
+
return styleArgumentToken(token.text);
|
|
230
|
+
case "option":
|
|
231
|
+
return text.option(token.text);
|
|
232
|
+
case "dim":
|
|
233
|
+
return styleDim(token.text);
|
|
234
|
+
case "literal":
|
|
235
|
+
return token.text;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function styleArgumentToken(content) {
|
|
239
|
+
// Token text already includes angle brackets. text.argument re-wraps in markdown,
|
|
240
|
+
// so strip first there; terminal/json keep the full `<value>` form.
|
|
241
|
+
const format = resolveOutputFormat();
|
|
242
|
+
if (format === "markdown" && content.startsWith("<") && content.endsWith(">")) {
|
|
243
|
+
return text.argument(content.slice(1, -1));
|
|
244
|
+
}
|
|
245
|
+
if (format === "json") {
|
|
246
|
+
return content;
|
|
247
|
+
}
|
|
248
|
+
return text.argument(content);
|
|
249
|
+
}
|
|
250
|
+
function styleDim(content) {
|
|
251
|
+
// Structural brackets stay unstyled in markdown/json; italicizing them as muted is wrong.
|
|
252
|
+
const format = resolveOutputFormat();
|
|
253
|
+
if (format === "json" || format === "markdown") {
|
|
254
|
+
return content;
|
|
255
|
+
}
|
|
256
|
+
return typography.dim(content);
|
|
257
|
+
}
|
|
258
|
+
export function joinHelpTokens(tokens) {
|
|
259
|
+
return tokens.map((token) => token.text).join("");
|
|
260
|
+
}
|
|
261
|
+
export function renderHelpTokens(tokens) {
|
|
262
|
+
return tokens.map((token) => styleHelpToken(token)).join("");
|
|
263
|
+
}
|
|
176
264
|
export function formatCommand(name, description) {
|
|
177
265
|
return formatColumns({
|
|
178
266
|
rows: [{ left: text.command(name), right: description }]
|
|
@@ -189,16 +277,24 @@ export function formatOption(flags, description) {
|
|
|
189
277
|
}
|
|
190
278
|
export function formatCommandList(commands) {
|
|
191
279
|
return formatColumns({
|
|
192
|
-
rows: commands.map((cmd) =>
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
280
|
+
rows: commands.map((cmd) => {
|
|
281
|
+
const depthPrefix = " ".repeat((cmd.depth ?? 0) * 2);
|
|
282
|
+
const styledName = cmd.nameTokens !== undefined && cmd.nameTokens.length > 0
|
|
283
|
+
? renderHelpTokens(cmd.nameTokens)
|
|
284
|
+
: text.command(cmd.name);
|
|
285
|
+
return {
|
|
286
|
+
left: `${depthPrefix}${styledName}`,
|
|
287
|
+
right: cmd.description
|
|
288
|
+
};
|
|
289
|
+
})
|
|
196
290
|
});
|
|
197
291
|
}
|
|
198
292
|
export function formatOptionList(options) {
|
|
199
293
|
return formatColumns({
|
|
200
294
|
rows: options.map((opt) => ({
|
|
201
|
-
left:
|
|
295
|
+
left: opt.flagTokens !== undefined && opt.flagTokens.length > 0
|
|
296
|
+
? renderHelpTokens(opt.flagTokens)
|
|
297
|
+
: text.option(opt.flags),
|
|
202
298
|
right: opt.description
|
|
203
299
|
}))
|
|
204
300
|
});
|
|
@@ -209,5 +305,8 @@ export const helpFormatter = {
|
|
|
209
305
|
formatUsage,
|
|
210
306
|
formatOption,
|
|
211
307
|
formatCommandList,
|
|
212
|
-
formatOptionList
|
|
308
|
+
formatOptionList,
|
|
309
|
+
styleHelpToken,
|
|
310
|
+
joinHelpTokens,
|
|
311
|
+
renderHelpTokens
|
|
213
312
|
};
|
|
@@ -4,8 +4,8 @@ export type { Color } from "./color.js";
|
|
|
4
4
|
export { symbols } from "./symbols.js";
|
|
5
5
|
export { createLogger, logger } from "./logger.js";
|
|
6
6
|
export type { LoggerOutput } from "./logger.js";
|
|
7
|
-
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./help-formatter.js";
|
|
8
|
-
export type { CommandInfo, OptionInfo, FormatColumnsOptions } from "./help-formatter.js";
|
|
7
|
+
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList, styleHelpToken, joinHelpTokens, renderHelpTokens } from "./help-formatter.js";
|
|
8
|
+
export type { CommandInfo, OptionInfo, FormatColumnsOptions, HelpToken, HelpTokenRole } from "./help-formatter.js";
|
|
9
9
|
export { formatCommandNotFound } from "./command-errors.js";
|
|
10
10
|
export { formatCommandNotFoundPanel } from "./command-errors.js";
|
|
11
11
|
export { renderTable } from "./table.js";
|
|
@@ -2,7 +2,7 @@ export { text } from "./text.js";
|
|
|
2
2
|
export { color } from "./color.js";
|
|
3
3
|
export { symbols } from "./symbols.js";
|
|
4
4
|
export { createLogger, logger } from "./logger.js";
|
|
5
|
-
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./help-formatter.js";
|
|
5
|
+
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList, styleHelpToken, joinHelpTokens, renderHelpTokens } from "./help-formatter.js";
|
|
6
6
|
export { formatCommandNotFound } from "./command-errors.js";
|
|
7
7
|
export { formatCommandNotFoundPanel } from "./command-errors.js";
|
|
8
8
|
export { renderTable } from "./table.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { helpFormatter } from "./components/help-formatter.js";
|
|
2
|
-
export type { CommandInfo, FormatColumnsOptions, OptionInfo } from "./components/help-formatter.js";
|
|
1
|
+
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList, styleHelpToken, joinHelpTokens, renderHelpTokens } from "./components/help-formatter.js";
|
|
2
|
+
export type { CommandInfo, FormatColumnsOptions, OptionInfo, HelpToken, HelpTokenRole } from "./components/help-formatter.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { helpFormatter } from "./components/help-formatter.js";
|
|
1
|
+
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList, styleHelpToken, joinHelpTokens, renderHelpTokens } from "./components/help-formatter.js";
|
|
@@ -12,9 +12,9 @@ export type { Color } from "./components/color.js";
|
|
|
12
12
|
export { symbols } from "./components/symbols.js";
|
|
13
13
|
export { createLogger, logger } from "./components/logger.js";
|
|
14
14
|
export type { LoggerOutput } from "./components/logger.js";
|
|
15
|
-
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./components/help-formatter.js";
|
|
15
|
+
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList, styleHelpToken, joinHelpTokens, renderHelpTokens } from "./components/help-formatter.js";
|
|
16
16
|
export * as helpFormatterPlain from "./components/help-formatter-plain.js";
|
|
17
|
-
export type { CommandInfo, OptionInfo, FormatColumnsOptions } from "./components/help-formatter.js";
|
|
17
|
+
export type { CommandInfo, OptionInfo, FormatColumnsOptions, HelpToken, HelpTokenRole } from "./components/help-formatter.js";
|
|
18
18
|
export { formatCommandNotFound } from "./components/command-errors.js";
|
|
19
19
|
export { formatCommandNotFoundPanel } from "./components/command-errors.js";
|
|
20
20
|
export { renderTable } from "./components/table.js";
|
|
@@ -10,7 +10,7 @@ export { text } from "./components/text.js";
|
|
|
10
10
|
export { color } from "./components/color.js";
|
|
11
11
|
export { symbols } from "./components/symbols.js";
|
|
12
12
|
export { createLogger, logger } from "./components/logger.js";
|
|
13
|
-
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./components/help-formatter.js";
|
|
13
|
+
export { helpFormatter, formatColumns, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList, styleHelpToken, joinHelpTokens, renderHelpTokens } from "./components/help-formatter.js";
|
|
14
14
|
export * as helpFormatterPlain from "./components/help-formatter-plain.js";
|
|
15
15
|
export { formatCommandNotFound } from "./components/command-errors.js";
|
|
16
16
|
export { formatCommandNotFoundPanel } from "./components/command-errors.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft-openapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.131",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"toolcraft-openapi-generate": "dist/bin/generate.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"toolcraft": "0.0.
|
|
33
|
+
"toolcraft": "0.0.131",
|
|
34
34
|
"auth-store": "^0.0.1",
|
|
35
35
|
"fast-string-width": "^3.0.2",
|
|
36
36
|
"fast-wrap-ansi": "^0.2.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"directory": "packages/toolcraft-openapi"
|
|
47
47
|
},
|
|
48
48
|
"optionalDependencies": {
|
|
49
|
-
"toolcraft-schema": "0.0.
|
|
49
|
+
"toolcraft-schema": "0.0.131",
|
|
50
50
|
"toolcraft-design": "*",
|
|
51
51
|
"@poe-code/frontmatter": "*"
|
|
52
52
|
},
|