diff --git a/lib/usage.js b/lib/usage.js index 555ffb52b..765c271ee 100644 --- a/lib/usage.js +++ b/lib/usage.js @@ -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() diff --git a/test/usage.js b/test/usage.js index a8877bfc7..6b5772233 100644 --- a/test/usage.js +++ b/test/usage.js @@ -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([])