/*
Creates a gcli exec function that wraps a 'callback' function contributed by
an 'orion.shell.type' service implementation.
513154
function contributedFunc(service) {
		if (typeof(service) !== "function") { //$NON-NLS-0$
			return undefined;
		}
		return function(args, typeSpec, context) {
			var promise = new Deferred();
			if (context) {
				/* invoking parse() */
				context.cwd = getCWD();
			}
			service(args, typeSpec, context).then(
				function(result) {
					promise.resolve(result);
				},
				function(error) {
					promise.reject(error);
				}
			);
			return promise;
		};
	}
1164520
function exec (func, context, args) {
	switch (args.length) {
		case 0: func.call(context); break;
		case 1: func.call(context, args[0]); break;
		case 2: func.call(context, args[0], args[1]); break;
		case 3: func.call(context, args[0], args[1], args[2]); break;
		case 4: func.call(context, args[0], args[1], args[2], args[3]); break;
		default: func.apply(context, args); break;
	}
}
1107346
function makeCallback(callback) {
  if (_.isFunction(callback)) {
    return callback;
  }
  var result = function() { return callback; };
  result._callback = callback;
  return result;
}
369618
function exec (cmd) {

        var deferred = Q.defer();

        faithfulExec(cmd)
            .then(function (result) {
                deferred.resolve(result);
            }, function (result) {
                deferred.reject(result);
            });

        return deferred.promise;

    }
138128
function(callback) {
    const contentStream = new stream.Writable();
    const data = [];

    contentStream._write = function(chunk) {
      callback(null, chunk.toString());
    };


    // here we can add the options in the future:
    // (options, context, gitRawCommitsOpts, parserOpts, writerOpts);
    const options = {
      preset: program.changelogpreset,
      releaseCount: program.releasecount,
    };
    changelog(options)
    // Use through() to handle multiple chunks which could be returned from changelog()
        .pipe(through({
          objectMode: true,
        }, function(chunk, enc, cb) {
          try {
            data.push(chunk);
          } catch (err) {
            setImmediate(function() {
              throw err;
            });
          }

          cb();
        }, function(cb) {
        // This function is called once ALL the object-chunks have been processed.
          data.push(null);

          cb(null, data.join('')); // Pass the data to the next stream processor
        }))
        .pipe(contentStream);
  }
1209006
function exec (opts, cb) {
    var file, ctx;
    if (typeof opts === 'string') {
        file = opts;
        ctx = null;
        opts = {};
    } else {
        ctx = opts.ctx || null;
        file = opts.file;
    }

    // caching
    var ctxHash = ctx ? md5(ctx) : '';
    if (!opts.force && exec.cache[file] && exec.cache[file][ctxHash]) {
        process.nextTick(function () {
            cb(null, exec.cache[file][ctxHash]);
        });
        return;
    }

    load({file: file, force: opts.forceLoad}, function (err, content) {
        if (err) {
            cb(err);
            return;
        }

        var module = _assign({
            Vow     : VOW,
            console : console,
            require : require
        }, ctx);

        try {
            VM.runInNewContext(content, module, file + '.vm');
        } catch (e) {
            cb(e);
            return;
        }

        // caching
        exec.cache[file] = exec.cache[file] || {};
        exec.cache[file][ctxHash] = module;

        cb(null, module);
    });
}
1079110
function (type, args, callback) {

                var result = function (result) {
                    return {result: result, type: type, args: args};
                };

                var error = function (error) {
                    //$log.error("$riffle error", {type: type, arguments: args, error: error});
                    return $q.reject({error: error, type: type, args: args});
                };

                // Only execute the action callback once we have an established session
                var action = sessionPromise.then(function () {
                    return callback();
                });

                var chain = [result, error];

                // Apply interceptors
                angular.forEach(reversedInterceptors, function (interceptor) {
                    if (interceptor[type + 'Response'] || interceptor[type + 'ResponseError']) {
                        chain.push(interceptor[type + 'Response'], interceptor[type + 'ResponseError']);
                    }
                });

                // We only want to return the actually result or error, not the entire information object
                chain.push(
                    function (response) {
                        return response.result;
                    }, function (response) {
                        return $q.reject(response.error);
                    }
                );

                while (chain.length) {
                    var resolved = chain.shift();
                    var rejected = chain.shift();

                    action = action.then(resolved, rejected);
                }

                return action;
            }
