Skip to content

Commit 558922c

Browse files
authored
fix(cli-repl): indent multi-line help descriptions properly MONGOSH-717 (#818)
1 parent fb6210f commit 558922c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/cli-repl/src/format-output.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,28 @@ for (const colors of [ false, true ]) {
287287
expect(output).to.not.contain('https://docs.mongodb.com');
288288
expect(output).to.contain('list available databases');
289289
});
290+
291+
it('handles multi-line descriptions', () => {
292+
const output = stripAnsiColors(format({
293+
value: {
294+
help: 'Shell API',
295+
attr: [{
296+
name: 'show dbs',
297+
description: 'list available\ndatabases\n\nwith line breaks'
298+
}]
299+
},
300+
type: 'Help'
301+
}));
302+
303+
expect(output).to.equal(`
304+
Shell API:
305+
306+
show dbs list available
307+
databases
308+
309+
with line breaks
310+
`);
311+
});
290312
});
291313

292314
context('when the result is ExplainOutput or ExplainableCursor', () => {

packages/cli-repl/src/format-output.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ function formatHelp(value: HelpProperties, options: FormatOptions): string {
221221
if (method.name && method.description) {
222222
formatted = ` ${method.name}`;
223223
const extraSpaces = argLen - formatted.length;
224-
formatted += `${' '.repeat(extraSpaces)}${method.description}`;
224+
const descriptionLines = method.description.split('\n');
225+
descriptionLines[0] = ' '.repeat(extraSpaces) + descriptionLines[0];
226+
for (let i = 1; i < descriptionLines.length; i++) {
227+
if (descriptionLines[i].trim() !== '') {
228+
descriptionLines[i] = ' '.repeat(argLen) + descriptionLines[i];
229+
}
230+
}
231+
formatted += descriptionLines.join('\n');
225232
}
226233
if (!method.name && method.description) {
227234
formatted = ` ${method.description}`;

0 commit comments

Comments
 (0)