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

fix: error when no command specified #3145

Merged
merged 1 commit into from
Jul 7, 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
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')
})
})