mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 19:09:16 +00:00
add shell command
This commit is contained in:
parent
905a63fd20
commit
1387d80e10
10
lib/command/index.js
Normal file
10
lib/command/index.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var typesHash = {
|
||||
'shell': require('./shell').ShellCommand
|
||||
};
|
||||
|
||||
exports.createCommand = function(params) {
|
||||
var Constructor = typesHash[params.type];
|
||||
return new Constructor(params);
|
||||
};
|
25
lib/command/shell.js
Normal file
25
lib/command/shell.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var ParentCommand = require('./spawn').SpawnCommand,
|
||||
inherits = require('util').inherits;
|
||||
|
||||
function Command(params) {
|
||||
ParentCommand.call(this, params);
|
||||
}
|
||||
|
||||
exports.ShellCommand = Command;
|
||||
|
||||
inherits(Command, ParentCommand);
|
||||
|
||||
|
||||
/**
|
||||
* Executes `params.cmd` (e.g. 'echo 1 && echo 2') in `params.shell`
|
||||
* (e.g. '/bin/sh') with `params.options`
|
||||
*/
|
||||
Command.prototype.run = function(params, callback) {
|
||||
if (!params.shell) return callback(new Error('`shell` is not set'));
|
||||
if (!params.cmd) return callback(new Error('`cmd` is not set'));
|
||||
ParentCommand.prototype.exec.call(this, {
|
||||
cmd: params.shell, args: ['-c', params.cmd], options: params.options
|
||||
}, callback);
|
||||
};
|
15
lib/utils.js
Normal file
15
lib/utils.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
['Function', 'String', 'Number', 'Date', 'RegExp'].forEach(function(name) {
|
||||
exports['is' + name] = function(obj) {
|
||||
return toString.call(obj) == '[object ' + name + ']';
|
||||
};
|
||||
});
|
||||
|
||||
exports.isObject = function(obj) {
|
||||
return obj === Object(obj);
|
||||
};
|
||||
|
||||
exports.noop = function() {};
|
||||
|
||||
exports.slice = Array.prototype.slice;
|
Loading…
Reference in New Issue
Block a user