Why Shell.js?
Configure your CLI app
Shell.js is simple to configure. All it takes is a declarative object describing your application. Consider it like the model of your application. It is enriched by plugins such as to route commands and to generate help screens.
const shell = require("shell")
const app = shell({
name: "myapp",
description: "My CLI application",
options: {
"config": {
shortcut: "c",
description: "Some option"
}
},
commands: {
"start": {
description: "Start something"
}
}
})
Parse arguments
For the handling and adding the functionality to the application operate with the `args` object returned with the method `parse`.
/* ... */
const args = app.parse()
console.log(args)
// Run `node myapp -c value start`
{ command: [ 'start' ], config: 'value' }
Organize the code with routing
Load and configure the router in a separate top-level module.
const shell = require("shell")
const app = shell({
/* ... */
commands: { "start":
{
/* ... */
route: './routes/start.js'
}
}
})
app.route()
/* The project structure:
|-- /node-modules
|-- /routes
|-- start.js
|-- myapp.js
|-- package.json
|-- package-lock.json
*/
Auto generate help
Shell.js convert the configuration object into a readable documentation string about how to use the CLI application or one of its commands.
// Run `node myapp help`
NAME
myapp - My CLI application
SYNOPSIS
myapp [myapp options] <command>
OPTIONS
-c --config Some option
-h --help Display help information
COMMANDS
start Start something
help Display help information
EXAMPLES
myapp --help Show this message
myapp help Show this message
Installing
The latest version of Shell.js is tested with Node.js 12, 14 and 16. New versions of Node.js shall work as well.
Via npm:
npm install shell
Via git (or downloaded tarball), copy or link the project from a discoverable Node.js directory:
git clone http://github.com/adaltas/node-shell.git