CLI

Server.Modules. CLI

# new CLI(coreObj) → {Server.Modules.CLI}

This is the CLI Module of the Blackrock Application Server. It is responsible for parsing command-line arguments passed to the application server at startup, and then executing methods from within other modules that have registered with the CLI module for those specific command-line arguments.

Parameters:
Name Type Description
coreObj Server.Modules.Core

The Core Module Singleton

Author:
  • Darren Smith
License:
  • Licensed under the LGPL license.
Returns:

module - The CLI Module Singleton

Type
Server.Modules.CLI

Extends

Methods

# (static) register(commands) → {boolean}

The register method on the CLI Module is used to register function handlers against a collection of defined command-line arguments. It can only be called internally (from other modules) within the application server, and must be called as part of the module's construction. Once all dependencies are loaded, the CLI Module will check the command-line arguments for the presence of any registered commands, and where present will execute the registered handlers for those commands.

Parameters:
Name Type Description
commands object

The Commands Object

Returns:

result - Method Result

Type
boolean
Example
core.module.isLoaded('cli').then(function(cliMod) {
   cliMod.register([
     {'cmd': 'install', 'params': '[app]', 'info': 'Installs a new app', 'fn': function(params) {
       core.emit('INSTALLER_INIT_INSTALLER', {'command': 'install', 'params': params});
     }},
     {'cmd': 'remove', 'params': '[app]', 'info': 'Removes an installed app', 'fn': function(params) {
       core.emit('INSTALLER_INIT_INSTALLER', {'command': 'remove', 'params': params});
     }},
   ]);
 }).catch(function(err) {
   log('error',
       'Failed to register with CLI - CLI module not loaded',
       err, 'INSTALLER_CLI_MOD_NOT_LOADED');
 });