(name, implementation, wrapOptions)
| 511 | |
| 512 | // Register a new ShellJS command |
| 513 | function _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 | } |
| 545 | exports.register = _register; |
nothing calls this directly
no test coverage detected
searching dependent graphs…