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

Method unknownOption

lib/command.js:2126–2149  ·  view source on GitHub ↗

* Unknown option `flag`. * * @param {string} flag * @private

(flag)

Source from the content-addressed store, hash-verified

2124 */
2125
2126 unknownOption(flag) {
2127 if (this._allowUnknownOption) return;
2128 let suggestion = '';
2129
2130 if (flag.startsWith('--') && this._showSuggestionAfterError) {
2131 // Looping to pick up the global options too
2132 let candidateFlags = [];
2133 // eslint-disable-next-line @typescript-eslint/no-this-alias
2134 let command = this;
2135 do {
2136 const moreFlags = command
2137 .createHelp()
2138 .visibleOptions(command)
2139 .filter((option) => option.long)
2140 .map((option) => option.long);
2141 candidateFlags = candidateFlags.concat(moreFlags);
2142 command = command.parent;
2143 } while (command && !command._enablePositionalOptions);
2144 suggestion = suggestSimilar(flag, candidateFlags);
2145 }
2146
2147 const message = `error: unknown option '${flag}'${suggestion}`;
2148 this.error(message, { code: 'commander.unknownOption' });
2149 }
2150
2151 /**
2152 * Excess arguments, more than expected.

Callers 1

Calls 4

errorMethod · 0.95
suggestSimilarFunction · 0.90
visibleOptionsMethod · 0.80
createHelpMethod · 0.45

Tested by

no test coverage detected