
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
cmd-arg-parser
Advanced tools
A simple command line argument parser for Node.js
It's Lightweight though provides features like arguments Grouping, Mutual Exclusion, and short option grouping.
No default option is defined, it simply parses the given set of arguments into a useful object.
-o value) and long (-option value) argument names.-o)
boolean and it does not require any argument.-o [value])
-o value)
-a, -b, and c are 3 flag options then, -abc can also be directly used to enable all three in once)npm install cmd-arg-parser
banner
parser.banner= 'new banner'optionsTitle
parser.optionsTitle= 'List of options'optionsTail
parser.optionsTail= 'Note at the end of the option list'addOption (shortName, longName, description, defaultValue, handler)
shortName: is a short option name (-o), RequiredlongName: is a long option name (--option), Requireddescription: is a option description (This is option description), RequireddefaultValue: is a option value if option is optional also this can be callback function that gets executed when a option is parsed, Optionalhandler: is a callback function that gets executed when a option is parsed, Optionalparser.addOption('-a','--option-a','This is a options A',callback);formOptionsGroup (groupTitle, groupOptionShortNameArray, groupNote)
groupTitle: is a groups title (Group title), RequiredgroupOptionShortNameArray: is a array of shortNames, RequiredgroupNote: is a information about the group shown in help/usage section, OptionalmakeOptionsMutuallyExclusive (optionsArray)
optionsArray: is a array of at least two shortNames, Requiredparse (options)
options: is a array of actually passed optionhelp
console.log(parser.help())var CmdArgParser = require('cmd-arg-parser');
var parser = new CmdArgParser();
// Initialize options.
// A flag only option
parser.addOption('-a', '--option-a', 'This is a options A');
// A Optional option without any default value
parser.addOption('-b', '--option-b [OPTIONAL]', 'This is a options B');
// A Optional option with default value 'DEFAULT'
parser.addOption('-c', '--option-c [OPTIONAL]', 'This is a options C', 'DEFAULT');
// A Optional option with default value 'DEFAULT' and a callback function
parser.addOption('-d', '--option-d [OPTIONAL]', 'This is a options d', 'DEFAULT', function (opt, value) {
// opt: is a camelCased option long name, e.g. optionD
// value: is a option value
console.log('%s : %s', opt, value);
});
// A Required option
parser.addOption('-e', '--option-e REQUIRED', 'This is a options E');
// A Required option with callback function
parser.addOption('-f', '--option-f REQUIRED', 'This is a options F', function (opt, value) {
// opt: is a camelCased option long name, e.g. optionF
// value: is a option value
console.log(' %s : %s', opt, value);
});
parser.addOption('-g', '--option-g', 'This is a options G');
parser.formOptionsGroup('Group Title', ['-d', '-e', '-f'], 'Group note');
parser.makeOptionsMutuallyExclusive(['-a', '-g']);
parser.addOption('-h', '--option-h', 'This is a help options', function () {
console.log(parser.help());
});
var optionArray = ['-a', '-c', 'optionalArgValue', '-e', 'requiredOptionValue'];
var result = parser.parse(optionArray);
parser.banner = 'Usage: [OPTIONS]';
parser.optionsTitle = 'new Title';
parser.optionsTail = 'A note that is shown at the end of the option list';
FAQs
A simple command line argument parser for Node.js
The npm package cmd-arg-parser receives a total of 3 weekly downloads. As such, cmd-arg-parser popularity was classified as not popular.
We found that cmd-arg-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.