
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
command-line-parser
Advanced tools
Simple lightweight function takes an array of command-line arguments and returns a parsed object
This code:
const argsObj = require('command-line-parser')();
invoked with:
node ./myscript.js myfile1 -v -debug -host there.com -port 8081 myfile2
returns this argsObj
object:
{
v: true,
debug: true,
host: 'there.com',
port: '8081',
_args: [ 'myfile1', 'myfile2' ]
}
This simple lightweight module exports a default function that takes an array of command-line arguments and returns a parsed object (a bit simpler than the venerable minimist
).
-abc
or -n5
).--debug
would be processed).Any argument with a dash is considered one key and will be in the parsed object with the following value:
-key value
).-key1 -key2
).Arguments that don't fulfill the role of a key or a value for a key will be added to a field called _args
in the parsed object.
If no argument is passed in to the default module function, it defaults to the array process.argv.slice(2)
.
See test/assert.js
for example usage.
Install with npm install command-line-parser
.
Test via npm test
.
PS. Useful pattern using destructuring assignment, default values, and renaming _args
:
const { v, debug = false, host = 'default.com', port = '80', _args: files = [] } = argsObj ;
will assign the locally scoped constant variables v
, debug
, host
, port
, and files
.
FAQs
Simple lightweight function takes an array of command-line arguments and returns a parsed object
The npm package command-line-parser receives a total of 719 weekly downloads. As such, command-line-parser popularity was classified as not popular.
We found that command-line-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.