Example #1
0
function pexec (str, opts) {
  opts = opts || {};
  var p = spawn(parse(str).shift(), parse(str).slice(1), {
    cwd: opts.cwd,
  });
  var prom = new Promise(function (resolve, reject) {
    if (opts.silent !== true) {
      p.stdout.pipe(process.stderr);
      p.stderr.pipe(process.stderr);
    }
    p.on('exit', function (code) {
      code ? reject(code) : resolve();
    });
    p.on('error', function (err) {
      console.error(err);
      throw err;
    });
  })
  prom.stdout = p.stdout;
  prom.stdin = p.stdin;
  prom.stderr = p.stderr;
  prom.pipe = function (B) {
    p.stdout.pipe(B.stdin);
    return B;
  }
  return prom;
}
Example #2
0
File: v.js Project: blowery/volo
 shell: function (cmd, options) {
     return Array.isArray(cmd) ?
            instance.env.sequence(cmd, options) :
            instance.env.spawn.apply(instance.env,
                                     shellQuote.parse(cmd)
                                               .concat(options));
 },
Example #3
0
//  try to be safer than using safe_exec_cmd
function safe_exec_cmd(cmd_string, options, cb) {
  var cmd_args = shell_quote.parse(cmd_string);
  var cmd = cmd_args.shift()


  return child_process.execFile(cmd, cmd_args, options, cb);
}
Example #4
0
test('is undefined', async (t) => {
  const command = parse("NODE_ENV is undefined then 'exit 0' else 'exit 1'");
  const opts = { ...options };

  t.true((await result(npmIf(command, opts))) === 0);
  t.true((await result(npmUnless(command, opts))) === 1);
});
Example #5
0
test('is not', async (t) => {
  const command = parse("NODE_ENV isnt production then 'exit 0' else 'exit 1'");
  const opts = { ...options, env: { NODE_ENV: 'production' } };

  t.true((await result(npmIf(command, opts))) === 1);
  t.true((await result(npmUnless(command, opts))) === 0);
});
Example #6
0
 parseRequest(req, compiler) {
     let source, options, backendOptions, filters;
     // IF YOU MODIFY ANYTHING HERE PLEASE UPDATE THE DOCUMENTATION!
     if (req.is('json')) {
         // JSON-style request
         const requestOptions = req.body.options;
         source = req.body.source;
         options = requestOptions.userArguments;
         backendOptions = requestOptions.compilerOptions;
         filters = requestOptions.filters || compiler.getDefaultFilters();
     } else {
         // API-style
         source = req.body;
         options = req.query.options;
         // By default we get the default filters.
         filters = compiler.getDefaultFilters();
         // If specified exactly, we'll take that with ?filters=a,b,c
         if (req.query.filters) {
             filters = _.object(_.map(req.query.filters.split(","), filter => [filter, true]));
         }
         // Add a filter. ?addFilters=binary
         _.each((req.query.addFilters || "").split(","), filter => {
             if (filter) filters[filter] = true;
         });
         // Remove a filter. ?removeFilter=intel
         _.each((req.query.removeFilters || "").split(","), filter => {
             if (filter) delete filters[filter];
         });
     }
     options = _.chain(quote.parse(options || '')
         .map(x => typeof(x) === "string" ? x : x.pattern))
         .compact()
         .value();
     return {source, options, backendOptions, filters};
 }
