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

Commit

Permalink
fix(cli): replace ronin with yargs
Browse files Browse the repository at this point in the history
Closes #331
  • Loading branch information
dignifiedquire committed Aug 4, 2016
1 parent 1b64acb commit cba42ca
Show file tree
Hide file tree
Showing 60 changed files with 540 additions and 414 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,23 @@
"lodash.get": "^4.4.0",
"lodash.set": "^4.3.0",
"mafmt": "^2.1.1",
"multihashes": "^0.2.2",
"multiaddr": "^2.0.2",
"multihashes": "^0.2.2",
"path-exists": "^3.0.0",
"peer-book": "^0.3.0",
"peer-id": "^0.7.0",
"peer-info": "^0.7.0",
"promisify-es6": "^1.0.1",
"read-pkg-up": "^1.0.1",
"readable-stream": "1.1.13",
"ronin": "^0.3.11",
"run-parallel": "^1.1.6",
"run-parallel-limit": "^1.0.3",
"run-series": "^1.1.4",
"run-waterfall": "^1.1.3",
"temp": "^0.8.3",
"through2": "^2.0.1"
"through2": "^2.0.1",
"update-notifier": "^1.0.2",
"yargs": "^4.8.1"
},
"contributors": [
"Andrew de Andrade <andrew@deandrade.com.br>",
Expand Down
22 changes: 15 additions & 7 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

'use strict'

const ronin = require('ronin')
const yargs = require('yargs')
const updateNotifier = require('update-notifier')
const readPkgUp = require('read-pkg-up')

const cli = ronin(__dirname)
const pkg = readPkgUp.sync().pkg
updateNotifier({
pkg,
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
}).notify()

cli.run()

// cli.autoupdate(function () {
// cli.run()
// })
yargs
.commandDir('commands')
.demand(1)
.help()
.strict()
.completion()
.argv
15 changes: 15 additions & 0 deletions src/cli/commands/bitswap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

module.exports = {
command: 'bitswap',

description: 'A set of commands to manipulate the bitswap agent.',

builder (yargs) {
return yargs
.commandDir('bitswap')
},

handler (argv) {
}
}
14 changes: 7 additions & 7 deletions src/cli/commands/bitswap/stat.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')

module.exports = Command.extend({
desc: 'Show some diagnostic information on the bitswap agent.',
module.exports = {
command: 'stat',

options: {
},
describe: 'Show some diagnostic information on the bitswap agent.',

run: () => {
builder: {},

handler () {
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
Expand All @@ -35,4 +35,4 @@ bitswap status
})
})
}
})
}
15 changes: 5 additions & 10 deletions src/cli/commands/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')

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

options: {
key: {
required: true
}
},
describe: 'Remove a given block from your wantlist.',

run: (key) => {
handler (argv) {
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
Expand All @@ -21,4 +16,4 @@ module.exports = Command.extend({
throw new Error('Not implemented yet')
})
}
})
}
19 changes: 13 additions & 6 deletions src/cli/commands/bitswap/wantlist.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')

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

options: {
describe: 'Print out all blocks currently on the bitswap wantlist for the local peer.',

builder: {
peer: {
alias: 'p',
describe: 'Specify which peer to show wantlist for.',
type: 'string'
}
},

run: () => {
handler (argv) {
// TODO: handle argv.peer
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
Expand All @@ -23,4 +30,4 @@ module.exports = Command.extend({
})
})
}
})
}
15 changes: 15 additions & 0 deletions src/cli/commands/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

module.exports = {
command: 'block',

description: 'Manipulate raw IPFS blocks.',

builder (yargs) {
return yargs
.commandDir('block')
},

handler (argv) {
}
}
19 changes: 8 additions & 11 deletions src/cli/commands/block/get.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')
const bs58 = require('bs58')
const debug = require('debug')
const log = debug('cli:block')
log.error = debug('cli:block:error')

