From 4309e1004bb77ee276b57228c35a921fb780a227 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 7 Jul 2020 17:46:26 +0100 Subject: [PATCH] fix: error when no command specified (#3145) --- packages/ipfs/src/cli/index.js | 2 +- packages/ipfs/src/cli/parser.js | 2 +- packages/ipfs/test/cli/commands.js | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ipfs/src/cli/index.js b/packages/ipfs/src/cli/index.js index cc5421515e..e795f52460 100644 --- a/packages/ipfs/src/cli/index.js +++ b/packages/ipfs/src/cli/index.js @@ -21,7 +21,7 @@ module.exports = (command, ctxMiddleware) => { // 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')) { + if (msg.includes('Unknown argument') || msg.includes('Please specify a command')) { yargs = parser } diff --git a/packages/ipfs/src/cli/parser.js b/packages/ipfs/src/cli/parser.js index 6d648a181e..d370a07086 100644 --- a/packages/ipfs/src/cli/parser.js +++ b/packages/ipfs/src/cli/parser.js @@ -24,7 +24,7 @@ const parser = yargs default: false }) .epilog(utils.ipfsPathHelp) - .demandCommand(1) + .demandCommand(1, 'Please specify a command') .showHelpOnFail(false) .commandDir('commands') .help() diff --git a/packages/ipfs/test/cli/commands.js b/packages/ipfs/test/cli/commands.js index 48137f9982..8bd80ae3a8 100644 --- a/packages/ipfs/test/cli/commands.js +++ b/packages/ipfs/test/cli/commands.js @@ -11,4 +11,12 @@ describe('commands', () => { const out = await cli('commands') expect(out.split('\n')).to.have.length(commandCount) }) + + it('requires a command', async () => { + await expect(cli('')).to.eventually.be.rejectedWith(/Please specify a command/).and.have.property('code', 'ERR_YARGS') + }) + + it('requires a known command', async () => { + await expect(cli('derp')).to.eventually.be.rejectedWith(/Unknown argument: derp/).and.have.property('code', 'ERR_YARGS') + }) })