From 4d930e9c8a51fae8cb7b3084115ab4b8e7c16d71 Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Sat, 11 Mar 2017 12:58:55 +0100 Subject: [PATCH] display documentation link correctly in every case --- __tests__/index.js | 16 +++++++++++++++- src/cli/index.js | 9 ++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/__tests__/index.js b/__tests__/index.js index 09e6dc29ec..52d9ae8de6 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -207,7 +207,7 @@ test.concurrent('should interpolate aliases', async () => { ); }); -test.concurrent('should display correct documentation for aliases', async () => { +test.concurrent('should display correct documentation link for aliases', async () => { await expectAnInfoMessageAfterError( execCommand('i', [], 'run-add', true), 'Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.', @@ -254,3 +254,17 @@ test.concurrent('should throws missing command for unknown command', async () => 'Command \"unknown\" not found', ); }); + +test.concurrent('should not display documentation link for unknown command', async () => { + await expectAnInfoMessageAfterError( + execCommand('unknown', [], 'run-add', true), + '', + ); +}); + +test.concurrent('should display documentation link for known command', async () => { + await expectAnInfoMessageAfterError( + execCommand('add', [], 'run-add', true), + 'Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.', + ); +}); diff --git a/src/cli/index.js b/src/cli/index.js index e41117611e..a72cfd566a 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -384,11 +384,10 @@ config.init({ onUnexpectedError(err); } - if (commandName) { - const actualCommandForHelp = aliases[commandName] ? aliases[commandName] : commandName; - if (command && actualCommandForHelp) { - reporter.info(getDocsInfo(actualCommandForHelp)); - } + if (aliases[commandName]) { + reporter.info(getDocsInfo(aliases[commandName])); + } else if (commands[commandName]) { + reporter.info(getDocsInfo(commandName)); } process.exit(1);