Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

fix: error when command is unknown #2916

Merged
merged 1 commit into from
Mar 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ipfs/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ module.exports = (command, ctxMiddleware) => {
.fail((msg, err, yargs) => {
// Handle yargs errors
if (msg) {
// if the error was caused by an unknown command, the use of `.parse(command)`
// below causes printing help to fail: https://github.com/yargs/yargs/issues/1419#issuecomment-527234789
// so pass the unadulterated parser in as `yargs` in order to print help successfully
if (msg.includes('Unknown argument')) {
yargs = parser
}

return reject(errCode(new Error(msg), 'ERR_YARGS', { yargs }))
}

Expand Down
9 changes: 9 additions & 0 deletions packages/ipfs/test/cli/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,13 @@ describe('daemon', () => {
}
})
})

it('should print help when command is unknown', async function () {
this.timeout(100 * 1000)

const err = await ipfs.fail('derp')

expect(err.stderr).to.include('Commands:')
expect(err.stderr).to.include('Unknown argument: derp')
})
})