mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-25 16:07:37 +00:00
feat: add overWrite option for commands (#503)
* feat: add overWrite option for commands * fix: throws an error if a command is overwritten
This commit is contained in:
parent
2395214fee
commit
902f92ab5b
@ -372,6 +372,7 @@ var DEFAULT_WRAP_OPTIONS = {
|
||||
pipeOnly: false,
|
||||
unix: true,
|
||||
wrapOutput: true,
|
||||
overWrite: false,
|
||||
};
|
||||
|
||||
// Register a new ShellJS command
|
||||
@ -379,6 +380,11 @@ function _register(name, implementation, wrapOptions) {
|
||||
wrapOptions = wrapOptions || {};
|
||||
// If an option isn't specified, use the default
|
||||
wrapOptions = objectAssign({}, DEFAULT_WRAP_OPTIONS, wrapOptions);
|
||||
|
||||
if (shell[name] && !wrapOptions.overWrite) {
|
||||
throw new Error('unable to overwrite `' + name + '` command');
|
||||
}
|
||||
|
||||
if (wrapOptions.pipeOnly) {
|
||||
wrapOptions.canReceivePipe = true;
|
||||
shellMethods[name] = wrap(name, implementation, wrapOptions);
|
||||
|
||||
@ -96,4 +96,11 @@ assert.equal(ret.stdout, '');
|
||||
assert.equal(ret.stderr, 'foo: Exited with code 5');
|
||||
assert.equal(shell.error(), 'foo: Exited with code 5');
|
||||
|
||||
// Cannot overwrite an existing command by default
|
||||
var oldCat = shell.cat;
|
||||
assert.throws(function () {
|
||||
plugin.register('cat', fooImplementation);
|
||||
}, 'Error: unable to overwrite `cat` command');
|
||||
assert.equal(shell.cat, oldCat);
|
||||
|
||||
shell.exit(123);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user