Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
So you want a CLI...
A better CLI framework, made for the ES2015 era.
Visit http://sywac.io for detailed documentation. NOTE! The docs site is still under construction.
process.argv
First install sywac from npm:
$ npm install --save sywac
Then create a cli.js
file with code similar to this:
#!/usr/bin/env node
'use strict'
require('sywac')
.positional('<string>', { paramsDesc: 'A required string argument' })
.boolean('-b, --bool', { desc: 'A boolean option' })
.number('-n, --num <number>', { desc: 'A number option' })
.help('-h, --help')
.version('-v, --version')
.showHelpByDefault()
.outputSettings({ maxWidth: 75 })
.parseAndExit()
.then(argv => {
console.log(JSON.stringify(argv, null, 2))
})
Make the cli.js
file executable:
$ chmod +x cli.js
And set up cli.js
as the "bin"
field in package.json
:
{
"name": "example",
"version": "0.1.0",
"bin": "cli.js"
}
Then test it out. Without any arguments, it will print the help text.
$ ./cli.js
Usage: cli <string> [options]
Arguments:
<string> A required string argument [required] [string]
Options:
-b, --bool A boolean option [boolean]
-n, --num <number> A number option [number]
-h, --help Show help [commands: help] [boolean]
-v, --version Show version number [commands: version] [boolean]
Let's try passing some arguments:
$ ./cli.js hello -b -n 42
{
"_": [],
"string": "hello",
"b": true,
"bool": true,
"n": 42,
"num": 42,
"h": false,
"help": false,
"v": false,
"version": false
}
What happens if we pass flags without a string argument?
$ ./cli.js --bool
Usage: cli <string> [options]
Arguments:
<string> A required string argument [required] [string]
Options:
-b, --bool A boolean option [boolean]
-n, --num <number> A number option [number]
-h, --help Show help [commands: help] [boolean]
-v, --version Show version number [commands: version] [boolean]
Missing required argument: string
Validation failed and sywac printed the help text with an error message. Let's check the exit code of that last run:
$ echo $?
1
This is a good sign that our CLI will play well with others.
For details on the full API, go to http://sywac.io
MIT
FAQs
So you want a CLI...
We found that sywac 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.