Skip to content
Myr

Code tidy from review suggestions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by John Gee · parent 725ebd1 · Browse files · 1 file+12 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−13 removed

  • other:+12 added−13 removed

1 file+12 added−13 removed

modified:index.js+12 added-13 removed
1153 unmodified lines
1154 var width = this.padWidth();11551156 var columns = process.stdout.columns || 80;1157 var descriptionWidth = columns - width - 4;1158 var minWidth = 40;11581159 // Append the help information1160 return this.options.map(function(option) {1161 const fullDesc = option.description +1162 ((!option.negate && option.defaultValue !== undefined) ? ' (default: ' + JSON.stringify(option.defaultValue) + ')' : '');1164 return pad(option.flags, width) + ' ' + optionalWrap(fullDesc, descriptionWidth, width + 2, minWidth);1165 }).concat([pad(this._helpFlags, width) + ' ' + optionalWrap(this._helpDescription, descriptionWidth, width + 2, minWidth)])1163 return pad(option.flags, width) + ' ' + optionalWrap(fullDesc, descriptionWidth, width + 2);1164 }).concat([pad(this._helpFlags, width) + ' ' + optionalWrap(this._helpDescription, descriptionWidth, width + 2)])1165 .join('\n');1166};11671168/**
10 unmodified lines
1179 var width = this.padWidth();11801181 var columns = process.stdout.columns || 80;1182 var descriptionWidth = columns - width - 4;1184 var minWidth = 40;11831184 return [1185 'Commands:',1186 commands.map(function(cmd) {1187 var desc = cmd[1] ? ' ' + cmd[1] : '';1190 return (desc ? pad(cmd[0], width) : cmd[0]) + optionalWrap(desc, descriptionWidth, width + 2, minWidth);1188 return (desc ? pad(cmd[0], width) : cmd[0]) + optionalWrap(desc, descriptionWidth, width + 2);1189 }).join('\n').replace(/^/gm, ' '),1190 ''1191 ].join('\n');1192};
157 unmodified lines
1350 */1351function wrap(str, width, indent) {1352 var regex = new RegExp('.{1,' + (width - 1) + '}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)', 'g');1353 var lines = str.match(regex) || [];1356 var result = lines.map(function(line, i) {1354 return lines.map(function(line, i) {1355 if (line.slice(-1) === '\n') {1356 line = line.slice(0, line.length - 1);1357 }1358 return ((i > 0 && indent) ? Array(indent + 1).join(' ') : '') + line;1359 }).join('\n');1362 return result;1360}13611362/**1363 * Optionally wrap the given str to a max width of width characters per line1367 * while indenting with indent spaces. Do not wrap the text when the minWidth1368 * is not hit.1364 * while indenting with indent spaces. Do not wrap if insufficient width or1365 * string is manually formatted.1366 *1367 * @param {String} str1368 * @param {Number} width1369 * @param {Number} indent1370 * @return {String}1371 * @api private1372 */1376function optionalWrap(str, width, indent, minWidth) {1377 // detected manually wrapped and indented strings by searching for line breaks1378 // followed by multiple spaces/tabs1373function optionalWrap(str, width, indent) {1374 // Detect manually wrapped and indented strings by searching for line breaks1375 // followed by multiple spaces/tabs.1376 if (str.match(/[\n]\s+/)) return str;1380 // check if minimum width is reached1377 // Do not wrap to narrow columns (or can end up with a word per line).1378 const minWidth = 40;1379 if (width < minWidth) return str;13801381 return wrap(str, width, indent);1382}13831384/**
92 unmodified lines