Esempio n. 1
0
 return function loadDrivers(dir) {
     dir = dir || path.join(app.root, 'drivers');
     var drivers = needs(dir, {
         module: true,
         filter: loadDriver
     });
     log.info('Loaded drivers: %s', Object.keys(drivers));
     return drivers;
 };
Esempio n. 2
0
//
// ## CommandLoader `CommandLoader(obj)`
//
// Creates a new instance of CommandLoader with the following options:
//  * root - The location of Command modules in the filesystem, represented as a
//    String. Defaults to a sibling 'commands' folder.
//  * strict - If true, CommandLoader will emit 'error' events if its run with a
//    primary argument that doesn't exist as a command. Otherwise, that argument
//    will be included in the fallback command's arguments. Defaults to `true`.
//  * usage - If `--help` or `-h` are passed as options, this command will be
//    used to generate a usage summary. Defaults to 'help'.
//  * fallback - If an unknown command is specified while running, this command
//    is used instead. Defaults to the same as `usage`.
//  * default - The command to run when no command is specified in argv.
//    Defaults to the same as `usage`.
//  * manuals - If set, this location will be used as a repository of named
//    manual files by loadManual()
//
// Commands are modules required from `root`. They must have a .run function,
// and a .usage string. Or, if module exports justa a function, that function
// will be used as the .run function, and if .usage is undefined it will be
// loaded by loadManual().
/**
 * 
 * @param obj
 * @returns {CommandLoader}
 * @constructor
 */
function CommandLoader(obj) {
  if (!(this instanceof CommandLoader)) {
    return new CommandLoader(obj);
  }

  obj = obj || {};

  this.root = obj.root || path.resolve(__dirname, 'commands');
  this.strict = true;
  this.usage = obj.usage || 'help';
  this.fallback = obj.fallback || this.usage;
  this.default = obj.default || this.usage;
  this.manuals = obj.manuals || null;

  this.logger = logger;

  this.commands = needs(__dirname, './commands');
}
Esempio n. 3
0
/**
 *
 * @param options
 * @returns {Cli}
 * @constructor
 */
function Cli(options) {
  if (!(this instanceof Cli)) {
    return new Cli(options);
  }

  options = options || {};

  this.root = options.root || path.resolve(__dirname, 'commands');
  this.strict = true;
  this.usage = options.usage || 'help';
  this.fallback = options.fallback || this.usage;
  this.default = options.default || this.usage;
  this.commands = needs(__dirname, './commands');

  this.insight = new Insight({
    trackingProvider: 'yandex',
    trackingCode: '36888775',
    pkg: pkg
  });
}