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

Commit

Permalink
fix: Display error when using unkown cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and daviddias committed Apr 8, 2018
1 parent e189b72 commit a849d2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ updateNotifier({
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
}).notify()

const args = process.argv.slice(2)

const cli = yargs
.option('silent', {
desc: 'Write no output',
Expand All @@ -32,6 +34,11 @@ const cli = yargs
if (err) {
throw err // preserve stack
}

if (args.length > 0) {
print(msg)
}

yargs.showHelp()
})

Expand All @@ -46,14 +53,12 @@ aliases.forEach((alias) => {
cli.command(alias.command, alias.describe, alias.builder, alias.handler)
})

const args = process.argv.slice(2)

// Need to skip to avoid locking as these commands
// don't require a daemon
if (args[0] === 'daemon' || args[0] === 'init') {
cli
.help()
.strict(false)
.strict()
.completion()
.parse(args)
} else {
Expand All @@ -69,7 +74,7 @@ if (args[0] === 'daemon' || args[0] === 'init') {

cli
.help()
.strict(false)
.strict()
.completion()
.parse(args, { ipfs: ipfs }, (err, argv, output) => {
if (output) { print(output) }
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/files/cat.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

module.exports = {
command: 'cat <ipfs-path>',
command: 'cat <ipfsPath>',

describe: 'Fetch and cat an IPFS path referencing a file',

builder: {},

handler (argv) {
let path = argv['ipfs-path']
let path = argv['ipfsPath']
if (path.indexOf('/ipfs/') !== 1) {
path = path.replace('/ipfs/', '')
}
Expand Down
5 changes: 3 additions & 2 deletions src/cli/commands/files/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function fileHandler (dir) {
}

module.exports = {
command: 'get <ipfs-path>',
command: 'get <ipfsPath>',

describe: 'Fetch a file or directory with files references from an IPFS Path',

Expand All @@ -58,7 +58,8 @@ module.exports = {
},

handler (argv) {
const ipfsPath = argv['ipfs-path']
const ipfsPath = argv['ipfsPath']

const dir = checkArgs(ipfsPath, argv.output)

const stream = argv.ipfs.files.getReadableStream(ipfsPath)
Expand Down
8 changes: 8 additions & 0 deletions test/cli/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ describe('general cli options', () => runOnAndOff.off((thing) => {
expect(out).to.be.empty()
})
})

it('should handle unknown arguments correctly', () => {
return thing.ipfs('random --again').then((out) => {
expect(out).to.include('Unknown arguments: again, random')
expect(out).to.include('random')
expect(out).to.include('again')
})
})
}))

0 comments on commit a849d2f

Please sign in to comment.