Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dashdash

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashdash - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

7

CHANGES.md
# node-dashdash changelog
## 1.10.0
- [issue #9] Support `includeDefault` in help config (similar to `includeEnv`) to have a
note of an option's default value, if any, in help output.
- [issue #11] Fix option group breakage introduced in v1.9.0.
## 1.9.0

@@ -4,0 +11,0 @@

21

examples/custom-option-fruit.js

@@ -41,7 +41,13 @@ #!/usr/bin/env node

var options = [
{ names: ['pie', 'p'], type: 'fruit' }
{
names: ['help', 'h'], // first name is opts key
type: 'bool',
help: 'Print this help and exit.'
},
{ names: ['pie', 'p'], type: 'fruit', env: 'FRUIT' }
];
var parser = dashdash.createParser({options: options});
try {
var opts = dashdash.parse({options: options});
var opts = parser.parse(process.argv);
} catch (e) {

@@ -52,2 +58,13 @@ console.error('%s: error: %s', path.basename(process.argv[1]), e.message);

if (opts.help) {
var help = parser.help({
includeEnv: true,
includeDefault: true
}).trimRight();
console.log('usage: node custom-option-fruit.js [OPTIONS]\n'
+ 'options:\n'
+ help);
process.exit(0);
}
console.log('pie fruit: %s', opts.pie);

@@ -518,3 +518,3 @@ /**

opts[o.key] = o.default;
} else if (optionTypes[o.type].default !== undefined) {
} else if (o.type && optionTypes[o.type].default !== undefined) {
opts[o.key] = optionTypes[o.type].default;

@@ -552,3 +552,8 @@ }

* - maxHelpCol {Number} Default 40.
* - includeEnv {Boolean} Default false.
* - includeEnv {Boolean} Default false. If true, a note stating the `env`
* envvar (if specified for this option) will be appended to the help
* output.
* - includeDefault {Boolean} Default false. If true, a note stating
* the `default` for this option, if any, will be appended to the help
* output.
* - helpWrap {Boolean} Default true. Wrap help text in helpCol..maxCol

@@ -575,2 +580,3 @@ * bounds.

assert.optionalBool(config.includeEnv, 'config.includeEnv');
assert.optionalBool(config.includeDefault, 'config.includeDefault');
assert.optionalBool(config.helpWrap, 'config.helpWrap');

@@ -649,4 +655,14 @@ var maxCol = config.maxCol || 80;

var helpDefault;
if (config.includeDefault) {
if (o.default !== undefined) {
helpDefault = format('Default: %j', o.default);
} else if (o.type && optionTypes[o.type].default !== undefined) {
helpDefault = format('Default: %j',
optionTypes[o.type].default);
}
}
var line = lines[i] = indent + lines[i];
if (!o.help && !(config.includeEnv && o.env)) {
if (!o.help && !(config.includeEnv && o.env) && !helpDefault) {
return;

@@ -680,3 +696,3 @@ }

// Wrap help description normally.
if (help.length && !~'.!?'.indexOf(help.slice(-1))) {
if (help.length && !~'.!?"\''.indexOf(help.slice(-1))) {
help += '.';

@@ -688,2 +704,8 @@ }

help += helpEnv;
if (helpDefault) {
if (helpEnv) {
help += '. ';
}
help += helpDefault;
}
line += textwrap(help, maxCol - helpCol).join(

@@ -698,2 +720,5 @@ '\n' + space(helpCol));

}
if (helpDefault) {
helpLines.push(helpDefault);
}
line += helpLines.join('\n' + space(helpCol));

@@ -700,0 +725,0 @@ }

2

package.json
{
"name": "dashdash",
"description": "A light, featureful and explicit option parsing library.",
"version": "1.9.0",
"version": "1.10.0",
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",

@@ -6,0 +6,0 @@ "keywords": ["option", "parser", "parsing", "cli", "command", "args"],

@@ -418,2 +418,5 @@ A light, featureful and explicit option parsing library for node.js.

append mentioned of those envvars to the help string.
- `includeDefault` (Boolean). Default false. If the option has a default value
(via the `default` option spec attribute, or a default on the option's type),
then a "Default: VALUE" string will be appended to the help string.

@@ -433,3 +436,4 @@

...
}
},
default: ... // optional
});

@@ -436,0 +440,0 @@

@@ -1053,3 +1053,6 @@ /*

],
options: [ {names: ['pie', 'p'], type: 'fruit'} ],
options: [
{group: 'Filling'},
{names: ['pie', 'p'], type: 'fruit', env: 'FRUIT'}
],
argv: 'node foo.js -p pear',

@@ -1059,3 +1062,13 @@ expect: {

_args: []
}
},
helpOptions: {
includeEnv: true,
includeDefault: true
},
/* BEGIN JSSTYLED */
expectHelp: [
/^ Filling:$/m,
/ +Environment: FRUIT=<fruit>\. Default: "apple"/m,
]
/* END JSSTYLED */
},

@@ -1062,0 +1075,0 @@ ];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc