Socket
Socket
Sign inDemoInstall

dreamopt

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dreamopt - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

24

lib/dreamopt.js

@@ -301,3 +301,3 @@ (function() {

Syntax.prototype.parse = function(argv) {
var $, arg, executeHook, func, funcs, index, name, option, positional, processOption, remainder, result, subarg, value, _, _i, _j, _len, _len2, _len3, _len4, _ref, _ref2, _ref3,
var $, arg, assignValue, executeHook, func, funcs, index, name, option, positional, processOption, remainder, result, subarg, value, _, _i, _j, _len, _len2, _len3, _len4, _ref, _ref2, _ref3,
_this = this;

@@ -345,2 +345,10 @@ argv = argv.slice(0);

};
assignValue = function(result, option, value) {
if (option.tags.list) {
if (!result.hasOwnProperty(option["var"])) result[option["var"]] = [];
if (value != null) return result[option["var"]].push(value);
} else {
return result[option["var"]] = value;
}
};
while (arg = argv.shift()) {

@@ -354,3 +362,3 @@ if (arg === '--') {

} else if (arg.match(/^--no-/) && (option = this.longOptions[arg.slice(5)]) && option.tags.flag) {
result[option["var"]] = false;
assignValue(result, option, false);
} else if ($ = arg.match(/^--([^=]+)(?:=(.*))?$/)) {

@@ -361,3 +369,3 @@ _ = $[0], name = $[1], value = $[2];

value = executeHook(option, value);
result[option["var"]] = value;
assignValue(result, option, value);
} else {

@@ -380,3 +388,3 @@ throw new Error("Unknown long option: " + arg);

value = executeHook(option, value);
result[option["var"]] = value;
assignValue(result, option, value);
} else {

@@ -401,3 +409,3 @@ if (arg === ("-" + subarg)) {

}
if ((option.defaultValue != null) || option.tags.fancydefault) {
if ((option.defaultValue != null) || option.tags.fancydefault || option.tags.list) {
if (option.defaultValue != null) {

@@ -409,3 +417,3 @@ value = option.coerce(option.defaultValue, result, this);

value = executeHook(option, value);
result[option["var"]] = value;
assignValue(result, option, value);
}

@@ -420,3 +428,3 @@ }

positional[index] = value;
if (option["var"]) result[option["var"]] = value;
if (option["var"]) assignValue(result, option, value);
}

@@ -438,3 +446,3 @@ }

value = executeHook(option, value);
if (option["var"]) result[option["var"]] = value;
if (option["var"]) assignValue(result, option, value);
if (index === positional.length) {

@@ -441,0 +449,0 @@ positional.push(value);

@@ -5,3 +5,3 @@ {

"description": "Command-line parser with readable syntax from your sweetest dreams",
"version": "0.5.1",
"version": "0.6.0",
"homepage": "https://github.com/andreyvit/dreamopt.js",

@@ -8,0 +8,0 @@ "repository": {

@@ -145,2 +145,3 @@ Command-Line Parser With Readable Syntax From Your Sweetest Dreams

* `#default(value)` specifies a default value
* `#list` marks an option that may be used multiple times; the final value is a JavaScript array
* `#fancydefault` forces the callback function associated with the current option to be called even when an argument is not provided and no default is set; in this case, the original value will be `null` and your function is expected to return a better one

@@ -147,0 +148,0 @@ * `#delayfunc` delays invocation of the callback function until all other options and arguments are processed; this is useful for options like `--help` or `--print-reporters`, when you want all normal options to be handled and validated before the callback is invoked; the return value of such callback functions is ignored

@@ -198,3 +198,3 @@ (function() {

});
return describe("with a syntax that has a required option", function() {
describe("with a syntax that has a required option", function() {
var syntax;

@@ -219,4 +219,22 @@ syntax = [" --src FILE Source file #required", " first First positional arg"];

});
return describe("with a syntax that has a list option", function() {
var syntax;
syntax = [" --src FILE Source file #list"];
o(syntax, [], {
src: [],
argv: []
});
o(syntax, ['--src', 'xxx'], {
src: ['xxx'],
argv: []
});
return o(syntax, ['--src', 'xxx', '--src', 'yyy'], {
src: ['xxx', 'yyy'],
argv: []
});
});
});
setTimeout((function() {}), 2000);
}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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