Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to specify minColumnWidth for Help.wrap #1430

Merged
merged 2 commits into from
Jan 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -316,17 +316,17 @@ class Help {
* @param {string} str
* @param {number} width
* @param {number} indent
* @param {number} [minColumnWidth=40]
* @return {string}
*
*/

wrap(str, width, indent) {
wrap(str, width, indent, minColumnWidth = 40) {
// Detect manually wrapped and indented strings by searching for line breaks
// followed by multiple spaces/tabs.
if (str.match(/[\n]\s+/)) return str;
// Do not wrap if not enough room for a wrapped column of text (as could end up with a word per line).
const columnWidth = width - indent;
const minColumnWidth = 40;
if (columnWidth < minColumnWidth) return str;

const leadingStr = str.substr(0, indent);
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Expand Up @@ -121,7 +121,7 @@ declare namespace commander {
* Wrap the given string to width characters per line, with lines after the first indented.
* Do not wrap if insufficient room for wrapping, or string is manually formatted.
*/
wrap(str: string, width: number, indent: number): string;
wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;

/** Generate the built-in help text. */
formatHelp(cmd: Command, helper: Help): string;
Expand Down