Skip to content

Commit

Permalink
Fix suggestions for CLI (#7808)
Browse files Browse the repository at this point in the history
At some point the `scripts` object changes to be a map instead of an array, at which point the suggestions functionality broke. This commit includes the fix and a test to make sure it doesn't break again.
  • Loading branch information
Kevin Deisz authored and arcanis committed Jan 22, 2020
1 parent 039bafd commit 2c8e97e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions __tests__/fixtures/index/run-suggestion/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test_suggestion",
"version": "1.0.0",
"license": "UNLICENSED",
"scripts": {
"foobar": "foobar"
}
}
4 changes: 4 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ test.concurrent('should throws missing command for unknown command', async () =>
await expectAnErrorMessage(execCommand('unknown', [], 'run-add', true), 'Command "unknown" not found');
});

test.concurrent('should suggest options for other commands when missing a command', async () => {
await expectAnErrorMessage(execCommand('foobarx', [], 'run-suggestion', true), 'Did you mean "foobar"?');
});

test.concurrent('should not display documentation link for unknown command', async () => {
await expectAnInfoMessageAfterError(execCommand('unknown', [], 'run-add', true), '');
});
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
} else {
let suggestion;

for (const commandName in scripts) {
for (const commandName of scripts.keys()) {
const steps = leven(commandName, action);
if (steps < 2) {
suggestion = commandName;
Expand Down

0 comments on commit 2c8e97e

Please sign in to comment.