Skip to content

Commit

Permalink
feat: if only one column is provided for examples, allow it to take u…
Browse files Browse the repository at this point in the history
…p the entire line (#749)
  • Loading branch information
maxrimue authored and bcoe committed Jan 16, 2017
1 parent 2e5ce0f commit 7931652
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/usage.js
Expand Up @@ -261,10 +261,24 @@ module.exports = function (yargs, y18n) {
})

examples.forEach(function (example) {
ui.div(
{text: example[0], padding: [0, 2, 0, 2], width: maxWidth(examples, theWrap) + 4},
example[1]
)
if (example[1] === '') {
ui.div(
{
text: example[0],
padding: [0, 2, 0, 2]
}
)
} else {
ui.div(
{
text: example[0],
padding: [0, 2, 0, 2],
width: maxWidth(examples, theWrap) + 4
}, {
text: example[1]
}
)
}
})

ui.div()
Expand Down
19 changes: 19 additions & 0 deletions test/usage.js
Expand Up @@ -1337,6 +1337,25 @@ describe('usage tests', function () {
})
})

it('should not wrap left-hand-column if no description is provided', function () {
var r = checkUsage(function () {
return yargs([])
.example('i am a fairly long example that is like really long woooo')
.demand('foo')
.wrap(50)
.argv
})

r.errors[0].split('\n').forEach(function (line, i) {
// ignore headings and blank lines.
if (!line.match('i am a fairly long example')) return

// with two white space characters on the left,
// line length should be 50 - 2
line.length.should.equal(48)
})
})

it('should wrap the usage string', function () {
var r = checkUsage(function () {
return yargs([])
Expand Down

0 comments on commit 7931652

Please sign in to comment.