Example #7
0
function run(cmd, opts) {
    opts = _.merge({
        pipe: true,
        cwd: undefined,
        callback: function(child) {
            // Since we return promise, we need to provide
            // this callback if one wants to access the child
            // process reference
            // Called immediately after successful child process
            // spawn
        }
    }, opts);

    var child;
    var parts = shellQuote.parse(cmd);
    try {
        child = childProcess.spawn(_.head(parts), _.tail(parts), {
            cwd: opts.cwd,
            stdio: opts.pipe ? "inherit" : null
        });
    } catch (e) {
        return Promise.reject(e);
    }
    opts.callback(child);

    return new Promise(function(resolve, reject) {
        child.on('error', function(err) {
            reject(err);
        });

        child.on('close', function(exitCode) {
            resolve(exitCode);
        });
    });
}
Example #8
0
// Split a command string into it's base components for strong-service-upstart
// command './bin/myapp.js --flag --two 2'
//  -> execPath: '/path/to/node'
//  -> script: ['/path/to/bin/myapp.js', '--flag', '--two', '2']
// command 'global-cmd sub-cmd --flag --two 2'
//  -> execPath: '/path/to/global-cmd' (resolved from $PATH)
//  -> script: ['sub-cmd', '--flag', '--two', '2']
function resolveCommand(opts, next) {

  // If opts.command is given by CLI it is most certainly a string
  if (!Array.isArray(opts.command)) {
    opts.command = shell.parse(opts.command);
  }

  which(opts.command[0], function(err, fromPath) {
    if (err)
      return maybeLocal();
    if (!opts.execPath) {
      // exec + script = command
      opts.execPath = fromPath;
      opts.script = opts.command.slice(1);
    }
    return next();
  });

  function maybeLocal() {
    var local = path.resolve(opts.command[0]);
    fs.exists(local, function(exists) {
      if (exists) {
        // exec + script = node + expanded path + args
        opts.execPath = opts.execPath || process.execPath;
        opts.script = [local].concat(opts.command.slice(1));
      } else {
        return next(new Error('Could not resolve command:', opts.command));
      }
    });
  }
}
Example #9
0
function launchPhpScriptWithXDebugEnabled(
  scriptPath: string,
  sendToOutputWindowAndResolve?: (text: string) => void,
): child_process$ChildProcess {
  const scriptArgv = parse(scriptPath);
  const args = ['-c', 'xdebug.ini', ...scriptArgv];
  const {hhvmBinaryPath} = getConfig();
  const proc = child_process.spawn(hhvmBinaryPath, args);
  logger.log(`child_process(${proc.pid}) spawned with xdebug enabled for: ${scriptPath}`);

  proc.stdout.on('data', chunk => {
    // stdout should hopefully be set to line-buffering, in which case the
    // string would come on one line.
    const block: string = chunk.toString();
    const output = `child_process(${proc.pid}) stdout: ${block}`;
    logger.log(output);
  });
  proc.on('error', err => {
    logger.log(`child_process(${proc.pid}) error: ${err}`);
    if (sendToOutputWindowAndResolve != null) {
      sendToOutputWindowAndResolve(
        `The process running script: ${scriptPath} encountered an error: ${err}`
      );
    }
  });
  proc.on('exit', code => {
    logger.log(`child_process(${proc.pid}) exit: ${code}`);
    if (sendToOutputWindowAndResolve != null) {
      sendToOutputWindowAndResolve(`Script: ${scriptPath} exited with code: ${code}`);
    }
  });
  return proc;
}
Example #10
0
 (function next () {
     if (before.length === 0) return runServers(start);
     
     var cmd = before.shift();
     if (!Array.isArray(cmd)) cmd = parseQuote(cmd);
     var ps = spawn(cmd[0], cmd.slice(1), { env: env, cwd: commit.dir });
     Object.keys(streams).forEach(function (key) {
         ps.stdout.pipe(streams[key], { end: false });
         ps.stderr.pipe(streams[key], { end: false });
     });
     procs.emit('spawn', ps, { command: cmd, commit: commit });
     
     var to = setTimeout(function () {
         ps.removeListener('exit', onexit);
         procs.emit('error', 'install took too long, aborting');
     }, 5 * 60 * 1000);
     
     ps.on('exit', onexit);
     function onexit (code) {
         clearTimeout(to);
         if (code !== 0) {
             procs.emit('error', 'non-zero exit code ' + code
                 + ' from command: ' + cmd.join(' ')
             );
         }
         else next()
     }
 })();
