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

Function getSuggestion

tests/command.showSuggestionAfterError.test.js:5–21  ·  view source on GitHub ↗
(program, arg)

Source from the content-addressed store, hash-verified

3import assert from 'node:assert/strict';
4
5function getSuggestion(program, arg) {
6 let message = '';
7 program.exitOverride().configureOutput({
8 writeErr: (str) => {
9 message = str;
10 },
11 });
12
13 try {
14 program.parse([arg], { from: 'user' });
15 } catch (err) {
16 /* empty */
17 }
18
19 const match = message.match(/Did you mean (one of )?(.*)\?/);
20 return match ? match[2] : null;
21}
22describe('Command.showSuggestionAfterError()', () => {
23 test('when unknown command and showSuggestionAfterError() then show suggestion', () => {
24 const program = new Command();

Calls 3

configureOutputMethod · 0.80
exitOverrideMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected