Skip to content

Commit

Permalink
display documentation link correctly in every case
Browse files Browse the repository at this point in the history
  • Loading branch information
voxsim committed Apr 7, 2017
1 parent 5ce0d22 commit b231c80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 15 additions & 1 deletion __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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.',
);
});
11 changes: 6 additions & 5 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,12 @@ 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]));
}

if (commands[commandName]) {
reporter.info(getDocsInfo(commandName));
}

process.exit(1);
Expand Down

0 comments on commit b231c80

Please sign in to comment.