Example #11
0
 function runCommands (key, cmd, env, evName) {
     var host = hosts[key];
     if (!Array.isArray(cmd)) cmd = parseQuote(cmd);
     
     var ps = spawn(cmd[0], cmd.slice(1), { env: env, cwd: commit.dir });
     ps.port = env.PORT;
     ps.key = key;
     ps.host = host;
     
     ps.on('exit', function (code) {
         procs.emit('exit', host, ps);
     });
     
     ps.stdout.pipe(streams[key], { end: false });
     ps.stderr.pipe(streams[key], { end: false });
     ps.respawn = function () {
         runCommands(key, cmd, env, 'restart');
     };
     procs.emit('spawn', ps, {
         command: cmd,
         commit: commit,
         key: key,
         host: host
     });
     procs.emit(evName || 'start', host, ps);
 }
Example #12
0
var run = function (cmdString, action, logger, config) {
    logger.action(action, cmdString);

    //pass env + BOWER_PID so callees can identify a preinstall+postinstall from the same bower instance
    var env = mout.object.mixIn({ 'BOWER_PID': process.pid }, process.env);
    var args = shellquote.parse(cmdString, env);
    var cmdName = args[0];
    mout.array.remove(args, cmdName); //no rest() in mout

    var options = {
        cwd: config.cwd,
        env: env
    };

    var promise = cmd(cmdName, args, options);

    promise.progress(function (progress) {
        progress.split('\n').forEach(function (line) {
            if (line) {
                logger.action(action, line);
            }
        });
    });

    return promise;
};
Example #13
0
 (function next () {
     if (before.length === 0) return runServers(start);
     
     var cmd = before.shift();
     if (!Array.isArray(cmd)) cmd = parseQuote(cmd);
     var ps = spawn(cmd[0], cmd.slice(1), { env: env, cwd: commit.dir });
     ps.stdout.pipe(process.stdout, { end: false });
     ps.stderr.pipe(process.stderr, { end: false });
     
     var to = setTimeout(function () {
         ps.removeListener('exit', onexit);
         cb('install took too long, aborting');
     }, 5 * 60 * 1000);
     
     ps.on('exit', onexit);
     function onexit (code) {
         clearTimeout(to);
         if (code !== 0) {
             cb('non-zero exit code ' + code
                 + ' from command: ' + cmd.join(' ')
             );
         }
         else next()
     }
 })();
