Skip to content

Commit

Permalink
right-alignment of wrapped extra params
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 16, 2011
1 parent 2b980bf commit b72bacf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion examples/line_count_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ var argv = require('optimist')
+ " Required even. So you'd better specify it."
)
.alias('b', 'base')
.describe('b', 'Numeric base to display the final output in.')
.describe('b', 'Numeric base to display the number of lines in')
.default('b', 10)
.describe('x', 'Super-secret optional parameter which is secret')
.default('x', '')
.argv
;

Expand Down
25 changes: 18 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,34 @@ function Argv (args, cwd) {
}

var prelude = ' ' + kswitch + spadding;
var body = [
desc,
var extra = [
type,
wrap
? '\n' + new Array(prelude.length + 3).join(' ')
: null
,
demanded[key]
? '[required]'
: null
,
defaults[key]
defaults[key] !== undefined
? '[default: ' + JSON.stringify(defaults[key]) + ']'
: null
,
].filter(Boolean).join(' ');

var body = [ desc, extra ].filter(Boolean).join(' ');

if (wrap) {
var dlines = desc.split('\n');
var dlen = dlines.slice(-1)[0].length
+ (dlines.length === 1 ? prelude.length : 0)

body = desc + (dlen + extra.length > wrap - 2
? '\n'
+ new Array(wrap - extra.length + 1).join(' ')
+ extra
: new Array(wrap - extra.length - dlen + 1).join(' ')
+ extra
);
}

help.push(prelude + body);
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "optimist",
"version" : "0.2.2",
"version" : "0.2.3",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"main" : "./index.js",
"directories" : {
Expand Down

0 comments on commit b72bacf

Please sign in to comment.