Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A library for node.js to build command-line interfaces (CLI). With its help, making a simple CLI application is a trivial task. It equally excels in complex tools with a lot of subcommands and specific features. This library supports argument coercion and completion suggestion — typing the commands is much easier.
Inspired by commander.js
Features:
npm install clap
const cli = require('clap');
const myCommand = cli.command('my-command [optional-arg]')
.description('Optional description')
.version('1.2.3')
.option('-b, --bool', 'Bollean option')
.option('--foo <foo>', 'Option with required argument')
.option('--bar [bar]', 'Option with optional argument')
.option('--baz [value]', 'Option with optional argument and normalize function',
value => Number(value),
123 // 123 is default
)
.action(function({ options, args, literalArgs }) {
// options is an object with collected values
// args goes before options
// literal args goes after "--"
});
myCommand.run(); // the same as "myCommnad.run(process.argv.slice(2))"
myCommand.run(['--foo', '123', '-b'])
// sub-commands
myCommand
.command('nested')
.option('-q, --quz', 'Some parameter', 'Default value')
// ...
.end()
.command('another-command [arg1] [arg2]')
// ...
.command('level3-command')
//...
.command()
// definition
.description(value)
.version(value, usage, description, action)
.help(usage, description, action)
.option(usage, description, ...options)
.command(usageOrCommand)
.extend(fn, ...options)
.end()
// argv processing pipeline handler setters
.init(command, context)
.applyConfig(context)
.prerareContenxt(context)
.action(context)
// main methods
.parse(argv, suggest)
.run(argv)
// misc
.clone(deep)
.createOptionValues()
.getCommand(name)
.getCommands()
.getOption(name)
.getOptions()
.outputHelp()
There are two usage:
.option(usage, description, normalize, value)
.option(usage, description, options)
Where options
:
{
default: any, // default value
normalize: (value, oldValue) => { ... }, // any value for option is passing through this function and its result stores as option value
shortcut: (value, oldValue) => { ... }, // for shortcut options, the handler is executed after the value is set, and its result (an object) is used as a source of values for other options
action: () => { ... }, // for an action option, which breaks regular args processing and preform and action (e.g. show help or version)
config: boolean // mark option is about config and should be applied before `applyConfig()`
}
init(command, context)
// before arguments parsing
applyConfig(context)
prepareContext(context)
// after arguments parsing
init(command, context)
applyConfig(context)
prepareContext(context)
// after arguments parsing
action(context)
-> command is targetaction(context)
-> command is targetMIT
3.1.0 (February 7, 2022)
command()
function by removing parameters except the first one, since others are not used anymorecommand("name", "[arg1] [arg2]")
) to avoid mistakes on migration from v2.0-
as a value for argFAQs
Command line argument parser
The npm package clap receives a total of 641,451 weekly downloads. As such, clap popularity was classified as popular.
We found that clap 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.