Skip to content

Commit 7931652

Browse files
maxrimuebcoe
authored andcommitted
feat: if only one column is provided for examples, allow it to take up the entire line (#749)
1 parent 2e5ce0f commit 7931652

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/usage.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,24 @@ module.exports = function (yargs, y18n) {
261261
})
262262

263263
examples.forEach(function (example) {
264-
ui.div(
265-
{text: example[0], padding: [0, 2, 0, 2], width: maxWidth(examples, theWrap) + 4},
266-
example[1]
267-
)
264+
if (example[1] === '') {
265+
ui.div(
266+
{
267+
text: example[0],
268+
padding: [0, 2, 0, 2]
269+
}
270+
)
271+
} else {
272+
ui.div(
273+
{
274+
text: example[0],
275+
padding: [0, 2, 0, 2],
276+
width: maxWidth(examples, theWrap) + 4
277+
}, {
278+
text: example[1]
279+
}
280+
)
281+
}
268282
})
269283

270284
ui.div()

test/usage.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,25 @@ describe('usage tests', function () {
13371337
})
13381338
})
13391339

1340+
it('should not wrap left-hand-column if no description is provided', function () {
1341+
var r = checkUsage(function () {
1342+
return yargs([])
1343+
.example('i am a fairly long example that is like really long woooo')
1344+
.demand('foo')
1345+
.wrap(50)
1346+
.argv
1347+
})
1348+
1349+
r.errors[0].split('\n').forEach(function (line, i) {
1350+
// ignore headings and blank lines.
1351+
if (!line.match('i am a fairly long example')) return
1352+
1353+
// with two white space characters on the left,
1354+
// line length should be 50 - 2
1355+
line.length.should.equal(48)
1356+
})
1357+
})
1358+
13401359
it('should wrap the usage string', function () {
13411360
var r = checkUsage(function () {
13421361
return yargs([])

0 commit comments

Comments
 (0)