
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
cli-inquirer
Advanced tools
A NodeJS package for CLI parsing. It will ask the user for an instruction and then parse it into a command, options and flags.
The easiest way to start using this package is to install it using npm.
In you application run npm i cli-inquirer and then require it in your code with const { inquirer } = require('cli-inquirer');.
This package has typescript declaration files, so if you're writing typescript code you can use import { inquirer } from 'cli-inquirer';.
When the exported function is called, it will prompt the user (via the command line) for an instruction. Once the user's input has been received it will be parsed and split into three components:
A Promise is returned that will resolve with an Object (containg the 3 properties listed above) or rejects with an error message.
NOTE: the options and flags can be provided by the user in any order.
The best way to check this package is to test it.
Check the folder examples/ for example code.
node examples/no-validation.js
node examples/with-validation.js
The package exposes one function named inquirer that receives 3 optional arguments:
Please type a command? .{}.{}.and returns a promise that resolves with an object with syntax
{
command: string,
options: string[],
flags: string[][]
}
or rejects with an error string.
If an empty object is provided, no validation of the commands or options will be done.
The syntax for this object is
{
[key: string]: (RegExp | null)[]
}
where the keys are the valid commands and the values are arrays of regexp objects or null, defining the valid options for each command.
The order of the array will be the order the options are expected to be given.
A null value defined that option as being non-required.
If an empty object is provided, no validation of the flags will be done.
The syntax for this object is
{
[key: string]: {
commands?: string[],
arg?: RegExp,
alias?: string
}
}
where the keys are the valid flags and the values are objects defining each flag's valid data.
/.+/ is enough.
A flag's argument will be stored with the flag under the flags property of the returned object.Consider the following code
'use strict';
const { inquirer } = require("cli-inquirer");
const commandData = {
'help': [/^files?$/i, /^\w+$/i],
'create': [null],
'generate': []
};
const flagData = {
'-f': {
commands: ['create', 'generate']
},
'--force': {
alias: '-f'
},
'-t': {
commands: ['help', 'create'],
arg: /^[^\s]+$/i
},
'--target': {
alias: '-t'
}
};
inquirer('type an instruction: ', commandData, flagData).
then((instruction) => {
// continue your code
}).
catch((reason) => {
// handle the error
});
For a user input of create file -f --target ./src/newfile.js the promise would resolve with
{
command: "create",
options: ["file"],
flags: [["-f"], ["--target", "./src/newfile.js"]]
}
cd into the package directorynpm installnpm run test -- ./test/**/*.test.jsFAQs
A CLI parser for nodejs applications.
We found that cli-inquirer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.