Commands

tmcw edited this page Feb 13, 2012 · 2 revisions

Commands

Commands are a way to execute particular actions for your Bones plugin using the command line. Bones ships with one command called start which is also the default action taken when you don't pass a command:

Usage: node ./index.js [command] --help for a list of options.
Available commands are:
  start:  start application

Default config options

When running node ./index.js start --help, on an empty application, you'll get these default options:

  -a  --adminParty     Enable admin mode. (Default: false)
      --config=[path]  Path to JSON configuration file.

  --host=false         Allow access to your bones application from any host

The --config parameter is available globally for each command. To show which configuration options Bones loads and uses, pass --show-config.

Creating a custom command

To add a custom command, create a commandname.bones file in the commands directory with:

command = Bones.Command.extend();

command.description = 'description';

command.options.paramName = {
    'title': 'paramName=[paramValue]', 
    'shortcut': 'a',                   
    'description': 'Description.',     
    'default': false                   
};

command.prototype.initialize = function(plugin, callback) {
    // Execute action.
};

For command options, every value in the hash is optional. 'default' can be either a plain value or a function. In the latter case, it will be called on application startup with the plugin object as the first parameter.

Adding more config defaults

To add config options to all commands, create an arbitrarily named file in the commands folder and add options to Bones.Command.options:

Bones.Command.options['syslog'] = {
    'title': 'syslog',
    'description': 'Log to syslog instead of stdout.',
    'default': false
};