
Security News
Static vs. Runtime Reachability: Insights from Latio’s On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
This library has been depreciated. Use classy-commander or commander instead!
The purrfect Command Line parsing library for Node.js console apps!
Kitten CLI enables rapid development of command line apps / tasks in node.
npm install kitten-cli --save
index.js
var cli = require('kitten-cli');
cli
.command('greet')
.value('name')
.action(greet);
cli.run();
function greet(command) {
console.log('Hello ' + command.value('name'));
}
Running node index.js greet World
would print Hello World
to the console
var cli = require('kitten-cli');
There are 2 ways to register commands:
cli
.command('login')
.value('user-name')
.value('password')
.option('-r', '--remember-me')
.action(login)
.command('logout')
.action(logout);
commands.txt
login <user-name> <password> -r|--remember-me
logout
Then load your commands from the file:
index.js
cli.commandsFromFile('commands.txt');
Note that if you use the DSL and you want to associate actions with your commands you still need to wire up your actions via the fluent API afterwards.
cli
.command('login').action(login)
.command('logout').action(logout);
You can declare options for a command. Note that you can specify multiple names for an option.
index.js
cli
.command('greet')
.value('name')
.option('-s', '--shout')
.action(showGreeting);
cli.run();
...
Then check them in your action handler:
...
function showGreeting(command) {
var message = 'Hi ' + command.value('name');
if (command.option('shout')) {
message = message.toUpperCase();
}
console.log(message);
}
Running node index.js greet Zoidberg
will print Hi Zoidberg
Running node index.js greet Zoidberg -s
will print HI ZOIDBERG
If you declare a value right after declaring an option, the value will be associated with the option (not the command).
cli
.command('bio')
.value('first-name')
.option('-l', '--last-name').value('last-name')
.option('-a', '--age').value('age')
.action(showBio);
function showBio(command) {
var message = 'First Name: ' + command.value('first-name');
if (command.option('last-name')) {
message += '\nLast Name' + command
.option('last-name')
.value('last-name');
}
if (command.option('age')) {
message += '\nAge:' + command
.option('age')
.value('age');
}
console.log(message);
}
Running node index.js bio Rick --last-name Sanchez --age 60
would print:
First Name: Rick
Last Name: Sanchez
Age: 60
Then please add an issue on GitHub! 😺
FAQs
The purrfect Command Line parsing library for Node.js
The npm package kitten-cli receives a total of 0 weekly downloads. As such, kitten-cli popularity was classified as not popular.
We found that kitten-cli 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
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.