Open roryokane opened 4 years ago
Is there any way to achieve this? We need to add a usage caveat and a new line would be the ideal place to put it.
@Slapbox I could imagine people wanting both formats, what if we made this a config setting?
https://github.com/yargs/yargs/blob/main/docs/api.md#parserconfigurationobj
@bcoe I think that would be fine, but I can't say I fully understand the implications for other cases where we want the automatic formatting to do its thing.
Problem
My CLI defines two examples, and one of them has both a long command and a long description. Here is a simplified version of my
yargs
setup:When I run
ts-node index.ts --help
(indirectly through a script inpackage.json
), the output looks like this:The problem is in the Examples section, it looks like there are three examples – the second one is
cat myTranscribeFile.xsc | index.ts >
and the last one istranscribeFileData.json
.Solution
This problem could be avoided by indenting all lines after the first line (i.e. adding a trailing indent) in multi-line examples, in both the command part and the description part:
Implementation
I looked in the code of yargs, and I see that these steps are needed to implement this:
div
function (https://github.com/yargs/cliui/issues/77)multilineIndents
for each column that takes an array of two numbers[leadingIndent, trailingIndent]
.ui.div
calls inlib/usage.ts
to use trailing indentsmultilineIndents
as described above, this change would consist of addingmultilineIndents: [0, 2],
to the options for all three columns within those twoui.div
calls.Wider applicability
So far I haven’t seen this problem of confusing wrapped lines anywhere but in my Examples section. But I wonder if any of the other Yargs sections are susceptible to a similar readability problem. If so, maybe trailing indents could fix readability in those sections too.