Comparing version 1.6.0 to 1.7.0
# node-dashdash changelog | ||
## 1.7.0 | ||
- [pull #7] Support for `<parser>.help({helpWrap: false, ...})` option be able | ||
to fully control the formatting for option help (by Patrick Mooney) `helpWrap: | ||
false` can also be set on individual options in the option objects, e.g.: | ||
var options = [ | ||
{ | ||
names: ['foo'], | ||
type: 'string', | ||
helpWrap: false, | ||
help: 'long help with\n newlines' + | ||
'\n spaces\n and such\nwill render correctly' | ||
}, | ||
... | ||
]; | ||
## 1.6.0 | ||
- [pull #6] Support headings between groups of options (by Joshua M. Clulow). | ||
- [pull #6] Support headings between groups of options (by Joshua M. Clulow) | ||
so that this code: | ||
var options = [ | ||
{ group: 'Armament Options' }, | ||
{ names: [ 'weapon', 'w' ], type: 'string' }, | ||
{ group: 'General Options' }, | ||
{ names: [ 'help', 'h' ], type: 'bool' } | ||
]; | ||
... | ||
will give you this help output: | ||
... | ||
Armament Options: | ||
-w, --weapon | ||
General Options: | ||
-h, --help | ||
... | ||
## 1.5.0 | ||
@@ -9,0 +46,0 @@ |
@@ -299,2 +299,4 @@ /** | ||
format('config.options.%d.helpGroup', i)); | ||
assert.optionalBool(o.helpWrap, | ||
format('config.options.%d.helpWrap', i)); | ||
@@ -334,3 +336,3 @@ if (o.name) { | ||
* | ||
* @param inputs {Object} | ||
* @param inputs {Object} Optional. | ||
* - argv {Array} Optional. The argv to parse. Defaults to | ||
@@ -354,3 +356,6 @@ * `process.argv`. | ||
assert.object(inputs, 'inputs'); | ||
assert.optionalObject(inputs, 'inputs'); | ||
if (!inputs) { | ||
inputs = {}; | ||
} | ||
assert.optionalArrayOfString(inputs.argv, 'inputs.argv'); | ||
@@ -546,2 +551,4 @@ //assert.optionalNumber(slice, 'slice'); | ||
* - includeEnv {Boolean} Default false. | ||
* - helpWrap {Boolean} Default true. Wrap help text in helpCol..maxCol | ||
* bounds. | ||
* @returns {String} | ||
@@ -566,2 +573,3 @@ */ | ||
assert.optionalBool(config.includeEnv, 'config.includeEnv'); | ||
assert.optionalBool(config.helpWrap, 'config.helpWrap'); | ||
var maxCol = config.maxCol || 80; | ||
@@ -634,11 +642,6 @@ var minHelpCol = config.minHelpCol || 20; | ||
} | ||
var help = (o.help || '').trim(); | ||
var helpEnv = ''; | ||
if (o.env && o.env.length && config.includeEnv) { | ||
if (help.length && !~'.!?'.indexOf(help.slice(-1))) { | ||
help += '.'; | ||
} | ||
if (help.length) { | ||
help += ' '; | ||
} | ||
help += 'Environment: '; | ||
helpEnv += 'Environment: '; | ||
var type = optionTypes[o.type]; | ||
@@ -655,6 +658,26 @@ var arg = o.helpArg || type.helpArg || 'ARG'; | ||
); | ||
help += envs.join(', '); | ||
helpEnv += envs.join(', '); | ||
} | ||
line += textwrap(help, maxCol - helpCol).join( | ||
'\n' + space(helpCol)); | ||
var help = (o.help || '').trim(); | ||
if (o.helpWrap !== false && config.helpWrap !== false) { | ||
// Wrap help description normally. | ||
if (help.length && !~'.!?'.indexOf(help.slice(-1))) { | ||
help += '.'; | ||
} | ||
if (help.length) { | ||
help += ' '; | ||
} | ||
help += helpEnv; | ||
line += textwrap(help, maxCol - helpCol).join( | ||
'\n' + space(helpCol)); | ||
} else { | ||
// Do not wrap help description, but indent newlines appropriately. | ||
var helpLines = help.split('\n').filter( | ||
function (ln) { return ln.length }); | ||
if (helpEnv !== '') { | ||
helpLines.push(helpEnv); | ||
} | ||
line += helpLines.join('\n' + space(helpCol)); | ||
} | ||
lines[i] = line; | ||
@@ -661,0 +684,0 @@ }); |
{ | ||
"name": "dashdash", | ||
"description": "A light, featureful and explicit option parsing library.", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)", | ||
@@ -6,0 +6,0 @@ "keywords": ["option", "parser", "parsing", "cli", "command", "args"], |
@@ -243,3 +243,3 @@ A light, featureful and explicit option parsing library for node.js. | ||
- `interspersed` (Boolean). Option. Default is true. If true this allows | ||
- `interspersed` (Boolean). Optional. Default is true. If true this allows | ||
interspersed arguments and options. I.e.: | ||
@@ -252,3 +252,3 @@ | ||
- `allowUnknown` (Boolean). Option. Default is false. If false, this causes | ||
- `allowUnknown` (Boolean). Optional. Default is false. If false, this causes | ||
unknown arguments to throw an error. I.e.: | ||
@@ -293,2 +293,3 @@ | ||
helpArg: 'PATH', | ||
helpWrap: false, | ||
default: path.resolve(process.env.HOME, '.mytoolrc') | ||
@@ -347,2 +348,5 @@ } | ||
- `helpWrap` (Boolean). Optional, default true. Set this to `false` to have | ||
that option's `help` *not* be text wrapped in `<parser>.help()` output. | ||
- `default`. Optional. A default value used for this option, if the | ||
@@ -406,2 +410,4 @@ option isn't specified in argv. | ||
- `maxHelpCol` (Number). Default 40. | ||
- `helpWrap` (Boolean). Default true. Set to `false` to have option `help` | ||
strings *not* be textwrapped to the helpCol..maxCol range. | ||
- `includeEnv` (Boolean). Default false. If the option has associated | ||
@@ -408,0 +414,0 @@ environment variables (via the `env` option spec attribute), then |
@@ -883,2 +883,63 @@ /* | ||
}, | ||
// helpWrap option | ||
{ | ||
options: [ | ||
{ | ||
names: ['opt', 'o'], | ||
type: 'string', | ||
env: ['ENVVARIABLE'], | ||
help: 'long help with\n newlines' + | ||
'\n spaces\n and such\nwill not render correctly' | ||
}, | ||
{ | ||
names: ['array', 'a'], | ||
type: 'string', | ||
helpWrap: false, | ||
env: ['OTHERVARIABLE'], | ||
help: 'long help with\n newlines' + | ||
'\n spaces\n and such\nwill render correctly' | ||
}, | ||
{ | ||
names: ['foo'], | ||
type: 'string', | ||
helpWrap: false, | ||
env: ['FOOVAR'] | ||
} | ||
], | ||
argv: 'node helpWrapTool.js --help', | ||
helpOptions: { includeEnv: true }, | ||
/* BEGIN JSSTYLED */ | ||
expectHelp: [ | ||
/long help with newlines spaces and such will not render/, | ||
/\. Environment: ENVVARIABLE=ARG/, | ||
// Without wrapping: | ||
/long help with$/m, | ||
/^ +newlines$/m, | ||
/^ +Environment: OTHERVARIABLE=ARG/m, | ||
// Ensure FOOVAR env is on *first* line and not after a blank. | ||
/^ +--foo=ARG +Environment: FOOVAR=ARG$/m | ||
] | ||
/* END JSSTYLED */ | ||
}, | ||
{ | ||
options: [ | ||
{ | ||
names: ['array', 'a'], | ||
type: 'string', | ||
env: ['OTHERVARIABLE'], | ||
help: 'long help with\n newlines' + | ||
'\n spaces\n and such\nwill render correctly' | ||
} | ||
], | ||
argv: 'node helpWrapTool2.js --help', | ||
helpOptions: { includeEnv: true, helpWrap: false }, | ||
/* BEGIN JSSTYLED */ | ||
expectHelp: [ | ||
/long help with$/m, | ||
/^ +newlines$/m, | ||
/^ +Environment: OTHERVARIABLE=ARG/m, | ||
] | ||
/* END JSSTYLED */ | ||
}, | ||
]; | ||
@@ -885,0 +946,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132924
1967
498