Skip to content

Commit fcc8988

Browse files
authored
ability to specify minColumnWidth for Help.wrap (#1430)
* ability to specify `minColumnWidth` for `Help.wrap` * Added missing param in TypeScript for Help.wrap
1 parent d934573 commit fcc8988

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ class Help {
316316
* @param {string} str
317317
* @param {number} width
318318
* @param {number} indent
319+
* @param {number} [minColumnWidth=40]
319320
* @return {string}
320321
*
321322
*/
322323

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

332332
const leadingStr = str.substr(0, indent);

typings/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ declare namespace commander {
121121
* Wrap the given string to width characters per line, with lines after the first indented.
122122
* Do not wrap if insufficient room for wrapping, or string is manually formatted.
123123
*/
124-
wrap(str: string, width: number, indent: number): string;
124+
wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;
125125

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

0 commit comments

Comments
 (0)