223163
function(params, callback) {
      var t = this;
      if (params === '.break' && t.shellCmd) {
        t.shellCmd.kill();
      }
      if (NEW_REPL) {
        t.stream.emit('data', params + "\n");
      } else {
        t.stream.emit('data', params);
      }
      return callback(null);
    }
567746
function execCmd(c, gcr) {
	return shell.exec(gcr ? c.replace(regexGitCmd, gcr) : c, {
		silent : true
	});
}
993413
function execProcess(command, options, onClose) {
    const procStart = process.hrtime(),
          cmd = command.join(' '),
          opts = options || {};

    childProcess.exec(cmd, opts, (error, stdout, stderr) => {
        const procEnd = process.hrtime(procStart),
              end = (procEnd[0] + procEnd[1] / 1e9).toFixed(2);

        logger.debug('Process output: %s', stdout);
        if (error) {
            logger.error('Process error: %s', stderr);
        }
        logger.debug('Execution time: %d sec', end);

        if (onClose) {
            onClose(error);
        }
    });
}
993173
function run(cmd) {
        return function (callback, options) {
            grunt.verbose.or.ok("Executing " + cmd);
            exec(cmd, options || {}, function (error, stdout, stderr) {
                if (error) {
                    grunt.fatal("'" + cmd + "' failed with :" + stderr);
                } else {
                    grunt.verbose.writeln("Result of " + cmd + ':\n' + stdout);
                    callback();
                }
            });
        };
    }
810362
function (source, opts, cb) {
        var callback,
            options;

        if (arguments.length === 2) {
            options = defaults();
            callback = opts;
        } else {
            options = defaults(opts);
            callback = cb;
        }

        try {
            source = api.clean(source);
            callback(null, api.insert(source, getToc(source, options)));
        } catch (err) {
            callback(err, null);
        }
    }
1007192
function(C) {
        if (!ES.IsCallable(C)) {
          throw new TypeError('bad promise constructor');
        }
        var capability = this;
        var resolver = function(resolve, reject) {
          capability.resolve = resolve;
          capability.reject = reject;
        };
        capability.promise = ES.Construct(C, [resolver]);
        // see https://bugs.ecmascript.org/show_bug.cgi?id=2478
        if (!capability.promise._es6construct) {
          throw new TypeError('bad promise constructor');
        }
        if (!(ES.IsCallable(capability.resolve) &&
              ES.IsCallable(capability.reject))) {
          throw new TypeError('bad promise constructor');
        }
      }
1003104
function(a,b,c,d,e,f,g,h) {
            //console.log("running callback function", a, that, moduleId);
            // store the value
            that.execValues[moduleId] = {
               output: [a,b,c,d,e,f,g,h]
            };
            
            that.executeModules(moduleId, "output");
         }
1292808
function execAsCallback(genFn) {
  const args = Array.prototype.slice.call(arguments, 1);
  const callback = args.pop();
  if (typeof callback !== 'function') {
    throw new TypeError(`the last argument must be a callback function`);
  }
  return genFnToPromise(genFn).apply(this, args).then(ret => callback(null, ret)).catch(callback);
}
756721
function exec(cmd, args, stdin, callback) {
            var stdout = concat();
            var stderr = concat();

            var process = child_process.spawn(cmd, args, {
                stdio: [stdin || 'ignore', 'pipe', 'pipe']
            });
            process.stdout.pipe(stdout);
            process.stderr.pipe(stderr);
            process.on('exit', function(code, signal) {
              var err;
              if (code) {
                err = new Error(code);
                err.code = code;
                err.signal = signal;
              }
              callback(err, stdout, stderr);
            });
            process.on('error', function (err) {
              callback(err, stdout, stderr);
            });
        }
109288
function run(exec, args, shell, callback) {
    var env = extend({}, this.env)
    env.TERM = 'dumb'
    const opts = { env: env, shell: shell }

    this.log.silly('execFile: exec = %j', exec)
    this.log.silly('execFile: args = %j', args)
    this.log.silly('execFile: opts = %j', opts)
    try {
      this.execFile(exec, args, opts, execFileCallback.bind(this))
    } catch (err) {
      this.log.silly('execFile: threw:\n%s', err.stack)
      return callback(err)
    }

    function execFileCallback(err, stdout, stderr) {
      this.log.silly('execFile result: err = %j', err && err.stack || err)
      this.log.silly('execFile result: stdout = %j', stdout)
      this.log.silly('execFile result: stderr = %j', stderr)
      if (err) {
        return callback(err)
      }
      const execPath = stdout.trim()
      callback(null, execPath)
    }
  }