/**
 * Execute a command.
 * @function ci.worker.execCommand
 * @param {object} config - Task configuration
 * @param {string} config.command - Command.
 * @param {string} config.cwd - Working directory name.
 * @param {function} callback - Callback when done.
 */
var debug = require('./_debug'),
    childProcess = require('child_process'),
    exec = childProcess.exec;

module.exports = function (config, callback) {
    var command = config.command;
    exec(command, {
        cwd: config.cwd,
        env: process.env
    }, function (err, stdOut, stdErr) {
        if (stdOut && !config.silent) console.log(stdOut);
        debug.didExecute(command);
        callback(err || stdErr || null);
    });
};