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

Commit 99c40bf

Browse files
start refactoring the cli using yargs. Closes #331
1 parent c3b2c5f commit 99c40bf

Some content is hidden

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

56 files changed

+475
-300
lines changed

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
"fs-blob-store": "^5.2.1",
6868
"glob": "^7.0.3",
6969
"hapi": "^13.4.1",
70-
"ipfs-bitswap": "^0.6.0",
7170
"ipfs-api": "^6.0.1",
71+
"ipfs-bitswap": "^0.6.0",
7272
"ipfs-block": "^0.3.0",
7373
"ipfs-block-service": "^0.4.0",
7474
"ipfs-merkle-dag": "^0.6.0",
@@ -83,21 +83,24 @@
8383
"lodash.get": "^4.3.0",
8484
"lodash.set": "^4.2.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",
9495
"ronin": "^0.3.11",
9596
"run-parallel": "^1.1.6",
9697
"run-parallel-limit": "^1.0.3",
9798
"run-series": "^1.1.4",
9899
"run-waterfall": "^1.1.3",
99100
"temp": "^0.8.3",
100-
"through2": "^2.0.1"
101+
"through2": "^2.0.1",
102+
"update-notifier": "^1.0.2",
103+
"yargs": "^4.8.1"
101104
},
102105
"contributors": [
103106
"Andrew de Andrade <[email protected]>",

src/cli/bin.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
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+
require('yargs')
16+
.commandDir('commands')
17+
.demand(1)
18+
.help()
19+
.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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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: {
8+
describe: 'Show some diagnostic information on the bitswap agent.',
9+
10+
builder: {
1011
},
1112

12-
run: () => {
13+
handler: () => {
1314
utils.getIPFS((err, ipfs) => {
1415
if (err) {
1516
throw err
@@ -35,4 +36,4 @@ bitswap status
3536
})
3637
})
3738
}
38-
})
39+
}

src/cli/commands/bitswap/unwant.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
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',
87

9-
options: {
8+
describe: 'Remove a given block from your wantlist.',
9+
10+
builder: {
1011
key: {
1112
required: true
1213
}
1314
},
1415

15-
run: (key) => {
16+
handler: (key) => {
1617
utils.getIPFS((err, ipfs) => {
1718
if (err) {
1819
throw err
@@ -21,4 +22,4 @@ module.exports = Command.extend({
2122
throw new Error('Not implemented yet')
2223
})
2324
}
24-
})
25+
}

src/cli/commands/bitswap/wantlist.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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: {
1011
},
1112

12-
run: () => {
13+
handler: () => {
1314
utils.getIPFS((err, ipfs) => {
1415
if (err) {
1516
throw err
@@ -23,4 +24,4 @@ module.exports = Command.extend({
2324
})
2425
})
2526
}
26-
})
27+
}

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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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: 'Get a raw IPFS block',
9+
module.exports = {
10+
command: 'get',
1211

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

15-
run: (key) => {
14+
builder: {},
15+
16+
handler: (key) => {
1617
if (!key) {
1718
throw new Error("Argument 'key' is required")
1819
}
@@ -40,4 +41,4 @@ module.exports = Command.extend({
4041
})
4142
})
4243
}
43-
})
44+
}

src/cli/commands/block/put.js

Lines changed: 7 additions & 6 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,12 +37,14 @@ 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',
4342

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

46-
run: (filePath) => {
45+
builder: {},
46+
47+
handler: (filePath) => {
4748
if (filePath) {
4849
return addBlock(fs.readFileSync(filePath))
4950
}
@@ -56,4 +57,4 @@ module.exports = Command.extend({
5657
addBlock(input)
5758
}))
5859
}
59-
})
60+
}

src/cli/commands/block/rm.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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',
1211

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

15-
run: (key) => {
14+
builder: {},
15+
16+
handler: (key) => {
1617
if (!key) {
1718
throw new Error("Argument 'key' is required")
1819
}
@@ -38,4 +39,4 @@ module.exports = Command.extend({
3839
})
3940
})
4041
}
41-
})
42+
}

src/cli/commands/block/stat.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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: 'Print information of a raw IPFS block',
9+
module.exports = {
10+
command: 'stat',
1211

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

15-
run: (key) => {
14+
builder: {},
15+
16+
handler: (key) => {
1617
if (!key) {
1718
throw new Error("Argument 'key' is required")
1819
}
@@ -41,4 +42,4 @@ module.exports = Command.extend({
4142
})
4243
})
4344
}
44-
})
45+
}

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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
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',
1110

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

14-
run: (multiaddr) => {
13+
builder: {},
14+
15+
handler: (multiaddr) => {
1516
utils.getIPFS((err, ipfs) => {
1617
if (err) {
1718
throw err
@@ -23,4 +24,4 @@ module.exports = Command.extend({
2324
})
2425
})
2526
}
26-
})
27+
}

src/cli/commands/bootstrap/list.js

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

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

9-
module.exports = Command.extend({
10-
desc: 'Show peers in the bootstrap list',
8+
module.exports = {
9+
command: 'list',
1110

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

14-
run: () => {
13+
builder: {},
14+
15+
handler: () => {
1516
utils.getIPFS((err, ipfs) => {
1617
if (err) {
1718
throw err
@@ -26,4 +27,4 @@ module.exports = Command.extend({
2627
})
2728
})
2829
}
29-
})
30+
}

0 commit comments

Comments
 (0)