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 = const cli = cli
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
Check for options
cli // will return true if setcli // will return the value of --lastname if set
Run command
Trigger a command from within the script.
cli
Prompt user for input
cliprompt'My question:'
Catch all commands
This will run if no registered command was triggered.
cli
Listen for data on stdin
cli
Write data to stdout
// you can useconsole// orcli
On exit
cli
Exit cli
cli // will close the cli and fire the exit event