Skip to content

Commit a75e555

Browse files
authored
Improve formatting for cli examples (#803)
1 parent 81f1ea6 commit a75e555

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

docs/cli/openapi-merge.partial.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ zuplo openapi merge --source https://example.com/path/to/openapi.json
2323
To rename the destination file, use the `--destination` option.
2424

2525
```bash
26-
zuplo openapi merge --source https://example.com/path/to/openapi.json --destination new-name
26+
zuplo openapi merge \
27+
--source https://example.com/path/to/openapi.json \
28+
--destination new-name
2729
```

scripts/generate-cli-docs.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,66 @@ function formatJsxProp(key: string, value: unknown): string {
106106
return `${key}={${JSON.stringify(value, null, 2)}}`;
107107
}
108108

109+
// Helper to wrap long CLI commands for better readability
110+
function wrapCliCommand(command: string, maxLength = 80): string {
111+
// If command is short enough, return as-is
112+
if (command.length <= maxLength) {
113+
return command;
114+
}
115+
116+
// Split the command into base command and arguments
117+
const parts = command.split(/\s+/);
118+
if (parts.length <= 2) {
119+
// Very simple command, no wrapping needed
120+
return command;
121+
}
122+
123+
// Find the base command (everything before the first --)
124+
let baseCommandEnd = 0;
125+
for (let i = 0; i < parts.length; i++) {
126+
if (parts[i].startsWith("--")) {
127+
baseCommandEnd = i;
128+
break;
129+
}
130+
}
131+
132+
// If no -- arguments found, return as-is
133+
if (baseCommandEnd === 0) {
134+
return command;
135+
}
136+
137+
const baseCommand = parts.slice(0, baseCommandEnd).join(" ");
138+
const lines: string[] = [baseCommand];
139+
let currentLine = "";
140+
141+
// Process arguments
142+
for (let i = baseCommandEnd; i < parts.length; i++) {
143+
const part = parts[i];
144+
145+
if (part.startsWith("--")) {
146+
// This is a flag, potentially start a new line
147+
if (currentLine) {
148+
lines.push(currentLine);
149+
currentLine = "";
150+
}
151+
currentLine = ` ${part}`;
152+
} else {
153+
// This is a value or continuation of the previous token
154+
currentLine += ` ${part}`;
155+
}
156+
}
157+
158+
// Add the last line
159+
if (currentLine) {
160+
lines.push(currentLine);
161+
}
162+
163+
// Join with backslashes (except the last line)
164+
return lines
165+
.map((line, i) => (i < lines.length - 1 ? `${line} \\` : line))
166+
.join("\n");
167+
}
168+
109169
// Read all partial files
110170
const partialFiles = await glob("docs/cli/*.partial.mdx", { cwd: projectDir });
111171
const partialContent: Record<string, string> = {};
@@ -197,7 +257,12 @@ async function createCommandPage(
197257
}
198258

199259
if (command.examples && command.examples.length > 0) {
200-
props.push(formatJsxProp("examples", command.examples));
260+
// Wrap long commands for better readability
261+
const wrappedExamples = command.examples.map(([cmd, desc]) => [
262+
wrapCliCommand(cmd),
263+
desc,
264+
]);
265+
props.push(formatJsxProp("examples", wrappedExamples));
201266
}
202267

203268
if (command.usage) {

0 commit comments

Comments
 (0)