
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
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
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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.