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

Function getSuggestion

tests/help.suggestion.test.js:8–32  ·  view source on GitHub ↗
(program, arg)

Source from the content-addressed store, hash-verified

6// and looking for possible subcommand 'sub'.
7
8function getSuggestion(program, arg) {
9 let message = '';
10 program
11 .showSuggestionAfterError() // make sure on
12 .exitOverride()
13 .configureOutput({
14 writeErr: (str) => {
15 message = str;
16 },
17 });
18 // Do the same setup for subcommand.
19 const sub = program._findCommand('sub');
20 if (sub) sub.copyInheritedSettings(program);
21
22 try {
23 // Passing in an array for a few of the tests.
24 const args = Array.isArray(arg) ? arg : [arg];
25 program.parse(args, { from: 'user' });
26 } catch (err) {
27 /* empty */
28 }
29
30 const match = message.match(/Did you mean (one of )?(.*)\?/);
31 return match ? match[2] : null;
32}
33
34describe('Command.showSuggestionAfterError()', () => {
35 describe('command suggestions', () => {

Callers 1

Calls 6

configureOutputMethod · 0.80
exitOverrideMethod · 0.80
_findCommandMethod · 0.80
copyInheritedSettingsMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected