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

command-line-args

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

command-line-args - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

32

lib/command-line-args.js

@@ -27,2 +27,6 @@ var w = require("wodge"),

function isOption(input){
return longArg.test(input) || shortArg.test(input);
}
function setOutputValue(option, value){

@@ -39,15 +43,17 @@ model[option.name] = value;

} else if (argv.length) {
if (typeof option.type === "function"){
if (option.type === Array){
setOutputValue(option, spliceWhile(argv, /^\w+/));
} else {
setOutputValue(option, option.type(argv.shift()));
}
} else {
setOutputValue(option, argv.shift());
}
} else {
console.error(option);
throw new Error("weird case");
}
var value;
if (typeof option.type === "function" && option.type === Array){
value = spliceWhile(argv, /^\w+/);
} else {
if (isOption(argv[0])){
value = null;
} else {
value = argv.shift();
value = typeof option.type === "function" ? option.type(value) : value;
}
}
setOutputValue(option, value);
} else {
setOutputValue(option, null);
}
} else {

@@ -54,0 +60,0 @@ throw new Error("Unexpected option: " + optionName);

{
"name": "command-line-args",
"version": "0.2.0",
"version": "0.2.1",
"description": "Parse command line options",

@@ -10,2 +10,13 @@ "repository": "https://github.com/75lb/command-line-args.git",

},
"keywords": [
"argv",
"parse",
"argument",
"args",
"option",
"parser",
"parsing",
"cli",
"command"
],
"author": "Lloyd Brookes",

@@ -12,0 +23,0 @@ "devDependencies": {

@@ -24,1 +24,18 @@ var test = require("tap").test;

});
test("handles missing option value", function(t){
var argv = [ "--colour" ];
t.deepEqual(cliArgs(optionDefinitions).parse(argv), {
colour: null
});
t.end();
});
test("handles missing option value", function(t){
var argv = [ "--colour", "--number", "2" ];
t.deepEqual(cliArgs(optionDefinitions).parse(argv), {
colour: null,
number: 2
});
t.end();
});
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