(program, arg)
| 6 | // and looking for possible subcommand 'sub'. |
| 7 | |
| 8 | function 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 | |
| 34 | describe('Command.showSuggestionAfterError()', () => { |
| 35 | describe('command suggestions', () => { |
no test coverage detected