Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
yargs-interactive
Advanced tools
Build command line tools without worring to parse arguments or ask them.
Interactive (prompt) support for yargs, based on inquirer. Useful for using the same CLI for both for humans and non-humans (like CI tools). Also supports mixed mode (yay!).
This tool helps you to build command line tools without worring to parse arguments or ask them.
npm install -S yargs-interactive
Then, add this code in your CLI code to get all the arguments parsed:
#!/usr/bin/env node
const yargsInteractive = require('yargs-interactive');
yargsInteractive()
.usage('$0 <command> [args]')
.interactive(/* pass options here, like */)
.then((result) => {
// Terminal arguments will be in the result
});
});
Finally, call your CLI from the terminal. You can see some example CLIs using this library here.
It supports the following use cases
my-cli.js
const yargsInteractive = require('yargs-interactive');
const options = {
name: {
type: 'input',
name: 'nano',
describe: 'Enter your name'
},
likesPizza: {
type: 'confirm',
default: false,
describe: 'Do you like pizza?'
},
};
yargsInteractive()
.usage('$0 <command> [args]')
.interactive(options)
.then((result) => {
// The tool will prompt questions and will output your answers.
// TODO: Do something with the result (e.g result.name)
console.log(result)
});
Usage in terminal
➜ node my-cli.js --interactive
Note: See more usage examples here.
It provides all prompt types supported by Inquirer.
You can opt-out options from interactive mode by setting the prompt
property to false
.
my-cli.js
const yargsInteractive = require('yargs-interactive');
const options = {
name: {
type: 'input',
name: 'nano',
describe: 'Enter your name'
},
likesPizza: {
type: 'confirm',
default: false,
describe: 'Do you like pizza?'
prompt: false // because everyone likes pizza
},
};
yargsInteractive()
.usage('$0 <command> [args]')
.interactive(options)
.then((result) => {
// The tool will prompt questions for all options and will output your answers.
// You can opt-out options by using `prompt: false`. For these properties, it
// will use the value sent by parameter (--likesPizza) or the default value.
// TODO: Do something with the result (e.g result.name)
console.log(result);
});
Usage in terminal
➜ node my-cli.js --name='Johh' --interactive
Note: See more usage examples here.
my-cli.js
const yargsInteractive = require('yargs-interactive');
const options = {
name: {
type: 'input',
name: 'nano',
describe: 'Enter your name'
},
likesPizza: {
type: 'confirm',
default: false,
describe: 'Do you like pizza?'
},
};
yargsInteractive()
.usage('$0 <command> [args]')
.interactive(options)
.then((result) => {
// The tool will output the values set via parameters or
// the default value (if not provided).
// TODO: Do something with the result (e.g result.name)
console.log(result);
});
Usage in terminal
➜ node my-cli.js --name='Johh' --likesPizza
Note: See more usage examples here.
FAQs
Build interactive command line tools without worring to parse the arguments (or ask them).
The npm package yargs-interactive receives a total of 7,505 weekly downloads. As such, yargs-interactive popularity was classified as popular.
We found that yargs-interactive 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 malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.