Super-CLI

Super-CLI is a micro framework for creating command line tools in node.
The goal with Super-CLI is to have a simple and powerful API, which enables you
to create beautiful CLI programs with minimal effort.
A Super-CLI script will have a structure like below.
my-script command [options, ...] [arguments, ...]
Install
npm install super-cli -—save
Usage
To get started you have to require the super-cli module and register your commands.
Remember to set the environment to node at the top of the script #!/usr/bin/env node
and make your script executable chmod a+x my-script
.
#!/usr/bin/env node
const SuperCLI = require('super-cli')
const cli = new SuperCLI()
cli.on('my-command', arg => {
console.log(arg)
})
Register commands
Commands are simply registered like below and arguments are automatically
parsed to the callbacks as function arguments.
If your CLI program has a lot of commands, it would be a great idea to move
the command callbacks into seperate files.
cli.on('my-command', (arg1, arg2, ...) => {
})
Check for options
cli.option('-h', '--help')
cli.option('-l=', '--lastname=')
Run command
Trigger a command from within the script.
cli.run('my-command')
Prompt user for input
cli.prompt('My question:').then(answer => console.log(answer))
Catch all commands
This will run if no registered command was triggered.
cli.on('*', (...args) => {
console.log(args)
})
Listen for data on stdin
cli.stdin(data => console.log(data))
Write data to stdout
console.log('message')
cli.stdout('message')
On exit
cli.on('exit', () => {
})
Exit cli
cli.exit()