MCPcopy
hub / github.com/shelljs/shelljs / _register

Function _register

src/common.js:513–544  ·  view source on GitHub ↗
(name, implementation, wrapOptions)

Source from the content-addressed store, hash-verified

511
512// Register a new ShellJS command
513function _register(name, implementation, wrapOptions) {
514 wrapOptions = wrapOptions || {};
515
516 // Validate options
517 Object.keys(wrapOptions).forEach(function (option) {
518 if (!DEFAULT_WRAP_OPTIONS.hasOwnProperty(option)) {
519 throw new Error("Unknown option '" + option + "'");
520 }
521 if (typeof wrapOptions[option] !== typeof DEFAULT_WRAP_OPTIONS[option]) {
522 throw new TypeError("Unsupported type '" + typeof wrapOptions[option] +
523 "' for option '" + option + "'");
524 }
525 });
526
527 // If an option isn't specified, use the default
528 wrapOptions = Object.assign({}, DEFAULT_WRAP_OPTIONS, wrapOptions);
529
530 if (shell.hasOwnProperty(name)) {
531 throw new Error('Command `' + name + '` already exists');
532 }
533
534 if (wrapOptions.pipeOnly) {
535 wrapOptions.canReceivePipe = true;
536 shellMethods[name] = wrap(name, implementation, wrapOptions);
537 } else {
538 shell[name] = wrap(name, implementation, wrapOptions);
539 }
540
541 if (wrapOptions.canReceivePipe) {
542 pipeMethods.push(name);
543 }
544}
545exports.register = _register;

Callers

nothing calls this directly

Calls 1

wrapFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…