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

Commit cba42ca

Browse files
fix(cli): replace ronin with yargs
Closes #331
1 parent 1b64acb commit cba42ca

Some content is hidden

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

60 files changed

+540
-414
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@
8383
"lodash.get": "^4.4.0",
8484
"lodash.set": "^4.3.0",
8585
"mafmt": "^2.1.1",
86-
"multihashes": "^0.2.2",
8786
"multiaddr": "^2.0.2",
87+
"multihashes": "^0.2.2",
8888
"path-exists": "^3.0.0",
8989
"peer-book": "^0.3.0",
9090
"peer-id": "^0.7.0",
9191
"peer-info": "^0.7.0",
9292
"promisify-es6": "^1.0.1",
93+
"read-pkg-up": "^1.0.1",
9394
"readable-stream": "1.1.13",
94-
"ronin": "^0.3.11",
9595
"run-parallel": "^1.1.6",
9696
"run-parallel-limit": "^1.0.3",
9797
"run-series": "^1.1.4",
9898
"run-waterfall": "^1.1.3",
9999
"temp": "^0.8.3",
100-
"through2": "^2.0.1"
100+
"through2": "^2.0.1",
101+
"update-notifier": "^1.0.2",
102+
"yargs": "^4.8.1"
101103
},
102104
"contributors": [
103105
"Andrew de Andrade <andrew@deandrade.com.br>",

src/cli/bin.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
'use strict'
44

5-
const ronin = require('ronin')
5+
const yargs = require('yargs')
6+
const updateNotifier = require('update-notifier')
7+
const readPkgUp = require('read-pkg-up')
68

7-
const cli = ronin(__dirname)
9+
const pkg = readPkgUp.sync().pkg
10+
updateNotifier({
11+
pkg,
12+
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
13+
}).notify()
814

9-
cli.run()
10-
11-
// cli.autoupdate(function () {
12-
// cli.run()
13-
// })
15+
yargs
16+
.commandDir('commands')
17+
.demand(1)
18+
.help()
19+
.strict()
20+
.completion()
21+
.argv

src/cli/commands/bitswap.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
module.exports = {
4+
command: 'bitswap',
5+
6+
description: 'A set of commands to manipulate the bitswap agent.',
7+
8+
builder (yargs) {
9+
return yargs
10+
.commandDir('bitswap')
11+
},
12+
13+
handler (argv) {
14+
}
15+
}

src/cli/commands/bitswap/stat.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54

6-
module.exports = Command.extend({
7-
desc: 'Show some diagnostic information on the bitswap agent.',
5+
module.exports = {
6+
command: 'stat',
87

9-
options: {
10-
},
8+
describe: 'Show some diagnostic information on the bitswap agent.',
119

12-
run: () => {
10+
builder: {},
11+
12+
handler () {
1313
utils.getIPFS((err, ipfs) => {
1414
if (err) {
1515
throw err
@@ -35,4 +35,4 @@ bitswap status
3535
})
3636
})
3737
}
38-
})
38+
}

src/cli/commands/bitswap/unwant.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54

6-
module.exports = Command.extend({
7-
desc: 'Remove a given block from your wantlist.',
5+
module.exports = {
6+
command: 'unwant <key>',
87

9-
options: {
10-
key: {
11-
required: true
12-
}
13-
},
8+
describe: 'Remove a given block from your wantlist.',
149

15-
run: (key) => {
10+
handler (argv) {
1611
utils.getIPFS((err, ipfs) => {
1712
if (err) {
1813
throw err
@@ -21,4 +16,4 @@ module.exports = Command.extend({
2116
throw new Error('Not implemented yet')
2217
})
2318
}
24-
})
19+
}

src/cli/commands/bitswap/wantlist.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54

6-
module.exports = Command.extend({
7-
desc: 'Print out all blocks currently on the bitswap wantlist for the local peer.',
5+
module.exports = {
6+
command: 'wantlist',
87

9-
options: {
8+
describe: 'Print out all blocks currently on the bitswap wantlist for the local peer.',
9+
10+
builder: {
11+
peer: {
12+
alias: 'p',
13+
describe: 'Specify which peer to show wantlist for.',
14+
type: 'string'
15+
}
1016
},
1117

12-
run: () => {
18+
handler (argv) {
19+
// TODO: handle argv.peer
1320
utils.getIPFS((err, ipfs) => {
1421
if (err) {
1522
throw err
@@ -23,4 +30,4 @@ module.exports = Command.extend({
2330
})
2431
})
2532
}
26-
})
33+
}

src/cli/commands/block.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
module.exports = {
4+
command: 'block',
5+
6+
description: 'Manipulate raw IPFS blocks.',
7+
8+
builder (yargs) {
9+
return yargs
10+
.commandDir('block')
11+
},
12+
13+
handler (argv) {
14+
}
15+
}

src/cli/commands/block/get.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:block')
87
log.error = debug('cli:block:error')
98

10-
module.exports = Command.extend({
11-
desc: 'Get a raw IPFS block',
9+
module.exports = {
10+
command: 'get <key>',
1211

13-
options: {},
12+
describe: 'Get a raw IPFS block',
1413

15-
run: (key) => {
16-
if (!key) {
17-
throw new Error("Argument 'key' is required")
18-
}
14+
builder: {},
1915

16+
handler (argv) {
2017
utils.getIPFS((err, ipfs) => {
2118
if (err) {
2219
throw err
2320
}
2421

2522
const mh = utils.isDaemonOn()
26-
? key
27-
: new Buffer(bs58.decode(key))
23+
? argv.key
24+
: new Buffer(bs58.decode(argv.key))
2825

2926
ipfs.block.get(mh, (err, block) => {
3027
if (err) {
@@ -40,4 +37,4 @@ module.exports = Command.extend({
4037
})
4138
})
4239
}
43-
})
40+
}

src/cli/commands/block/put.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54
const bs58 = require('bs58')
65
const bl = require('bl')
@@ -38,14 +37,16 @@ function addBlock (buf) {
3837
})
3938
}
4039

41-
module.exports = Command.extend({
42-
desc: 'Stores input as an IPFS block',
40+
module.exports = {
41+
command: 'put [data]',
4342

44-
options: {},
43+
describe: 'Stores input as an IPFS block',
4544

46-
run: (filePath) => {
47-
if (filePath) {
48-
return addBlock(fs.readFileSync(filePath))
45+
builder: {},
46+
47+
handler (argv) {
48+
if (argv.data) {
49+
return addBlock(fs.readFileSync(argv.data))
4950
}
5051

5152
process.stdin.pipe(bl((err, input) => {
@@ -56,4 +57,4 @@ module.exports = Command.extend({
5657
addBlock(input)
5758
}))
5859
}
59-
})
60+
}

src/cli/commands/block/rm.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:block')
87
log.error = debug('cli:block:error')
98

10-
module.exports = Command.extend({
11-
desc: 'Remove a raw IPFS block',
9+
module.exports = {
10+
command: 'rm <key>',
1211

13-
options: {},
12+
describe: 'Remove a raw IPFS block',
1413

15-
run: (key) => {
16-
if (!key) {
17-
throw new Error("Argument 'key' is required")
18-
}
14+
builder: {},
1915

16+
handler (argv) {
2017
utils.getIPFS((err, ipfs) => {
2118
if (err) {
2219
throw err
@@ -27,15 +24,15 @@ module.exports = Command.extend({
2724
throw new Error('rm block with daemon running is not yet implemented')
2825
}
2926

30-
const mh = new Buffer(bs58.decode(key))
27+
const mh = new Buffer(bs58.decode(argv.key))
3128

3229
ipfs.block.del(mh, (err) => {
3330
if (err) {
3431
throw err
3532
}
3633

37-
console.log('removed', key)
34+
console.log('removed', argv.key)
3835
})
3936
})
4037
}
41-
})
38+
}

src/cli/commands/block/stat.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const utils = require('../../utils')
54
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:block')
87
log.error = debug('cli:block:error')
98

10-
module.exports = Command.extend({
11-
desc: 'Print information of a raw IPFS block',
9+
module.exports = {
10+
command: 'stat <key>',
1211

13-
options: {},
12+
describe: 'Print information of a raw IPFS block',
1413

15-
run: (key) => {
16-
if (!key) {
17-
throw new Error("Argument 'key' is required")
18-
}
14+
builder: {},
1915

16+
handler (argv) {
2017
utils.getIPFS((err, ipfs) => {
2118
if (err) {
2219
throw err
2320
}
2421

2522
const mh = utils.isDaemonOn()
26-
? key
27-
: new Buffer(bs58.decode(key))
23+
? argv.key
24+
: new Buffer(bs58.decode(argv.key))
2825

2926
ipfs.block.stat(mh, (err, block) => {
3027
if (err) {
@@ -41,4 +38,4 @@ module.exports = Command.extend({
4138
})
4239
})
4340
}
44-
})
41+
}

src/cli/commands/bootstrap.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
module.exports = {
4+
command: 'bootstrap',
5+
6+
description: 'Show or edit the list of bootstrap peers.',
7+
8+
builder (yargs) {
9+
return yargs
10+
.commandDir('bootstrap')
11+
},
12+
13+
handler (argv) {
14+
}
15+
}

src/cli/commands/bootstrap/add.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
'use strict'
22

3-
const Command = require('ronin').Command
43
const debug = require('debug')
54
const log = debug('cli:bootstrap')
65
const utils = require('../../utils')
76
log.error = debug('cli:bootstrap:error')
87

9-
module.exports = Command.extend({
10-
desc: 'Add peers to the bootstrap list',
8+
module.exports = {
9+
command: 'add <peer>',
1110

12-
options: {},
11+
describe: 'Add peers to the bootstrap list',
1312

14-
run: (multiaddr) => {
13+
builder: {},
14+
15+
handler (argv) {
1516
utils.getIPFS((err, ipfs) => {
1617
if (err) {
1718
throw err
1819
}
19-
ipfs.bootstrap.add(multiaddr, (err, list) => {
20+
ipfs.bootstrap.add(argv.peer, (err, list) => {
2021
if (err) {
2122
throw err
2223
}
2324
})
2425
})
2526
}
26-
})
27+
}

0 commit comments

Comments
 (0)