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
}

0 commit comments

Comments
 (0)