n-cli

a usefull toolset for node commandline applications
Installation
$ npm install --save n-cli
Usage
#!/usr/bin/env node
"use strict";
var Cli = new require("n-cli");
var cli = new Cli({
silent: false,
handleUncaughtException : true
});
cli.on("unicorn", function(){
this.argv.notNull("rainbow");
this.log(this);
});
$ your-client-app unicorn --rainbow forever;
{
prettyError:
PrettyError { },
init:
{ appname: 'node-cli-example-app-1',
handleUncaughtException: true },
argv: { _: [ 'unicorn' ], rainbow: 'e', notNull: [Function: bound ] },
config:
{ settings: {},
appFolder: 'c:\\git\\n-cli\\examples',
appPackageFilename: 'c:\\git\\n-cli\\examples\\package.json',
appPackage: {},
appName: 'node-cli-example-app-1',
dataFolder: 'C:\\Users\\User\\AppData\\Roaming\\node-cli-example-app-1',
filename: 'C:\\Users\\User\\AppData\\Roaming\\node-cli-example-app-1\\config.json' },
color:
Chalk { },
Error: [Function: NodeCliError],
minimist: [Function]
}
$ your-client-app unicorn --rainbow ;
Demo
https://www.youtube.com/watch?v=m53SlSaP6cs
License
MIT © s-a
API
CLI
Members:
CLI(config)
Parameters
config: object
, configuration.
Example:
var cli = new CLI({
silent: false,
handleUncaughtException : true
})
CLI.resolvePath(fileOrDir)
Resolve a path
Parameters
fileOrDir: string
, Filename or directory
Returns: string
, Absolute directory name relative to the current working directory of process.
CLI.findup(basedir, filename)
Find a file in parent directories.
Parameters
basedir: string
, In most cases the current directory of process.
filename: string
, Filename to find.
Returns: string
, Absolute directory to given filename
.
CLI.programInfo()
Output program informations based on package.json
to console.
CLI.on(commandName, commandFunction)
Catch a commandline switch case. The commandFunction runs in context of CLI.
Parameters
commandName: string
, A command you want to process. For example push
or commit
.
commandFunction: function
, An event handler function.
CLI.silent()
Determines of console app is running in silent mode. Silent mode activates automaticaly when process.env.NODE_ENV === "test"
.
CLI.log()
Like console.log put implements util.inspect.
CLI.error()
Like console.error put implements util.inspect.
CLI.stdout()
Wrapper for process.stdout.write
CLI.stderr()
Wrapper for process.stderr.write