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

fix: Display error when using unkown cli option #1301

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