Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/cli-repl/src/format-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,28 @@ for (const colors of [ false, true ]) {
expect(output).to.not.contain('https://docs.mongodb.com');
expect(output).to.contain('list available databases');
});

it('handles multi-line descriptions', () => {
const output = stripAnsiColors(format({
value: {
help: 'Shell API',
attr: [{
name: 'show dbs',
description: 'list available\ndatabases\n\nwith line breaks'
}]
},
type: 'Help'
}));

expect(output).to.equal(`
Shell API:

show dbs list available
databases

with line breaks
`);
});
});

context('when the result is ExplainOutput or ExplainableCursor', () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/cli-repl/src/format-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ function formatHelp(value: HelpProperties, options: FormatOptions): string {
if (method.name && method.description) {
formatted = ` ${method.name}`;
const extraSpaces = argLen - formatted.length;
formatted += `${' '.repeat(extraSpaces)}${method.description}`;
const descriptionLines = method.description.split('\n');
descriptionLines[0] = ' '.repeat(extraSpaces) + descriptionLines[0];
for (let i = 1; i < descriptionLines.length; i++) {
if (descriptionLines[i].trim() !== '') {
descriptionLines[i] = ' '.repeat(argLen) + descriptionLines[i];
}
}
formatted += descriptionLines.join('\n');
}
if (!method.name && method.description) {
formatted = ` ${method.description}`;
Expand Down