MCPcopy
hub / github.com/tj/commander.js / _registerCommand

Method _registerCommand

lib/command.js:645–663  ·  view source on GitHub ↗

* Check for command name and alias conflicts with existing commands. * Register command if no conflicts found, or throw on conflict. * * @param {Command} command * @private

(command)

Source from the content-addressed store, hash-verified

643 */
644
645 _registerCommand(command) {
646 const knownBy = (cmd) => {
647 return [cmd.name()].concat(cmd.aliases());
648 };
649
650 const alreadyUsed = knownBy(command).find((name) =>
651 this._findCommand(name),
652 );
653 if (alreadyUsed) {
654 const existingCmd = knownBy(this._findCommand(alreadyUsed)).join('|');
655 const newCmd = knownBy(command).join('|');
656 throw new Error(
657 `cannot add command '${newCmd}' as already have command '${existingCmd}'`,
658 );
659 }
660
661 this._initCommandGroup(command);
662 this.commands.push(command);
663 }
664
665 /**
666 * Add an option.

Callers 2

commandMethod · 0.95
addCommandMethod · 0.95

Calls 2

_findCommandMethod · 0.95
_initCommandGroupMethod · 0.95

Tested by

no test coverage detected