diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-01-16 20:13:49 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-01-16 20:13:49 -0400 |
commit | f6c5df932dfba1567ef8b521796ecaf73317638d (patch) | |
tree | 8063956b24a6d8d8e6df61598b361fe143853d4b | |
parent | 8fa238e49bf4db2ddd72de4960bbaec7f4a72824 (diff) |
padding lines between long option help
-rwxr-xr-x | src/upd8.js | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/upd8.js b/src/upd8.js index 5668542c..42f0df46 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -252,6 +252,8 @@ async function main() { console.log(`(No options available)`) } + let justInsertedPaddingLine = false; + for (const {name, descriptor} of sortedOptions) { if (descriptor.alias) { continue; @@ -261,6 +263,16 @@ async function main() { .filter(([_name, {alias}]) => alias === name) .map(([name]) => name); + let wrappedHelp, wrappedHelpLines = 0; + if (descriptor.help) { + wrappedHelp = indentWrap(4, descriptor.help); + wrappedHelpLines = wrappedHelp.split('\n').length; + } + + if (wrappedHelpLines > 1 && !justInsertedPaddingLine) { + console.log(''); + } + console.log(color.bright(` --` + name) + (aliases.length ? ` (or: ${aliases.map(alias => color.bright(`--` + alias)).join(', ')})` @@ -269,12 +281,21 @@ async function main() { ? '' : color.dim(' (no help provided)'))); - if (descriptor.help) { - console.log(indentWrap(4, descriptor.help)); + if (wrappedHelp) { + console.log(wrappedHelp); + } + + if (wrappedHelpLines > 1) { + console.log(''); + justInsertedPaddingLine = true; + } else { + justInsertedPaddingLine = false; } } - console.log(``); + if (!justInsertedPaddingLine) { + console.log(``); + } }; console.log( |