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

Commit

Permalink
fix: error when no command specified (#3145)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Jul 7, 2020
1 parent ab3127f commit 4309e10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ipfs/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs/src/cli/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions packages/ipfs/test/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 4309e10

Please sign in to comment.