File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -372,13 +372,19 @@ var DEFAULT_WRAP_OPTIONS = {
372
372
pipeOnly : false ,
373
373
unix : true ,
374
374
wrapOutput : true ,
375
+ overWrite : false ,
375
376
} ;
376
377
377
378
// Register a new ShellJS command
378
379
function _register ( name , implementation , wrapOptions ) {
379
380
wrapOptions = wrapOptions || { } ;
380
381
// If an option isn't specified, use the default
381
382
wrapOptions = objectAssign ( { } , DEFAULT_WRAP_OPTIONS , wrapOptions ) ;
383
+
384
+ if ( shell [ name ] && ! wrapOptions . overWrite ) {
385
+ throw new Error ( 'unable to overwrite `' + name + '` command' ) ;
386
+ }
387
+
382
388
if ( wrapOptions . pipeOnly ) {
383
389
wrapOptions . canReceivePipe = true ;
384
390
shellMethods [ name ] = wrap ( name , implementation , wrapOptions ) ;
Original file line number Diff line number Diff line change @@ -96,4 +96,11 @@ assert.equal(ret.stdout, '');
96
96
assert . equal ( ret . stderr , 'foo: Exited with code 5' ) ;
97
97
assert . equal ( shell . error ( ) , 'foo: Exited with code 5' ) ;
98
98
99
+ // Cannot overwrite an existing command by default
100
+ var oldCat = shell . cat ;
101
+ assert . throws ( function ( ) {
102
+ plugin . register ( 'cat' , fooImplementation ) ;
103
+ } , 'Error: unable to overwrite `cat` command' ) ;
104
+ assert . equal ( shell . cat , oldCat ) ;
105
+
99
106
shell . exit ( 123 ) ;
You can’t perform that action at this time.
0 commit comments