Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suggestions for CLI #7808

Merged
merged 1 commit into from Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/fixtures/index/run-suggestion/package.json
@@ -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
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
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