shell: expose promises variant
This commit is contained in:
22
src/shell.js
22
src/shell.js
@@ -1,18 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
spawn,
|
||||
exec,
|
||||
sudo
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
const assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
child_process = require('child_process'),
|
||||
debug = require('debug')('box:shell'),
|
||||
once = require('once'),
|
||||
util = require('util');
|
||||
|
||||
exports = module.exports = {
|
||||
spawn,
|
||||
exec,
|
||||
sudo,
|
||||
|
||||
promises: {
|
||||
exec: util.promisify(exec),
|
||||
spawn: util.promisify(spawn),
|
||||
sudo: util.promisify(sudo)
|
||||
}
|
||||
};
|
||||
|
||||
const SUDO = '/usr/bin/sudo';
|
||||
|
||||
function exec(tag, cmd, callback) {
|
||||
@@ -88,7 +94,7 @@ function sudo(tag, args, options, callback) {
|
||||
if (options.preserveEnv) sudoArgs.push('-E'); // -E preserves environment
|
||||
if (options.ipc) sudoArgs.push('--close-from=4'); // keep the ipc open. requires closefrom_override in sudoers file
|
||||
|
||||
var cp = spawn(tag, SUDO, sudoArgs.concat(args), options, callback);
|
||||
const cp = spawn(tag, SUDO, sudoArgs.concat(args), options, callback);
|
||||
cp.stdin.end();
|
||||
return cp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user