module.exports = Command.extend({
desc: 'Get a raw IPFS block',
module.exports = {
command: 'get <key>',

options: {},
describe: 'Get a raw IPFS block',

run: (key) => {
if (!key) {
throw new Error("Argument 'key' is required")
}
builder: {},

handler (argv) {
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
}

const mh = utils.isDaemonOn()
? key
: new Buffer(bs58.decode(key))
? argv.key
: new Buffer(bs58.decode(argv.key))

ipfs.block.get(mh, (err, block) => {
if (err) {
Expand All @@ -40,4 +37,4 @@ module.exports = Command.extend({
})
})
}
})
}
17 changes: 9 additions & 8 deletions src/cli/commands/block/put.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')
const bs58 = require('bs58')
const bl = require('bl')
Expand Down Expand Up @@ -38,14 +37,16 @@ function addBlock (buf) {
})
}

module.exports = Command.extend({
desc: 'Stores input as an IPFS block',
module.exports = {
command: 'put [data]',

options: {},
describe: 'Stores input as an IPFS block',

run: (filePath) => {
if (filePath) {
return addBlock(fs.readFileSync(filePath))
builder: {},

handler (argv) {
if (argv.data) {
return addBlock(fs.readFileSync(argv.data))
}

process.stdin.pipe(bl((err, input) => {
Expand All @@ -56,4 +57,4 @@ module.exports = Command.extend({
addBlock(input)
}))
}
})
}
19 changes: 8 additions & 11 deletions src/cli/commands/block/rm.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')
const bs58 = require('bs58')
const debug = require('debug')
const log = debug('cli:block')
log.error = debug('cli:block:error')

module.exports = Command.extend({
desc: 'Remove a raw IPFS block',
module.exports = {
command: 'rm <key>',

options: {},
describe: 'Remove a raw IPFS block',

run: (key) => {
if (!key) {
throw new Error("Argument 'key' is required")
}
builder: {},

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

const mh = new Buffer(bs58.decode(key))
const mh = new Buffer(bs58.decode(argv.key))

ipfs.block.del(mh, (err) => {
if (err) {
throw err
}

console.log('removed', key)
console.log('removed', argv.key)
})
})
}
})
}
19 changes: 8 additions & 11 deletions src/cli/commands/block/stat.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
'use strict'

const Command = require('ronin').Command
const utils = require('../../utils')
const bs58 = require('bs58')
const debug = require('debug')
const log = debug('cli:block')
log.error = debug('cli:block:error')

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

options: {},
describe: 'Print information of a raw IPFS block',

run: (key) => {
if (!key) {
throw new Error("Argument 'key' is required")
}
builder: {},

handler (argv) {
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
}

const mh = utils.isDaemonOn()
? key
: new Buffer(bs58.decode(key))
? argv.key
: new Buffer(bs58.decode(argv.key))

ipfs.block.stat(mh, (err, block) => {
if (err) {
Expand All @@ -41,4 +38,4 @@ module.exports = Command.extend({
})
})
}
})
}
15 changes: 15 additions & 0 deletions src/cli/commands/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

module.exports = {
command: 'bootstrap',

description: 'Show or edit the list of bootstrap peers.',

builder (yargs) {
return yargs
.commandDir('bootstrap')
},

handler (argv) {
}
}
15 changes: 8 additions & 7 deletions src/cli/commands/bootstrap/add.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
'use strict'

const Command = require('ronin').Command
const debug = require('debug')
const log = debug('cli:bootstrap')
const utils = require('../../utils')
log.error = debug('cli:bootstrap:error')

module.exports = Command.extend({
desc: 'Add peers to the bootstrap list',
module.exports = {
command: 'add <peer>',

options: {},
describe: 'Add peers to the bootstrap list',

run: (multiaddr) => {
builder: {},

handler (argv) {
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
}
ipfs.bootstrap.add(multiaddr, (err, list) => {
ipfs.bootstrap.add(argv.peer, (err, list) => {
if (err) {
throw err
}
})
})
}
})
}
Loading

0 comments on commit cba42ca

Please sign in to comment.