Example #14
0
function launchPhpScriptWithXDebugEnabled(
  scriptPath: string,
  sendToOutputWindowAndResolve?: (text: string) => void,
): child_process$ChildProcess {
  const child_process = require('child_process');
  const scriptArgv = parse(scriptPath);
  const args = ['-c', 'xdebug.ini', ...scriptArgv];
  // TODO[jeffreytan]: make hhvm path configurable so that it will
  // work for non-FB environment.
  const proc = child_process.spawn('/usr/local/hphpi/bin/hhvm', args);
  logger.log(`child_process(${proc.pid}) spawned with xdebug enabled for: ${scriptPath}`);

  proc.stdout.on('data', chunk => {
    // stdout should hopefully be set to line-buffering, in which case the
    // string would come on one line.
    const block: string = chunk.toString();
    const output = `child_process(${proc.pid}) stdout: ${block}`;
    logger.log(output);
  });
  proc.on('error', err => {
    logger.log(`child_process(${proc.pid}) error: ${err}`);
    if (sendToOutputWindowAndResolve != null) {
      sendToOutputWindowAndResolve(
        `The process running script: ${scriptPath} encountered an error: ${err}`
      );
    }
  });
  proc.on('exit', code => {
    logger.log(`child_process(${proc.pid}) exit: ${code}`);
    if (sendToOutputWindowAndResolve != null) {
      sendToOutputWindowAndResolve(`Script: ${scriptPath} exited with code: ${code}`);
    }
  });
  return proc;
}
Example #15
0
module.exports = exports = function (cmdStr, context, options) {
    var shell = this;

    // Initialize shell helper methods.
    if (context) shellHelpers.updateContext(context);

    var prompt = shell.getVar('prompt');

    // If no command string was supplied then write an error message.
    if (!cmdStr || /^[\s';"\[\]|&()<>]+$/.test(cmdStr))
        return shell.error('You must supply a value.');

    // Parse the command string into an argument array and set the command name to the first item.
    var args = cmdStr,
        cmdName = cmdStr;
    if (cmdStr.length > 0) {
        args = shellQuote.parse(cmdStr);
        cmdName = args[0];
    }

    if (cmdStr.toLowerCase() !== 'cancel') {
        // If a prompt context exists then override command and options with those stored in the context...
        if (prompt) {
            cmdName = prompt.cmd;
            options = prompt.options;
            options[prompt.option] = cmdStr;
            shell.clearPrompt();
        }
        // ...otherwise remove the command name from the args array and build our options object.
        else {
            args.splice(0, 1);
            options = extend({}, optimist(args).argv, options);
        }

        // Get reference to the command module by name.
        var cmd = shell.cmds[cmdName.toLowerCase()];
        // If the command module exists then process it's options and invoke the module.
        if (cmd && cmd.access(shell, cmdName.toLowerCase())) {
            if (options.hasOwnProperty('?') || options.hasOwnProperty('help'))
                shell.execute('help', context, { command: cmdName });
            else if (validateCommandOptions(options, cmd, shell))
                cmd.invoke(shell, options);
        }
        else
            shell.error('"' + cmdName + '" is not a valid command');
    }
    else {
        // If prompt exists then cancel it...
        if (prompt){
            shell.warn('prompt canceled');
            shell.clearPrompt();
        }
        // ...otherwise inform user there is no active prompt.
        else
            shell.error('there are no active prompts');

    }

    return shell;
};
Example #16
0
function guessEditor() {
  // Explicit config always wins
  if (process.env.REACT_EDITOR) {
    return shellQuote.parse(process.env.REACT_EDITOR);
  }

  // Using `ps x` on OSX we can find out which editor is currently running.
  // Potentially we could use similar technique for Windows and Linux
  if (process.platform === 'darwin') {
    try {
      var output = child_process.execSync('ps x').toString();
      var processNames = Object.keys(COMMON_EDITORS);
      for (var i = 0; i < processNames.length; i++) {
        var processName = processNames[i];
        if (output.indexOf(processName) !== -1) {
          return [COMMON_EDITORS[processName]];
        }
      }
    } catch(error) {
      // Ignore...
    }
  }

  // Last resort, use old skool env vars
  if (process.env.VISUAL) {
    return [process.env.VISUAL];
  } else if (process.env.EDITOR) {
    return [process.env.EDITOR];
  }

  return [null];
}
Example #17
0
function parse(line) {

  var env = true;
  var out = {
    envs: {},
    exec: null,
    args: []
  };

  var split = quotes(line);
  split.forEach(function (item) {
    // check for environment varable
    if (env && item[0] != '-' && item.indexOf('=') > 0) {
      var key_arg   = item.split('=');
      var key       = key_arg[0];
      var arg       = key_arg[1];
      return out.envs[key] = arg;
    } else {
      env = false;
    }

    // write exec
    if (!out.exec) {
      return out.exec = item;
    }

    // everything else is an argument
    out.args.push(item);

  });

  return out;

}
function run(cmd, opts) {
    opts = _.merge({
        // If set to a function, it will be called for each line
        // written to the child process's stdout as (line, child)
        onOutputLine: undefined,
    }, opts);

    var child;
    var parts = shellQuote.parse(cmd);
    try {
        child = childProcess.spawn(_.head(parts), _.tail(parts), {
            stdio: DEBUG_TESTS && !opts.onOutputLine ? 'inherit': null,
        });
    } catch (e) {
        return Promise.reject(e);
    }

    if (opts.onOutputLine) {
        readLines(child, opts.onOutputLine);
    }

    return new Promise(function(resolve, reject) {
        child.on('error', function(err) {
            reject(err);
        });

        child.on('close', function(exitCode) {
            resolve(exitCode);
        });
    });
}
Example #19
0
    get_open_port(function(port) {
        if (!Array.isArray(cmd)) {
            cmd = parse_cmd(cmd, { ZUUL_PORT: port });
        }

        if (/\.js$/.test(cmd[0])) {
            cmd.unshift(process.execPath);
        }

        env.ZUUL_PORT = port;

        debug('user server port %d', port);

        var ps = spawn(cmd[0], cmd.slice(1), { cwd: cwd, env: env });
        ps.stdout.pipe(process.stdout);
        ps.stderr.pipe(process.stderr);

        function exit() {
            ps.kill('SIGTERM');
        }

        ps.once('exit', function (code) {
            debug('user server exited with status: %d', code);
            process.removeListener('exit', exit);
        });

        process.on('exit', exit);

        return setTimeout(function(){
            callback({ port: port, process: ps });
        }, wait);
    });
Example #20
0
function _cowsay(command, args, callback) {
    // This command requires arguments.
    if (!args) {
        return callback();
    }

    var argv = parseArgs(shellQuote.parse(args), {
        alias: { h: 'help' },
        boolean: ['b', 'd', 'g', 'p', 's', 't', 'w', 'y', 'h', 'l']
    });

    argv._ = argv._.filter(a => typeof a === 'string');

    if (argv.h) {
        var help = `Usage: /${command} [-e eye_string] [-f cowfile] [-h] [-l] [-T tongue_string] [-bdgpstwy] "text"\n\n`;
        help += 'If any arguments are left over after all switches have been processed, they become the cow′s message.\n\n';
        help += 'If the command is invoked as /cowthink then the cow will think its message instead of saying it.\n\n';
        help += 'Options:\n';
        help += '  -b  "Borg", uses == for the cow′s eyes.\n';
        help += '  -d  "Dead", uses XX, plus a descending U to represent an extruded tongue.\n';
        help += '  -g  "Greedy", uses $$ for the cow′s eyes.\n';
        help += '  -p  "Paranoid", uses @@ for the cow′s eyes.\n';
        help += '  -s  "Stoned", uses ** to represent bloodshot eyes, plus a descending U to represent an extruded tongue.\n';
        help += '  -t  "Tired", uses -- for the cow′s eyes.\n';
        help += '  -w  "Wired", uses OO for the cow′s eyes.\n';
        help += '  -y  "Youthful", uses .. to represent smaller eyes.\n';
        help += '  -e  Manually specifies the cow′s eye-type. [default: "oo"]\n';
        help += '  -T  Manually specifies the cow′s tongue shape. [default: "  "]\n';
        help += '  -h  Display this help message.\n';
        help += '  -f  Specifies a cow picture file ("cowfile") to use. [default: "default"]\n';
        help += '  -l  List all cowfiles available.\n';

        return callback(null, `/${command} ${args}\n~~~\n${help}\n~~~`);
    } else if (argv.l) {
        return cowsay.list(function(err, cows) {
            if (err) {
                return callback();
            }

            callback(null, `/${command} ${args}\n~~~\n${cows.join(' ')}\n~~~`);
        });
    }

    // Don't allow disabling word-wrapping
    delete argv.n;

    // A reply on mobile can only fit 32 characters
    argv.W = 32;

    var result;

    try {
        result = command === 'cowthink' ? cowsay.think(argv) : cowsay.say(argv);
        result = `~~~\n${result}\n~~~`;
    } catch(e) {
        // eslint-disable-line
    }

    callback(null, result);
}
Example #21
0
 }, function(callback) {
   if (task.verify) {
     var verifyArgs = parse(task.verify);
     execCommand(task.name,task.verify, callback);
   } else {
     return callback(null);
   }
 }],function(err, results) {
Example #22
0
function ShellTransform(commandLine) {
    stream.Transform.call(this, {decodeStrings: false});
    this.bufferData = [];
    this.readable = true;
    this.writable = true;
    this.commandLine = commandLine;

    var command = shellQuote.parse(commandLine);
    this.handle = child_process.spawn(command[0], command.slice(1),
                                      {stdio: 'pipe'});
    var that = this;

    // console.warn('cmd', commandLine, args);

    // console.warn(this.handle.exitCode, this.handle.pid);

    this.handle.on('exit', function (code) {
        // console.warn('handle exit');
        that.readable = that.writable = false;
    });

    this.handle.on('error', function (err) {
        // console.warn('handle error');
        that.emit('error', err);
    });
    this.handle.stdin.on('error', function (err) {
        // console.warn('stdin error', err);
        that.readable = that.writable = false;
        that.emit('error', err);
    });

    this.handle.stdout.on('readable', function () {
        var data = that.handle.stdout.read();
        if (data) {
            data = data.toString();
            that.push(data);
        }
    });

    this.handle.stderr.on('readable', function () {
        var data = that.handle.stderr.read();
        if (data) {
            // console.warn('stderr', data.toString());
        }
    });
    this.handle.stdout.on('error', function (err) {
        // console.warn('stdout error', err);
        that.emit('error', err);
    });

    this.handle.stdout.on('close', function () {
        // console.warn('stdout close');
    });
    this.handle.stdout.on('finish', function () {
        // console.warn('stdout finish');
        that.push(null);
    });
}
Example #23
0
  group[1].forEach(function (file) {
    var usedarg = false;
    var spawncmd = parse(exe, process.env).map(function (arg) {
      if (arg == '{}') {
        usedarg = true;
        return file;
      }
      return arg;
    }).concat(usedarg ? [] : [file]);

    var proc = spawn(spawncmd[0], spawncmd.slice(1));
    var tap = proc.stdout.pipe(tinytap.parseStream());

    function prefixStream () {
      var transform = new stream.Transform()
      var buf = '';
      transform._transform = function (chunk, encoding, callback) {
        buf += chunk.toString(encoding == 'buffer' ? null : encoding);
        var pos;
        while ((pos = buf.indexOf('\n')) > -1) {
          this.push(' | ' + buf.slice(0, pos) + '\n');
          buf = buf.slice(pos + 1);
        }
        callback();
      }
      return transform;
    }

    if ('TAP_VERBOSE' in process.env || 'TAPV' in process.env) {
      proc.stdout.pipe(prefixStream()).pipe(process.stderr);
      proc.stderr.pipe(prefixStream()).pipe(process.stderr);
    }

    var exited = false, completed = false, code = -1;
    proc.on('exit', function (_code) {
      code = _code;
      exited = true;
      exited && completed && procComplete();
    })

    tap.on('complete', function () {
      completed = true;
      exited && completed && procComplete();
    });

    function procComplete () {
      console.log(tap.success && code == 0 ? 'ok' : 'not ok', currentttest++, '-', file + (code != 0 ? ' (exit code ' + code + ')' : ''));
      tap.success && code == 0 && testsuccess++;

      if (currentttest == group[1].length) {
        if (groups.length) {
          next(groups.shift());  
        } else {
          finish();
        }
      }
    }
  });
Example #24
0
    dax.adag.job.forEach(function(job) {
        ++nextTaskId;
        var args = parse(job.argument[0]);
        wfOut.tasks.push({
            "name": job['$'].name,
            "function": functionName,
            "type": "dataflow",
            "executor": "syscommand",
            "firingLimit": 1,
            "config": {
                "executor": {
                    "executable": job['$'].name,
                    "args": args
                }
            },
            "ins": [],
            "outs": []
        });

        if (job['$'].runtime) { // synthetic workflow dax
            wfOut.tasks[nextTaskId].runtime = job['$'].runtime;
        }

        //var
        //if (config

        var dataId, dataName;
        job.uses.forEach(function(job_data) {
        if (job_data['$'].name) {
                dataName = job_data['$'].name; // dax v3.3
        } else {
                dataName = job_data['$'].file; // dax v2.1
        }
            if (!dataNames[dataName]) {
                ++nextDataId;
                wfOut.data.push({
                    "name": dataName,
                    "sources": [],
                    "sinks": []
                });
                dataId = nextDataId;
                dataNames[dataName] = dataId;
            } else {
                dataId = dataNames[dataName];
            }
            if (job_data['$'].size) { // synthetic workflow dax
                wfOut.data[dataId].size = job_data['$'].size;
            }
            if (job_data['$'].link == 'input') {
                wfOut.tasks[nextTaskId].ins.push(dataId);
                wfOut.data[dataId].sinks.push(nextTaskId);
            } else {
                wfOut.tasks[nextTaskId].outs.push(dataId);
                wfOut.data[dataId].sources.push(nextTaskId);
            }
        });
    });
Example #25
0
File: cli.js Project: jaz303/spinup
 [/^\!(set|default)\s+(\w+)\s+(.*?)$/, () => {
     const op = RegExp.$1, key = RegExp.$2, parsed = parse(RegExp.$3, config.env);
     if (op === 'default' && (key in config.env)) {
         return;
     }
     if (parsed.length !== 1) {
         throw new Error("value for !" + op + " directive must evaluate to a single value (try quoting with \"\")");
     }
     config.env[key] = parsed[0];
 }],
Example #26
0
            shell: function (cmd, options) {
                options = options || {};

                if (Array.isArray(cmd)) {
                    return instance.env.sequence(cmd, options);
                } else {
                    options._originalCommand = cmd;
                    var parsedArgs = shellQuote.parse(cmd);
                    cmd = parsedArgs.shift();
                    return instance.env.spawn(cmd, parsedArgs, options);
                }
            },
Example #27
0
function Compute (db, opts) {
    if (!(this instanceof Compute)) return new Compute(db, opts);
    if (!opts) opts = {};
    BatchDB.call(this, db, extend({ run: run }, opts));
    
    var sh = defined(opts.shell, process.env.SHELL, defaultShell);
    if (typeof sh === 'string') sh = parseShell(sh);
    
    function run () {
        var ps = spawn(sh[0], sh.slice(1));
        return duplexer(ps.stdin, pack(ps));
    }
};
Example #28
0
function parse(a) {
    if (a.startsWith('"')) {
        a = a.replace(/\\n/g, '\n');
    }
    else if (a.startsWith("'")) {
        a = a.replace(/\\\\/g, '\\');
    }
    let parsed = shell.parse(a);
    if (parsed.length > 1)
        throw new Error(`Invalid token: ${a}`);
    return parsed[0];
    // return parsed[0].replace(/\\\\n/g, '\n')
}
Example #29
0
 function runCommands (key, cmd, env) {
     var host = (key === 'index' ? '' : key + '.') + commit.branch;
     if (!Array.isArray(cmd)) cmd = parseQuote(cmd);
     
     var ps = spawn(cmd[0], cmd.slice(1), { env: env, cwd: commit.dir });
     ps.port = env.PORT;
     ps.key = key;
     ps.host = host;
     
     ps.stdout.pipe(process.stdout, { end: false });
     ps.stderr.pipe(process.stderr, { end: false });
     ps.respawn = function () { runCommands(host, cmd, env) };
     cb(null, ps);
 }
Example #30
0
exports.run = function (defaultArgString) {
	var args = 0;

	var defaultArgs = [];
	if (defaultArgString) {
		defaultArgs = shellParse(defaultArgString);
		console.log("Environment options: " + defaultArgs.join(", "));
	}
	// defaults go first, so they get overriden by manually specified options
	var argv = defaultArgs.concat(process.argv.slice(2));
	
	argv.forEach(function (arg) {
		if (arg[0] !== '-') {
			try {
				argHandlers[args++][1](arg);
			}
			catch (err) {
				usageError();
			}
		}

		else if (arg[1] === '-') {
			var match = FLAG_MATCHER.exec( arg.substr(2) );

			if (match) {
				try {
					flagHandlers[ match[1] ]( match[2] );
				}
				catch (err) {
					usageError();
				}
			}
			else {
				usageError();
			}
		}

		else {
			Array.prototype.slice.call( arg.substr(1) ).forEach(function (flag) {
				try {
					flagHandlers[flag]();
				}
				catch (err) {
					usageError();
				}
			});
		}
	});
};