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

Commit e67f6df

Browse files
finish cli refactor
1 parent 99c40bf commit e67f6df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+163
-212
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"promisify-es6": "^1.0.1",
9393
"read-pkg-up": "^1.0.1",
9494
"readable-stream": "1.1.13",
95-
"ronin": "^0.3.11",
9695
"run-parallel": "^1.1.6",
9796
"run-parallel-limit": "^1.0.3",
9897
"run-series": "^1.1.4",

src/cli/bin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ updateNotifier({
1212
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
1313
}).notify()
1414

15-
require('yargs')
15+
yargs
1616
.commandDir('commands')
1717
.demand(1)
1818
.help()
19+
.strict()
20+
.completion()
1921
.argv

src/cli/commands/bitswap/stat.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ module.exports = {
77

88
describe: 'Show some diagnostic information on the bitswap agent.',
99

10-
builder: {
11-
},
10+
builder: {},
1211

13-
handler: () => {
12+
handler () {
1413
utils.getIPFS((err, ipfs) => {
1514
if (err) {
1615
throw err

src/cli/commands/bitswap/unwant.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@
33
const utils = require('../../utils')
44

55
module.exports = {
6-
command: 'unwant',
6+
command: 'unwant <key>',
77

88
describe: 'Remove a given block from your wantlist.',
99

10-
builder: {
11-
key: {
12-
required: true
13-
}
14-
},
15-
16-
handler: (key) => {
10+
handler (argv) {
1711
utils.getIPFS((err, ipfs) => {
1812
if (err) {
1913
throw err

src/cli/commands/bitswap/wantlist.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ module.exports = {
88
describe: 'Print out all blocks currently on the bitswap wantlist for the local peer.',
99

1010
builder: {
11+
peer: {
12+
alias: 'p',
13+
describe: 'Specify which peer to show wantlist for.',
14+
type: 'string'
15+
}
1116
},
1217

13-
handler: () => {
18+
handler (argv) {
19+
// TODO: handle argv.peer
1420
utils.getIPFS((err, ipfs) => {
1521
if (err) {
1622
throw err

src/cli/commands/block/get.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ const log = debug('cli:block')
77
log.error = debug('cli:block:error')
88

99
module.exports = {
10-
command: 'get',
10+
command: 'get <key>',
1111

1212
describe: 'Get a raw IPFS block',
1313

1414
builder: {},
1515

16-
handler: (key) => {
17-
if (!key) {
18-
throw new Error("Argument 'key' is required")
19-
}
20-
16+
handler (argv) {
2117
utils.getIPFS((err, ipfs) => {
2218
if (err) {
2319
throw err
2420
}
2521

2622
const mh = utils.isDaemonOn()
27-
? key
28-
: new Buffer(bs58.decode(key))
23+
? argv.key
24+
: new Buffer(bs58.decode(argv.key))
2925

3026
ipfs.block.get(mh, (err, block) => {
3127
if (err) {

src/cli/commands/block/put.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ function addBlock (buf) {
3838
}
3939

4040
module.exports = {
41-
command: 'put',
41+
command: 'put [data]',
4242

4343
describe: 'Stores input as an IPFS block',
4444

4545
builder: {},
4646

47-
handler: (filePath) => {
48-
if (filePath) {
49-
return addBlock(fs.readFileSync(filePath))
47+
handler (argv) {
48+
if (argv.data) {
49+
return addBlock(fs.readFileSync(argv.data))
5050
}
5151

5252
process.stdin.pipe(bl((err, input) => {

src/cli/commands/block/rm.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@ const log = debug('cli:block')
77
log.error = debug('cli:block:error')
88

99
module.exports = {
10-
command: 'rm',
10+
command: 'rm <key>',
1111

1212
describe: 'Remove a raw IPFS block',
1313

1414
builder: {},
1515

16-
handler: (key) => {
17-
if (!key) {
18-
throw new Error("Argument 'key' is required")
19-
}
20-
16+
handler (argv) {
2117
utils.getIPFS((err, ipfs) => {
2218
if (err) {
2319
throw err
@@ -28,14 +24,14 @@ module.exports = {
2824
throw new Error('rm block with daemon running is not yet implemented')
2925
}
3026

31-
const mh = new Buffer(bs58.decode(key))
27+
const mh = new Buffer(bs58.decode(argv.key))
3228

3329
ipfs.block.del(mh, (err) => {
3430
if (err) {
3531
throw err
3632
}
3733

38-
console.log('removed', key)
34+
console.log('removed', argv.key)
3935
})
4036
})
4137
}

src/cli/commands/block/stat.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ const log = debug('cli:block')
77
log.error = debug('cli:block:error')
88

99
module.exports = {
10-
command: 'stat',
10+
command: 'stat <key>',
1111

1212
describe: 'Print information of a raw IPFS block',
1313

1414
builder: {},
1515

16-
handler: (key) => {
17-
if (!key) {
18-
throw new Error("Argument 'key' is required")
19-
}
20-
16+
handler (argv) {
2117
utils.getIPFS((err, ipfs) => {
2218
if (err) {
2319
throw err
2420
}
2521

2622
const mh = utils.isDaemonOn()
27-
? key
28-
: new Buffer(bs58.decode(key))
23+
? argv.key
24+
: new Buffer(bs58.decode(argv.key))
2925

3026
ipfs.block.stat(mh, (err, block) => {
3127
if (err) {

src/cli/commands/bootstrap/add.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ const utils = require('../../utils')
66
log.error = debug('cli:bootstrap:error')
77

88
module.exports = {
9-
command: 'add',
9+
command: 'add <peer>',
1010

1111
describe: 'Add peers to the bootstrap list',
1212

1313
builder: {},
1414

15-
handler: (multiaddr) => {
15+
handler (argv) {
1616
utils.getIPFS((err, ipfs) => {
1717
if (err) {
1818
throw err
1919
}
20-
ipfs.bootstrap.add(multiaddr, (err, list) => {
20+
ipfs.bootstrap.add(argv.peer, (err, list) => {
2121
if (err) {
2222
throw err
2323
}

src/cli/commands/bootstrap/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212

1313
builder: {},
1414

15-
handler: () => {
15+
handler () {
1616
utils.getIPFS((err, ipfs) => {
1717
if (err) {
1818
throw err

src/cli/commands/bootstrap/rm.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ log.error = debug('cli:bootstrap:error')
66
const utils = require('../../utils')
77

88
module.exports = {
9-
command: 'rm',
9+
command: 'rm <peer>',
1010

1111
describe: 'Removes peers from the bootstrap list',
1212

1313
builder: {},
1414

15-
handler: (multiaddr) => {
15+
handler (argv) {
1616
utils.getIPFS((err, ipfs) => {
1717
if (err) {
1818
throw err
1919
}
20-
ipfs.bootstrap.rm(multiaddr, (err, list) => {
20+
ipfs.bootstrap.rm(argv.peer, (err, list) => {
2121
if (err) {
2222
throw err
2323
}

src/cli/commands/config.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const utils = require('../utils')
1010
module.exports = {
1111
command: 'config <key> [value]',
1212

13-
describe: 'Get and set IPFS config values',
13+
description: 'Get and set IPFS config values',
1414

15-
options (yargs) {
15+
builder (yargs) {
1616
return yargs
1717
.commandDir('config')
1818
.options({
@@ -25,18 +25,16 @@ module.exports = {
2525
default: false
2626
}
2727
})
28-
.usage('so and so')
2928
},
3029

3130
handler (argv) {
32-
if (argv.help) {
33-
return
34-
}
31+
if (argv._handled) return
32+
argv._handled = true
3533

3634
const bool = argv.bool
3735
const json = argv.json
3836
const key = argv.key
39-
const value = argv.value
37+
let value = argv.value
4038

4139
utils.getIPFS((err, ipfs) => {
4240
if (err) {
@@ -53,7 +51,7 @@ module.exports = {
5351
throw new Error('failed to read the config')
5452
}
5553

56-
console.log(config.Value)
54+
console.log(config)
5755
})
5856
}
5957

src/cli/commands/config/edit.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ module.exports = {
1414

1515
describe: 'Opens the config file for editing in $EDITOR',
1616

17-
handler: (name) => {
17+
builder: {},
18+
19+
handler (argv) {
20+
if (argv._handled) return
21+
argv._handled = true
22+
1823
utils.getIPFS((err, ipfs) => {
1924
if (err) {
2025
throw err

src/cli/commands/config/replace.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ const utils = require('../../utils')
88
const fs = require('fs')
99

1010
module.exports = {
11-
command: 'replace',
11+
command: 'replace <file>',
1212

1313
describe: 'Replaces the config with <file>',
1414

1515
builder: {},
1616

17-
handler: (configPath) => {
17+
handler (argv) {
18+
if (argv._handled) return
19+
argv._handled = true
20+
1821
utils.getIPFS((err, ipfs) => {
1922
if (err) {
2023
throw err
2124
}
2225

23-
const filePath = path.resolve(process.cwd(), configPath)
26+
const filePath = path.resolve(process.cwd(), argv.file)
2427

2528
const config = utils.isDaemonOn()
2629
? filePath : JSON.parse(fs.readFileSync(filePath, 'utf8'))

src/cli/commands/config/show.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ module.exports = {
1212

1313
builder: {},
1414

15-
handler: () => {
15+
handler (argv) {
16+
if (argv._handled) return
17+
argv._handled = true
18+
1619
utils.getIPFS((err, ipfs) => {
1720
if (err) {
1821
throw err

src/cli/commands/daemon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212

1313
describe: 'Start a long-running daemon process',
1414

15-
handler: (name) => {
15+
handler () {
1616
console.log('Initializing daemon...')
1717
httpAPI = new HttpAPI(process.env.IPFS_PATH)
1818
httpAPI.start((err) => {

src/cli/commands/dns.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict'
22

3-
43
module.exports = {
54
command: 'dns',
65

76
describe: '',
87

9-
handler: () => {
8+
handler (argv) {
109
}
1110
}

src/cli/commands/files/add.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function checkPath (inPath, recursive) {
3535
}
3636

3737
module.exports = {
38-
command: 'add',
38+
command: 'add <file>',
3939

4040
describe: 'Add a file to IPFS using the UnixFS data format',
4141

@@ -47,10 +47,10 @@ module.exports = {
4747
}
4848
},
4949

50-
handler: (recursive, inPath) => {
50+
handler (argv) {
5151
let rs
5252

53-
inPath = checkPath(inPath, recursive)
53+
let inPath = checkPath(argv.file, argv.recursive)
5454

5555
glob(path.join(inPath, '/**/*'), (err, res) => {
5656
if (err) {

0 commit comments

Comments
 (0)