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

Commit a849d2f

Browse files
vasco-santosdaviddias
authored andcommitted
fix: Display error when using unkown cli option
1 parent e189b72 commit a849d2f

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/cli/bin.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ updateNotifier({
1414
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
1515
}).notify()
1616

17+
const args = process.argv.slice(2)
18+
1719
const cli = yargs
1820
.option('silent', {
1921
desc: 'Write no output',
@@ -32,6 +34,11 @@ const cli = yargs
3234
if (err) {
3335
throw err // preserve stack
3436
}
37+
38+
if (args.length > 0) {
39+
print(msg)
40+
}
41+
3542
yargs.showHelp()
3643
})
3744

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

49-
const args = process.argv.slice(2)
50-
5156
// Need to skip to avoid locking as these commands
5257
// don't require a daemon
5358
if (args[0] === 'daemon' || args[0] === 'init') {
5459
cli
5560
.help()
56-
.strict(false)
61+
.strict()
5762
.completion()
5863
.parse(args)
5964
} else {
@@ -69,7 +74,7 @@ if (args[0] === 'daemon' || args[0] === 'init') {
6974

7075
cli
7176
.help()
72-
.strict(false)
77+
.strict()
7378
.completion()
7479
.parse(args, { ipfs: ipfs }, (err, argv, output) => {
7580
if (output) { print(output) }

src/cli/commands/files/cat.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict'
22

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

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

88
builder: {},
99

1010
handler (argv) {
11-
let path = argv['ipfs-path']
11+
let path = argv['ipfsPath']
1212
if (path.indexOf('/ipfs/') !== 1) {
1313
path = path.replace('/ipfs/', '')
1414
}

src/cli/commands/files/get.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function fileHandler (dir) {
4545
}
4646

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

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

@@ -58,7 +58,8 @@ module.exports = {
5858
},
5959

6060
handler (argv) {
61-
const ipfsPath = argv['ipfs-path']
61+
const ipfsPath = argv['ipfsPath']
62+
6263
const dir = checkArgs(ipfsPath, argv.output)
6364

6465
const stream = argv.ipfs.files.getReadableStream(ipfsPath)

test/cli/general.js

+8
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ describe('general cli options', () => runOnAndOff.off((thing) => {
1010
expect(out).to.be.empty()
1111
})
1212
})
13+
14+
it('should handle unknown arguments correctly', () => {
15+
return thing.ipfs('random --again').then((out) => {
16+
expect(out).to.include('Unknown arguments: again, random')
17+
expect(out).to.include('random')
18+
expect(out).to.include('again')
19+
})
20+
})
1321
}))

0 commit comments

Comments
 (0)