diff --git a/packages/ipfs/src/cli/index.js b/packages/ipfs/src/cli/index.js index 708eda1d0f..cc5421515e 100644 --- a/packages/ipfs/src/cli/index.js +++ b/packages/ipfs/src/cli/index.js @@ -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 })) } diff --git a/packages/ipfs/test/cli/daemon.js b/packages/ipfs/test/cli/daemon.js index fb6720f748..6ff510b179 100644 --- a/packages/ipfs/test/cli/daemon.js +++ b/packages/ipfs/test/cli/daemon.js @@ -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') + }) })